ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Assignments → Lossless Assignments → EXACT - Lossless Operator
EXACT - Lossless Conversion of Enumerated Types
If the constructor expression CONV is applied to
enumerated types, the same
rules apply as for the conversion operator CONV:
- An enumerated object can be converted to the
base type if its enumerated type, as with
CONV.
... EXACT base_type( enum_dobj ) ...
- A data object that can be converted to the base type of an
enumerated type can be converted to the enumerated type, as with
CONV.
... EXACT enum_type( dobj ) ...
The conditions of losslessness also apply:
- If a data object that can be converted to the base type is converted to the enumerated type, this happens in accordance with the rules of lossless assignment.
- If an arithmetic expression is used as the argument of a conversion to the enumerated type, the result must be obtained in accordance with the rules of lossless calculation.
Other versions:
7.31 | 7.40 | 7.54
Example
If the conversion operator is used, the argument is converted to the base type c with length 4, with surplus places cut off. If the Lossless operator is used, this results in an exception.
TYPES:
char8 TYPE c LENGTH 4,
BEGIN OF ENUM text BASE TYPE char8,
first VALUE IS INITIAL,
second VALUE 'Seco',
third VALUE 'Thrd',
END OF ENUM text.
DATA(result1) = CONV text( `Seco` && `nd` ).
TRY.
DATA(result2) = EXACT text( `Seco` && `nd` ).
CATCH cx_sy_conversion_data_loss.
cl_demo_output=>display( `Oops!` ).
ENDTRY.
If an arithmetic expression is used in the conversion operator, the result is converted to the base
type i, with the decimal places cut off. If the Lossless operator is used, this results in an exception.
TYPES:
BEGIN OF ENUM number,
n0, n1, n2,
END OF ENUM number.
DATA(result1) = CONV number( + '1.2' ).
TRY.
DATA(result2) = EXACT number( + '1.2' ).
CATCH cx_sy_conversion_rounding.
cl_demo_output=>display( `Oops!` ).
ENDTRY.