Classifying Technical Data Types in ABAP

Objective

After completing this lesson, you will be able to classify technical data types in ABAP

Data Types in ABAP

Recap - Some Predefined ABAP Types

Let's have a quick recap of the predefined ABAP types that you learned about earlier in your learning journey. We will also look at some additional complete and incomplete data types.

The above figure shows the data types that you learned about in your previous learning journey. The types STRING, I, D, and T are known as complete types, because you cannot alter their length. The types C, N, and P are known as incomplete types. When you declare a variable with one of these types, you must specify the length and, in the case of type P, the number of decimal places.

As well as the four complete data types that you have already encountered (STRING, I, D, and T), there are six more:

  • INT8 - 8-byte integer
  • DECFLOAT16 - Decimal floating point number with 16 digits
  • DECFLOAT34 - Decimal floating point number with 34 digits
  • F - Binary floating point number
  • XSTRING - Byte sequence of any length
  • UTCLONG - Timestamp

In addition to the types C, N, and P, ABAP also has a built-in type X for byte sequences. Type X is incomplete, meaning you must specify a length when you declare variables using this type.

Classification of Data Types

As well as distinguishing between complete and incomplete data types, we can classify the built-in ABAP data types as character-like, numeric, byte-like, and date and time. This distinction is important as certain operations are only allowed for character-like fields, and others only for numeric fields. You cannot mix character and byte fields in a single operation.

When choosing numeric types, you should use type I if you need whole numbers, and type P for numbers with decimal places. You can use type INT8 if the range of type I is too small. Equally, use one of the DECFLOAT types if the range or accuracy of type P is insufficient. A packed number can have up to 14 decimal places. The DECFLOAT data types, in particular DECFLOAT34, support a significantly higher accuracy.

Type F is for binary floating point numbers. Since rounding errors can occur when converting binary numbers back into the decimal system, you should avoid using type F for calculations in your programs. However, floating point numbers figure prominently when you read data from the database using SQL.

For date and time fields, you can use the types D and T. Type D uses the format YYYYMMDD and type T the format HHMMSS. Type T is only accurate to the second - if you need a higher accuracy you can use the type UTCLONG. This is a timestamp comprising both date and time and is accurate to 100 nanoseconds.

Log in to track your progress & complete quizzes