ABAP Keyword Documentation →  ABAP Programming Guidelines →  Robust ABAP →  Assignments, Calculations, and Other Types of Data Access → 

Selecting the Numeric Type

Background

Several numeric types with various properties and value ranges are available in ABAP, which you can use for storing numbers and for calculations:

The decimal floating point numbers meet the requirements for highly exact processing of decimal numbers in a large value ranges, where the data types p and f only cover a single aspect each.

Rule

Select suitable numeric types for numbers and calculations

Select a numeric type to suit the values that you want to map, in order to achieve the highest possible speed and accuracy. Here is a general rule of thumb:

Details

The calculation speed and accuracy are generally contradictory requirements and depend on the data type of the objects to be processed. Therefore, when selecting the numeric type, you must weigh up these two requirements. These considerations must also include the value range to be mapped:

Thanks to the hardware support available on all platforms, binary floating point type f allows fast calculations. However, it is inferior to the new decimal floating point types due to the following reasons:

Note

For programs that are currently created with decimal floating point types, the performance is increased as soon as the processor architecture supports decimal floating point calculations and the ABAP runtime environment starts using this hardware support. Calculations with decimal floating point numbers then become faster than calculations with packed numbers.

Bad Example

The following source code shows a declaration of a binary floating point number. The start value 0.815 is assigned. The true start value, however, is 8.1499999999999995E-01.

DATA number TYPE f VALUE '0.815'.

Good Example

The following source code shows a declaration of a decimal floating point number. The start value 0.815 is assigned. The true start value is actually 8.15E-01.

DATA number TYPE decfloat34 VALUE '0.815'