Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Numeric Calculations →  arith_exp - Arithmetic Expressions 

arith_exp - Lossless Calculations

A lossless calculation is a calculation of an arithmetic expression in which no roundings occur. Lossless calculations can be performed using the lossless operator EXACT:

Other versions: 7.31 | 7.40 | 7.54

Syntax


... EXACT type( arith_exp ) ....

If the operand of the operator EXACT is an arithmetic expression, the data type specified by type cannot have the type f. arith_exp must be an arithmetic expression simplified as follows:

  • The permitted arithmetic operators are +, -, *, and /. The operators DIV, MOD, and ** cannot be used.
  • The permitted built-in functions are abs, sign, ceil, floor, trunc, frac, round, and rescale. These functions do not raise the exception CX_SY_CONVERSION_ROUNDING. No other built-in functions can be specified because their results are not lossless (in principle).
  • No operands of data type x and xstring can be specified.
  • No functional methods can be specified, since the losslessness requirements cannot be applied to the method execution.
  • Operands of the type f (binary floating point numbers) are not permitted because they cannot represent every decimal number precisely, due to their internal representation.
  • The operator EXACT specifies that a simplified expression with the calculation type decfloat34 is calculated and checks whether roundings are performed. If roundings are not performed, the result is assigned to the return value (if necessary, the result is converted from decfloat34 to the data type determined by type. If a rounding is required by the calculation, the exception CX_SY_CONVERSION_ROUNDING is raised. Rounding can take place when operands are converted to the calculation type, during the calculation, or when the result is converted to the target field.

    The exception is raised when the first subexpression that requires a rounding is calculated. When the exception is handled, the VALUE attribute in the exception object contains the result provided by a regular calculation. The attribute OPERATION contains the first operation that had to be rounded; conversions are represented by ":=".


    Notes

    • The first calculation in lossless calculations that requires rounding raises an exception. This means that arithmetic expressions that are mathematically identical but constructed in different ways can display different behavior (see the executable example).

    • If the operand of the operator EXACT is not an arithmetic expression, the operator performs a lossless assignment.

    • The use of the addition EXACT in the obsolete statement COMPUTE is an obsolete form of lossless calculation.

    Example

    The second arithmetic expression raises an exception, since it requires rounding to two decimal places.

    TYPES pack TYPE p LENGTH 8 DECIMALS 2. 
    
    DATA(result1) = EXACT pack( 1 / 4 ). 
    
    DATA(result2) = EXACT pack( 1 / 3 ). 
    

    Executable Example

    Lossless Calculations

    Executable Example

    Floating Point Numbers, Arithmetic Calculations

    Exceptions

    Handleable Exceptions

    CX_SY_TYPE_NOT_EXACT

    • Cause: Invalid operand type for lossless calculations
      Runtime error: UNCAUGHT_EXCEPTION

    CX_SY_CONVERSION_ROUNDING

    • Cause: Rounding in a lossless calculation
      Runtime error: UNCAUGHT_EXCEPTION

    Continue

    Lossless Calculations