SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Release-Specific Changes → Changes in Release 7.0, EhP2 →
Decimal Floating Point Numbers in Release 7.0, EhP2
Decimal floating point numbers with the types decfloat16 and decfloat34 have been introduced in ABAP to satisfy the demand for more precise processing of decimal numbers with a large range of values. The existing ABAP type p (packed number) represents a decimal number precisely and can be calculated precisely (apart from unavoidable commercial rounding), but the value range is often too small. The existing ABAP type f (binary floating point number) has a large value range, but cannot represent every decimal number precisely due to the internal binary representation.
Both of these requirements are satisified by decimal floating point numbers. Unlike binary floating
point numbers, decimal floating point numbers are represented internally with a decimal mantissa. Each
decimal number can be represented precisely within the length of the mantissa (16 or 34) and it can
be used for calculations in the same way as with type p. Unlike type
p, the number of decimal places is not a property of the data type; an exponent of the value
determines the decimal places instead. This means that decimal floating point numbers have the advantage of providing a very large range of values.
1. New predefined ABAP types decfloat16 and decfloat34
2. New predefined types in ABAP Dictionary
3. New predefined functions round and rescale
5. Methods for decimal floating point numbers
6. Formatting of decimal floating point numbers using WRITE
New predefined ABAP types decfloat16 and decfloat34
From Release 7.0, EhP2, ABAP includes the new predefined numeric ABAP types decfloat16 and decfloat34 for decimal floating point numbers. The corresponding data objects are eight bytes or 16 bytes long and the data objects are aligned in their lengths. The value range is determined by mantissas of the length -383 and +384 or. -6143 and +6144. The new generic ABAP type decfloat covers both new types, decfloat16 and decfloat34.
The following changes have been caused by the new types:
New predefined types in ABAP Dictionary
The following new types have been introduced in ABAP Dictionary for the new ABAP types decfloat16 and decfloat34:
Data elements with these types can be used to declare fields in database tables and in dynpros. An
output style can be specified in a domain or directly in a structure component created with one
of these types. For dynpro fields whose data type is not defined in ABAP Dictionary, the output style can be defined in
Screen Painter.
New predefined functions round and rescale
The new rounding functions
round and rescale enable decimal floating point numbers to be rounded or their
scaling to be changed. New constants
have been added to the class CL_ABAP_MATH. These constants can be used to specify the rounding rule.
Lossless Calculations
The new addition EXACT of the statement COMPUTE can be used to force a
lossless calculation
for decimal floating point numbers, under certain prerequisites. No roundings are allowed in a lossless calculation; they raise the exception CX_SY_CONVERSION_ROUNDING.
Methods for decimal floating point numbers
Methods for operations with floating point numbers have been added to the class CL_ABAP_MATH.
The new class CL_ABAP_DECFLOAT contains special methods for decimal floating point numbers.
Formatting of decimal floating point numbers using WRITE
Predefined formats have been defined for the new types decfloat16 and decfloat34 for the statements WRITE ... TO for formatted assignments and WRITE for list outputs. The predefined output lengths for list output are 24 and 46.
The new addition STYLE has been added to the WRITE statements for the formatting of decimal floating point numbers with different formats.