SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Assignments → Lossless Assignments →EXACT - Lossless Operator
Syntax
... EXACT type( dobj ) ...
Effect
A constructor expression with the lossless operator EXACT performs either a lossless assignment or a lossless calculation (depending on the specified argument dobj) and creates a result with the data type type. The following can be specified for type:
The parentheses must contain precisely one unnamed argument dobj that can be converted to the data type type. dobj is a general expression position. The content of the result is defined as follows:
If data is lost in either case, the corresponding exception is raised. If the argument is compatible with the data type type in a lossless assignment, EXACT does not perform any checks and a syntax check warning is produced.
Note
The lossless operator EXACT replaces the identically named addition of the obsolete statements MOVE and COMPUTE.
Example
Lossless assignment. Here, the exception CX_SY_CONVERSION_ERROR is raised, because the argument contains an invalid value.
TYPES numtext TYPE n LENGTH 255.
TRY.
DATA(number) = EXACT numtext( '4 Apples + 3 Oranges' ).
CATCH cx_sy_conversion_error INTO DATA(exc).
...
ENDTRY.
Example
Lossless assignment with generic types. The first method call produces a successful assignment; the second raises the exception CX_SY_CONVERSION_EXACT_NOT_SUP. If the assignment is replaced by p2 = EXACT #( + p1 ), a lossless calculation is produced and no exception is raised.
CLASS c1 DEFINITION.
PUBLIC SECTION.
CLASS-METHODS m1 IMPORTING p1 TYPE data
EXPORTING p2 TYPE data.
ENDCLASS.
CLASS c1 IMPLEMENTATION.
METHOD m1.
DATA arg TYPE i.
TRY.
p2 = EXACT #( p1 ) ##operator.
cl_demo_output=>display_data( p2 ).
CATCH cx_sy_conversion_exact_not_sup
cx_sy_conversion_error INTO DATA(err).
cl_demo_output=>display_text( err->get_text( ) ).
ENDTRY.
ENDMETHOD.
ENDCLASS.
DATA: date TYPE d,
text TYPE string.
START-OF-SELECTION.
c1=>m1( EXPORTING p1 = sy-timlo
IMPORTING p2 = text ).
c1=>m1( EXPORTING p1 = sy-timlo
IMPORTING p2 = date ).
Example
Lossless calculation. Here, the exception CX_SY_CONVERSION_ROUNDING is raised, because the calculation is not lossless. The rounded result is assigned to the inline declared variable rounded_result.
TRY.
DATA(exact_result) = EXACT #( 3 * ( 1 / 3 ) ).
CATCH cx_sy_conversion_rounding INTO DATA(exc).
DATA(rounded_result) = exc->value.
ENDTRY.
Catchable Exceptions
CX_SY_CONVERSION_EXACT_NOT_SUP