SAP DDIC DECIMAL FLOATING POINT



Get Example source ABAP code based on a different SAP table
  



ABAP_DDIC - Decimal Floating Point Numbers
In decimal floating point numbers, a maximum of 16 or 34 places exactly are returned in the mantissa depending on the data type.
ITOC

Handling in ABAP Dictionary
In ABAP Dictionary, the following data types are available for decimal floating numbers.

Decimal Floating Point Types
The following built-in ABAP Dictionary data types represent real floating point types of a database:
DECFLOAT16 for 16-digit numbers.
DECFLOAT34 for 34-digit numbers.
They can be used, without restrictions, as numeric data types in appropriate expressions and functions. They are currently only supported by SAP HANA databases.

Replacement Types
The following built-in data types in ABAP Dictionary are used as replacements for real decimal floating point types:
DF16_DEC and DF16_RAW for 16-digit numbers.
DF34_DEC and DF34_RAW for 34-digit numbers.
These types can be used as replacements on database systems that do not support decimal floating point types. They are mainly used to save decimal floating point numbers from ABAP programs and can be used in a limited way as numeric data types in appropriate expressions and functions:
DF16_DEC and DF34_DEC In database fields of this type, decimal floating point numbers are stored as a packed number (format DEC). The length and the number of decimal places must be specified when defining a data type in ABAP Dictionary. For this type, restricted operations can be performed on the database:
No operands of these types can be used in arithmetic SQL expressions or numeric SQL functions.
Columns, but no SQL expressions of these types, can be used as operands in the aggregate functions except for STRING_AGG.
In the statement UPDATE, operations with these types are possible with SET + and -.
Database fields with these types can be processed in
BEGIN_SECTION VERSION 5 OUT Native SQL or
END_SECTION VERSION 5 OUT AMDP.
When there is a write to the database, the system implicitly rounds off to the number of decimal places and decimal overflows can occur.
DF16_RAW and DF34_RAW In database fields of this type, decimal floating point numbers are stored as binary (in RAW format). The length is set to 16 or 34 places. Values can be sorted, compared, and used in indexes. For this type, no calculations can be performed on the database. This is an SAP-specific format, which means that the corresponding fields also cannot be processed in
BEGIN_SECTION VERSION 5 OUT Native SQL or
END_SECTION VERSION 5 OUT AMDP. The scaling is lost when writing to the database.



Latest notes:

If possible, the types DECFLOAT16 and DECFLOAT34 should be used.
If it is necessary to work with the replacement types, the intended use case determines which type is to be used:
The types DF16_DEC and DF34_DEC can be used for calculations on the database, but their value ranges are smaller than those of real decimal floating point numbers.
The types DF16_RAW and DF34_RAW cover the whole value range, but are not recognized as numbers by the databases.
As in the general packed numbers , the number of places in the replacement types DF16_DEC and DF34_DEC should be odd.
In ABAP CDS it is not usually possible to execute expressions or functions for the replacement types.
NON_V5_HINTS
As well as the types above, there are also the obsolete replacement types DF16_SCL and DF34_SCL for decimal floating point numbers with scaling.
In database fields of this type, decimal floating point numbers are stored in the same way as DF16_RAW or DF34_RAW (length 16 or 34 places, and the same restrictions apply). 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.
It is strongly advised not to use the types DF16_SCL and DF34_SCL. Their functions are rarely needed and the additional column for scaling makes them too complicated and error-prone to use correctly.
ABAP_HINT_END
BEGIN_SECTION VERSION 5 OUT

Handling in Dynpros - Output Length and Output Style
The maximum output length that can be specified in a domain for a 16-character decimal floating point number is 24. For a 34-character number, 46 is the maximum output length. These are also the default values.
In a domain, or directly in a structure component created using one of the types for decimal floating numbers (but not in data elements with directly specified technical properties), one of the following output styles is always defined. The output style defines how a dynpro field defined with reference to this domain (or a corresponding ABAP field in the case of list output) is formatted:
Normal Mathematical or scientific notation (depending on space).
Sign right Commercial notation. If not enough space is available, the operation is canceled. No implicit transformation to scientific notation takes place.
Scale-preserving Format with preservation of scaling, including trailing zeros in the decimal places.
Scientific Scientific notation.
Scientific with leading zero Scientific notation with a 0 as an integer digit.
Scale-preserving scientific Scientific notation including trailing zeros in the mantissa.
Engineering Scientific notation where the exponent is always an integer and a multiple of 3. The value range of the integer digits is between 1 and 999, except if the source field has the value 0.
For dynpro fields whose data type is not defined in ABAP Dictionary, the output style can also be determined in Screen Painter. In the case of formatting with string templates or with the statements WRITE or WRITE TO, the addition STYLE is available.



Latest notes:

If scientific notation is used, a limited number of displayed positions of the mantissa can be useful. This can be achieved using the built-in function rescale.
The scale-preserving style ensures that the scaling is restored in conversions from dynpro fields to ABAP, and not just the original value.
If vertically aligned decimal separators and exponents are needed on UIs, the scale-preserving scientific notation can be used.
NON_V5_HINTS
ABAP_HINT_END
END_SECTION VERSION 5 OUT

Handling in ABAP Programs
The ABAP types that correspond to the 16- or 34-digit decimal floating numbers in ABAP Dictionary are decfloat16 and decfloat34. They are handled internally according to the IEEE-754-2008 standard, and are supported by all ABAP operations. There is restricted support for floating point numbers with replacement types in SQL expressions. In arithmetic SQL expressions, only those decimal floating point numbers are supported that are based on the decimal floating point types.
The addition STYLE after WRITE $[TO$] and the formatting option STYLE in embedded expressions are available for the formatting of decimal floating numbers in programs. These overwrite the output style defined in ABAP Dictionary. When the addition CURRENCY is used after WRITE $[TO$] for a decimal floating number defined in the ABAP Dictionary, it must be defined with the output style Sign right, otherwise an exception occurs.