Ansicht
Dokumentation

ABENLOSSLESS_CALCULATION - LOSSLESS CALCULATION

ABENLOSSLESS_CALCULATION - LOSSLESS CALCULATION

General Material Data   Addresses (Business Address Services)  
This documentation is copyright by SAP AG.
SAP E-Book

- 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:

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

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

  • The allowed arithmetic operators are +, -, *, and /. The operators DIV, MOD, and ** cannot be used.
  • The allowed 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 requirement for losslessness cannot be applied to the method execution.
  • Operands of the type f (binary floating point numbers) are not allowed because they cannot represent every decimal number precisely, due to their internal representation.

The operator EXACT ensures that a simplified expression with the calculation type decfloat34 is calculated and checks whether roundings are performed. If no roundings occur, 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 occur 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. If the exception is handled, the exception object in the VALUE attribute contains the result of a regular calculation. The attribute OPERATION contains the first operation that had to be rounded, whereby conversions are represented by ":=".

Notes

  • Since the first calculation in lossless calculations that requires rounding raises an exception, the behavior in arithmetic expressions that are mathematically identical but constructed in different ways can be different (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.

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

Lossless Calculations

Example

Refer to Decimal Floating Point Numbers, Arithmetic 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





CL_GUI_FRONTEND_SERVICES - Frontend Services   RFUMSV00 - Advance Return for Tax on Sales/Purchases  
This documentation is copyright by SAP AG.

Length: 5259 Date: 20240420 Time: 024255     sap01-206 ( 78 ms )