ABAP Keyword Documentation → ABAP - Release-Specific Changes → Changes in Release 7.0 and its EhPs → 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 satisfied 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 built-in ABAP types decfloat16
and decfloat34
2. New built-in types in ABAP Dictionary
3. New built-in functions round
and rescale
5. Methods for decimal floating point numbers
6. Formatting of decimal floating point numbers using WRITE
Other versions: 7.31 | 7.40 | 7.54
Modification 1
New Built-In ABAP Types decfloat16 and decfloat34
From Release 7.0, EhP2, ABAP includes the new built-in
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 conversion and comparison rules have been introduced for the new types.
-
If a decimal floating point number appears in an arithmetic expression, the
calculation type is
decfloat34
. -
The floating point
functions
exp
,log
,log10
, andsqrt
now no longer work just with arguments of typef
; they now also work with arguments of typedecfloat16
anddecfloat34
. The type of the argument determines the type of the return code. Decimal floating point numbers cannot be used as arguments for the remaining floating point functions at the moment.
Modification 2
New Built-In Types in ABAP Dictionary
The following new types have been introduced in ABAP Dictionary for the new ABAP types decfloat16
and decfloat34
:
- DF16_DEC and DF34_DEC are used by database fields in which decimal floating point numbers, such as packed numbers with type DEC are stored. Database writes can cause roundings and overflows.
- DF16_RAW and DF34_RAW are used by database fields in which decimal floating point numbers are stored in their internal representation.
-
DF16_SCL and
DF34_SCL are used by database fields in which
decimal floating point numbers are stored with their scaling. In this kind of field, the decimal floating
point numbers are stored as in DF16_RAW or DF34_RAW. The scaling must be specified in a direct successor
database field with type INT2. When a decimal floating point number is written, this field is filled
automatically with the scaling and the scaling is taken from it in reads. These data types are now obsolete and their use is strongly discouraged.
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.
Modification 3
New Built-In 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.
Modification 4
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.
Modification 5
Methods for Decimal Floating Point Numbers
Methods for operations with floating point numbers have been added to the class CL_ABAP_MATH.
- The method GET_SCALE gets the scaling of a decimal floating point number.
- The method GET_NUMBER_OF_DIGITS gets the precision of a decimal floating point number.
- The method NORMALIZE gets a normalized floating point number. This means that the scaling and precision of an input value are changed so that the mantissa has no trailing zeros.
- The method GET_MAX_DB_VALUE returns the maximum value of a number of the type DF16_DEC or DF34_DEC on the database (from EhP1).
-
The method GET_DB_LENGTH_DECS returns the length and number of decimal places of a number of the type DF16_DEC or DF34_DEC on the database (from EhP1).
The new class CL_ABAP_DECFLOAT contains special methods for decimal floating point numbers.
-
The methods READ_DECFLOAT34 and READ_DECFLOAT16 convert character-like data objects to decimal floating point numbers and, unlike regular assignments, enable enhanced exception handling.
Modification 6
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 output. 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.