Welcome to SAP Data Types tutorial. This tutorial is part of our free SAP ABAP course and you will learn about different types of data that exist in SAP. We will discuss data types in ABAP Dictionary and predefined ABAP data types.
Speaking about SAP data types one should always consider that there are two kinds of types here. First, types of Data Dictionary objects and entities. Second, pure ABAP types, i.e. types of programmatic objects that are created within ABAP programs, function modules and procedures. Although, they are highly correlated and were adapted for seamless interaction with each other, there are significant differences between them and their use cases. In this tutorial, we are going to dig into ins and outs of SAP data types.
SAP Data Types in ABAP Dictionary
These are the fundamental pieces of which ABAP Data Dictionary is constructed. They are used both in the standard ABAP Dictionary objects as well as in the custom ones. You use them in tables and table fields, data elements, domains, views, that is literally everywhere. Each and every object in Data Dictionary is based on some Data Dictionary type, and that is why it is important to have a good grasp of them.
Numeric SAP Data Types
Numeric predefined SAP data types are used to store numbers in arithmetic calculations, expressions and numeric tabular data. There are three numeric types in ABAP Dictionary which vary by nature:
Integer type, which comprises of:
- INT1 – 1-byte integers, with value range 0 to 255
- INT2 – 2-byte integers, with value range -32,768 to 32,767
- INT4 – 4-byte integers, with value range -2,147,483,648 to +2,147,483,647
INT2 and INT2 have correspondent predefined ABAP types b and s, which, however, cannot be used directly by developer and are only for internal use by SAP system.
Packed number type or a DEC type.
It is used for efficient representation of decimal numbers in a database in a so-called BCD format, i.e. binary-coded decimal. It is always specified by a total length and number of decimal places. Packed type is an internal representation of types CURR, DF34_DEC, DF16_DEC, and QUAN types.
Floating number type.
In ABAP Data Dictionary, floating type is presented by decimal floating point numbers DF16_DEC, DF16_RAW, DF34_DEC, DF34_RAW and binary floating point numbers FLTP.
Decimal floating-point numbers:
- DF16_DEC – decimal BCD floating numbers with a length of 15 places
- DF16_RAW – decimal binary floating numbers with a length of 16 places
- DF34_DEC – decimal BCD floating numbers with a length of 31 places
- DF34_RAW – decimal binary floating numbers with a length of 34 places
Floating point numbers:
- FLTP – floating point number with a length of 16, specified by IEEE-754 standard.
What is actually the difference between decimal floating types and FLTP? The main thing any developer should know is that FLTP is a binary type, correspondent to ABAP type f, and it is platform-dependent. Therefore 100% accuracy cannot be reached there, because its representation is different on different database back-ends. Like packed number it can hold only uneven number of places, maximum of 17. One should always avoid using it in high-accuracy calculations, like tax or financial statements and expressions. Almost all FLTP numbers can be represented in DEC-types, and they should be.
On the other hand, what is the difference between DFXX_RAW and DFXX_DEC types? RAW-types are placed to database as binary, therefore are not treated as numbers, they cannot be used in SQL-calculations and cannot be edited by Native SQL. In its turn, DEC-types are handled as numbers, they can be used in SQL calculation and Native SQL, but are limited in range to 16 places, so do not cover the whole range. Wise developer should always select the proper type for each use-case, however DFXX_DE are preferable.
Character-Like SAP Data Types
Character-like types represent string and character data with certain peculiarities. They consist of
Character data
- CHAR – character data with a length 1-30000 (max 1333 for tables)
- LCHAR – long character data with a length 256-32000.
Note, that only one LCHAR field can be in database table, and it field cannot be included in table key. This type is a legacy type and is not recommended for future developments.
String data
SSTRING – short string data, with a length of 1-1333
STRING – short string data, with a length of 256-infinit
Character types correspond to ABAP type c and are used for storing small character values, constants and for char calculations. String types correspond to string ABAP type and are used for storing big string data.
When we say that length of STRING type is limited to infinity that is not strictly true, i.e. there is so-called Maximum Size of Dynamic Data Objects, which should be respected when planning developments. This maximum size equals to max size that current internal session can request for dynamic data objects. It is also generally limited by the largest block that can be addressed and is usually 2Gb.
Byte-Like SAP Data Types
Byte-like types are used for storing byte chains in a quite variety of development tasks. Here we have following types:
- RAW – byte string with a length of 1-32000 places. For table fields max is 255.
- LRAW – long byte string with a length of 256-32000 places
- RAWSTRING – BLOB string with a length of 256-infinity
RAW and LRAW types have correspondent ABAP type x, whilst RAWSTRING types is correspondent to xstring type. LRAW is treated as legacy and is not preferable for future developments.
Byte-like strings have similar length restrictions like STRING, as was specified above. In addition, one should always remember that STRING and RAWSTRING types have certain limitations and cannot be used in SQL expressions, aggregate functions and GROUP and ORDER clauses.
Special SAP Data Types
Special Data Dictionary types are called special not for nothing, but because they cannot be placed in any of the above categories and have special use-cases in SAP system. It can be divide into three synthetic groups according their application.
Date/time types
- DATS – character representation of a date in 8-character view YYYYMMDD. One should consider, however that dates in that format are not validated when reading and writing from/to database, the validation is done only on Dynpros. This type has correspondent d type in ABAP.
- TIMS – character representation of time in 6-character view HHMMSS. Like the case with date, check is made only in Dynpros. This type has correspondent t type in ABAP.
- ACCP – character representation of posting periods in Data Dictionary. It is 6-character type representing periods in a YYYYMM view.
Special char types
- NUMC – special type, technically held as character with max length of 255, but used for storing numbers. Like previous special type checks are made only for dynprocs. Correspondent ABAP type is m type.
- CLNT – char type technically represented as CHAR of length 3. It is used as first field of a client-dependent table. The type was discussed in a previous tutorial while table creation.
- LANG – type for storing language flag in tables, technically represented as CHAR with length 1. This flag is considered by SAP system while importing-exporting tabular data via RFC or from/to Unicode systems.
Currency/quantity fields
- CURR – type used for storing currency, technically represented as packed number of length 1-31.
- CUKY – currency key for currency fields, presented by char type. Max length is 5 places.
- QUAN – type used for storing quantities in specific units, technically represented as packed number of length 1-31.
- UNIT – unit key for quantity field, presented by char type. Max length is 3 places.
Currency and quantity fields are special fields for storing data by functional attribute. All currency and quantity fields must be associated with correspondent key fields (CUKY and UNIT), otherwise the table won’t pass validation. All currency key fields can contain only values from TCURC table, whilst all quantity fields can contain only fields from T006 table.
What else should regular developer know about CURR and QUAN fields? As they are based on packed number type, they similarly can contain only uneven number of places.
Predefined ABAP SAP Data Types
In the first section, we described Data Dictionary types that are used in DDIC objects: tables, table fields, views, etc. For every Data Dictionary type, there is a corresponding predefined ABAP type and now we will discuss these predefined types in more detail.
Predefined Numeric SAP Data Types
Predefined ABAP numeric types serve for storing internal numeric data in ABAP programs as well as for passing numeric data to/from ABAP Data Dictionary. There are following numeric types in ABAP:
- b – 1-byte integer, used internally for storing INT1 DDIC type.
- s – 2-byte integer, used internally for storing INT2 DDIC type.
By “internally” we mean that it cannot be used by developer in customer programs, only standard SAP programs utilize it.
- i – 4-bytes integer, analog of INT4 DDIC type. It is the only integer type that can be used in ABAP programs.
- p – packed number, interchangeable with Data Dictionary DEC type. Maximum length is 16 bytes.
- decfloat16 – decimal floating-point number used for storing Dictionary types DF16_DEC and DF16_RAW. Maximum length is 8 bytes.
- decfloat34 – decimal floating-point number used for storing Dictionary types DF34_DEC and DF34_RAW. Maximum length is 16 bytes.
- f – binary floating-point number type, analog of FLTP DDIC type.
What one should consider when using ABAP predefined numeric types? As well as with floating DDIC types, one should always avoid choosing f type, for high-accuracy calculations. All previous recommendations also apply here. The representation of decimal point notation in packed and decimal numbers can be adjusted in a per-user manner via SU01 transaction.
These settings are applied in WRITE and WRITE TO statements in ABAP programs.
Predefined Character SAP Data Types
These types are used for representing character data in ABAP programs as well as for storing CHAR and LCHAR types from Data Dictionary.
- c – general character type with a length of 1 to 262,143 chars.
- string – types used for storing strings and short strings from Data Dictionary (STRING and SSTRING), as well as for wide range of string manipulations.
- n – analog of NUMC type from Data Dictionary
- d – date type used for storing DATS values from Data Dictionary, i.e. yyyymmdd. Length is 8 chars.Date validation rules are applied: “yyyy” (year) should be within range 0001 to 9999, “mm” (month) within 01 to 12, and “dd” (day) should be within 01 to 31.
- t – time type used for storing TIMS values from Data Dictionary, i.e. hhmmss. Length is 6 chars. Time validation rules are applied: “hh” (hours) should be within range 00 to 23, “mm” (minutes) within 00 to 59, “ss” (seconds) should be within 00 to 59.
When using character-like predefined types one should always consider Unicode systems. UTF16 code pages have character two bytes long. Maximum size for dynamic objects apply as well here as for DDIC character type. CL_ABAP_ELEMDESCR class can be used for checking maximum length of types n and c.
Predefined Byte SAP Data Types
Predefined ABAP types are used for storing and manipulating byte chains in ABAP programs as well as for interaction with Data Dictionary types RAW, LRAW and RAWSTRING. They are
- x – byte chain of length 1 to 524,287 bytes. Analog of RAW DDIC type.
- xstring – byte chain with variable length. Analog of RAWSTRING DDIC type.
As with previous variable length types, it doesn’t mean that xstring maximum length is indefinite. It depends on memory configuration on current system and can be checked via CL_ABAP_ELEMDESCR class constant TYPE_X_MAX_LENGTH. Besides the above constant, requirements to the maximum size of the dynamic objects apply here as well.
—
Did you like this tutorial? Have any questions or comments? We would love to hear your feedback in the comments section below. It’d be a big help for us, and hopefully it’s something we can address for you in improvement of our free SAP ABAP tutorials.
Navigation Links
Go to next lesson: SAP Data Objects
Go to previous lesson: How to Create Tables in SAP
Go to overview of the course: SAP ABAP Training
INT2 and INT2 have correspondent predefined ABAP types b and s,
Did not get the above statement. both the integers are same.