Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Assignments →  Lossless Assignments 

EXACT - Lossless Operator

Other versions: 7.31 | 7.40 | 7.54

Syntax


... EXACT type( [let_exp] 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 # character for a data type, determined in accordance with the following hierarchy:
  • If the data type required in an operand position is unique and fully recognized, the operand type is used. The operand type can also be generic and the current type is used at runtime.
  • If the data type cannot be derived from the context, the calculation type decfloat34 is used in lossless calculations and the data type of the argument is used in lossless assignments.

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 the argument dobj is specified as an arithmetic expression, the expression is calculated in accordance with the rules for a lossless assignment and the result (with calculation type decfloat34) is converted to the data type type.
  • In all other cases, the content of the result is defined by an assignment of the argument in accordance with the associated conversion rules, during which a check is performed in accordance with the rules of lossless assignments.

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.

A LET expression let_exp can be specified (optional) before the argument to define local auxiliary fields.


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.

Exceptions


Catchable Exceptions

CX_SY_CONVERSION_EXACT_NOT_SUP

  • Cause: Invalid combination of types or lengths.
    Runtime Error: CONVT_NOT_SUPPORTED