With Release 7.40 ABAP supports so called constructor operators. Constructor operators are used in constructor expressions to create a result that can be used at operand positions. The syntax for constructor expressions is
... operator type( ... ) ...
operator is a constructor operator. type is either the explicit name of a data type or the character #. With # the data type can be dreived from the operand position if the operand type is statically known. Inside the parentheses specific parameters can be specified.
The lossless operator EXACT is a constructor operator that exceutes either a lossless calculation or a lossless assignment.
Lossless calculations were introduced for decimal floating point numbers in Release 7.02 with the addition EXACT to COMPUTE. This addition (better the whole statement COMPUTE) became obsolete now.
A lossless calculation must not perform any roundings. If it does, an exception occurrs.
TRY.
DATA(r1) = EXACT decfloat34( 3 / 2 ).
cl_demo_output=>write( |Exact: { r1 }| ).
CATCH cx_sy_conversion_rounding INTO DATA(e1).
cl_demo_output=>write( |Not exact: { e1->value }| ).
ENDTRY.
TRY.
DATA(r2) = EXACT decfloat34( 3 / 7 ).
cl_demo_output=>write( |Exact: { r2 }| ).
CATCH cx_sy_conversion_rounding INTO DATA(e2).
cl_demo_output=>write( |Not exact: { e2->value }| ).
ENDTRY.
cl_demo_output=>display( ).
The output is:
Exact: 1.5
Not exact: 0.4285714285714285714285714285714286
You see that the non-exact result can be found in th exception object.
Lossless assignments were introduced for conversions in Release 7.02 with the addition EXACT to MOVE. This addition (better the whole statement MOVE) became obsolete now.
A lossless assignment is an assignment where
TYPES numtext TYPE n LENGTH 10.
cl_demo_output=>write( CONV numtext( '4 Apples + 2 Oranges' ) ).
TRY.
DATA(number) = EXACT numtext( '4 Apples + 2 Oranges' ).
CATCH cx_sy_conversion_error INTO DATA(exc).
cl_demo_output=>write( exc->get_text( ) ).
ENDTRY.
cl_demo_output=>display( ).
The result is
0000000042
The argument '4 Apples + 2 Oranges' cannot be interpreted as a number
The infamous conversion rule from c to n is not supported by EXACT.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |