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 predefined functions are abs, sign, ceil, floor, trunc, frac, round, and rescale. These functions do not raise the exception CX_SY_CONVERSION_ROUNDING. No other predefined 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 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

    See Lossless Calculations


    Exceptions


    Catchable 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 - Example