For calculations in business applications, use packed numbers. The program attribute Fixed point arithmetic affects calculations using packed numbers.
If the program attribute Fixed point arithmetic is not set, type P fields are interpreted as integers without decimal places. The decimal places that you specify in the DECIMALS addition of the TYPES or DATA statement only affect how the field is formatted in the WRITE statement.
DATA: pack TYPE p DECIMALS 2.
pack = '12345'.
If the program attribute Fixed point arithmetic is not set, the output is as follows:
If the program attribute Fixed point arithmetic is set, the output is as follows:
If the Fixed point arithmetic attribute is set, the decimal places are also taken into account in arithmetic operations. Calculations with packed numbers in ABAP use the same arithmetic as a calculator. Intermediate results are calculated using up to 31 digits (before and after the decimal point). You should therefore always set the Fixed point arithmetic attribute when you use type p fields.
REPORT demo_data_packed_numbers .
DATA: pack TYPE p DECIMALS 0.
pack = 1 / 3 * 3.
If you have not set the Fixed point arithmetic attribute, the result is 0, since the calculation is performed using integer accuracy, and the result is therefore rounded internally to 0.
If the program attribute Fixed point arithmetic is set, the result is 1 because the result of the division is stored internally as 0.333333333333333333333333333333 with an accuracy of up to 31 digits.