Ansicht
Dokumentation

ABAPCOMPUTE_ARITH - COMPUTE ARITH

ABAPCOMPUTE_ARITH - COMPUTE ARITH

PERFORM Short Reference   BAL Application Log Documentation  
This documentation is copyright by SAP AG.
SAP E-Book

Arithmetic Expressions ()

Short Reference



... $[+$|-$] operand1
    $[${+$|-$|*$|/$|DIV$|MOD$|**$} $[+$|-$] operand2
    $[${+$|-$|*$|/$|DIV$|MOD$|**$} $[+$|-$] operand3
    ... $]$] ...


Effect

An arithmetic expression expresses a calculation. The result of an arithmetic expression is a numeric value that exists in the calculation type that is assigned to the arithmetic expression. In an arithmetic expression arith_exp, the arithmetic operators +, -, *, /, DIV, MOD, or ** can be used to combine an operand operand1 with one or more operands operand2, operand3 ... Brackets are also possible. The calculation is based on calculation rules that depend on the respective calculation type.

Arithmetic expressions can occur in the read positions of certain statements, in particular on the right side of an assignment with the assignment operator =. When used as the operand of the lossless operator EXACT, an arithmetic expression can be checked for a lossless calculation.

The operand positions operand are general expression positions, that is, numeric data objects, built-in functions, functional methods, or compound arithmetic expressions can be specified. The arithmetic operators +, -, *, /, DIV, MOD, and ** combine two adjacent operands. When the expression is evaluated, a numeric value is calculated and combined with the next adjacent operand. The priority of this combination depends on the operators used.

Each operand can be preceded by the signs + or -, in any order and separated by one or more blanks. The effect of a plus/minus sign is the same as specifying the expression +1 * or -1 * in its place, which means that a sign has the same priority as a multiplication.

If functional methods or character-like expressions are specified as operands, they are executed from left to right and from inside to outside before the remainder of the expression is evaluated. The return values are buffered for use in the corresponding operand positions. Here, character-like processing functions and string expressions are only possible as arguments of description functions.

Notes

  • It should be ensured that the value of a data object that is also used as an operand is changed in a specified functional method. Even if such an operand is to the left of the functional method, its value will always be changed by the method before it is evaluated.
  • Arithmetic expressions, string expressions, and bit expressions cannot be combined. Built-in functions that are used as operands for arithmetic expressions can, however, contain string expressions or bit expressions as arguments.
  • A simple arithmetic expression +$|- literal, which is comprised of an operator +$|-, a blank, and an unsigned numeric literal literal, has the same value as the corresponding numeric literal +$|-literal prefixed directly with a plus/minus sign. However, since the expression is handled like an expression and always evaluated at runtime, the numeric literal should always be used in these cases for performance reasons.

Example

The following program section calculates the hyperbolic sine with the Eulerian formula in the explicit calculation type decfloat34 and with the built-in function sinh in the implicit calculation type f and displays the difference.

Example

The following program demonstrates the rule specifying how functional methods are evaluated in arithmetic expressions. The first calculation sets the variable changing to 6 and returns the expected result of 9. The result of the second calculation is 15 and not 10 as might be expected. The functional method is called first and its result 9 is added to the changed value 6 of variable changing and not to its initial value 1.

Exceptions

Catchable Exceptions

CX_SY_ARG_OUT_OF_DOMAIN

  • Cause: Invalid call of acos
    Runtime Error: COMPUTE_ACOS_DOMAIN (catchable)
  • Cause: Invalid call of asin
    Runtime Error: COMPUTE_ASIN_DOMAIN (catchable)

  • Cause: Invalid call of cos
    Runtime Error: COMPUTE_COS_DOMAIN (catchable)
  • Cause: Invalid call of log10
    Runtime Error: COMPUTE_LOG10_ERROR (catchable)
  • Cause: Invalid call of log
    Runtime Error: COMPUTE_LOG_ERROR (catchable)
  • Cause: Illegal argument in powers
    Runtime Error: COMPUTE_POW_DOMAIN (catchable)
  • Cause: Invalid call of sin
    Runtime Error: COMPUTE_SIN_DOMAIN (catchable)
  • Cause: Invalid call of sqrt
    Runtime Error: COMPUTE_SQRT_DOMAIN (catchable)
  • Cause: Invalid call of tan
    Runtime Error: COMPUTE_TAN_DOMAIN (catchable)

CX_SY_ARITHMETIC_OVERFLOW

  • Cause: Overflow in arithmetic operation (type p)
    Runtime Error: BCD_OVERFLOW (catchable)
  • Cause: Overflow in arithmetic operation (all operands of type p)
    Runtime Error: COMPUTE_BCD_OVERFLOW (catchable)
  • Cause: Overflow in cosh
    Runtime Error: COMPUTE_COSH_OVERFLOW (catchable)
  • Cause: Overflow or underflow in exp
    Runtime Error: COMPUTE_EXP_RANGE (catchable)
  • Cause: Overflow at addition (type decfloat)
    Runtime Error: COMPUTE_DECFLOAT_ADD_OVERFLOW
  • Cause: Overflow at subtraction (type decfloat)
    Runtime Error: COMPUTE_DECFLOAT_SUB_OVERFLOW
  • Cause: Overflow at multiplication (type decfloat)
    Runtime Error: COMPUTE_DECFLOAT_MUL_OVERFLOW
  • Cause: Overflow at division (type decfloat)
    Runtime Error: COMPUTE_DECFLOAT_DIV_OVERFLOW
  • Cause: Overflow at division (type decfloat)
    Runtime Error: COMPUTE_DECFLOAT_DIV_OVERFLOW
  • Cause: Overflow at division (type f)
    Runtime Error: COMPUTE_FLOAT_DIV_OVERFLOW (catchable)
  • Cause: Overflow at subtraction (type f)
    Runtime Error: COMPUTE_FLOAT_MINUS_OVERFLOW (catchable)
  • Cause: Overflow at addition (type f)
    Runtime Error: COMPUTE_FLOAT_PLUS_OVERFLOW (catchable)
  • Cause: Overflow at multiplication (type f)
    Runtime Error: COMPUTE_FLOAT_TIMES_OVERFLOW (catchable)
  • Cause: Overflow at |-2147483648|
    Runtime Error: COMPUTE_INT_ABS_OVERFLOW (catchable)
  • Cause: Whole-number overflow at division
    Runtime Error: COMPUTE_INT_DIV_OVERFLOW (catchable)
  • Cause: Whole-number overflow at subtraction
    Runtime Error: COMPUTE_INT_MINUS_OVERFLOW (catchable)
  • Cause: Whole-number overflow at addition
    Runtime Error: COMPUTE_INT_PLUS_OVERFLOW (catchable)
  • Cause: Whole-number overflow at multiplication
    Runtime Error: COMPUTE_INT_TIMES_OVERFLOW (catchable)
  • Cause: Invalid call of log10
    Runtime Error: COMPUTE_LOG10_ERROR (catchable)
  • Cause: Invalid call of log
    Runtime Error: COMPUTE_LOG_ERROR (catchable)
  • Cause: Overflow or underflow at powers
    Runtime Error: COMPUTE_POW_RANGE (catchable)
  • Cause: Overflow at sinh
    Runtime Error: COMPUTE_SINH_OVERFLOW (catchable)
  • Cause: Overflow at function round or rescale
    Runtime Error: COMPUTE_ROUND_RESCALE_OVERFLOW

CX_SY_CONVERSION_NO_NUMBER

  • Cause: Operand cannot be interpreted as a number
    Runtime Error: CONVT_NO_NUMBER (catchable)

CX_SY_CONVERSION_OVERFLOW

  • Cause: Overflow at arithmetic operation (type p, with specified length)
    Runtime Error: BCD_FIELD_OVERFLOW (catchable)
  • Cause: Operand too big or (interim) result too big
    Runtime Error: CONVT_OVERFLOW (catchable)

CX_SY_PRECISION_LOSS

  • Cause: Result of cos inexact
    Runtime Error: COMPUTE_COS_LOSS (catchable)
  • Cause: Result of sin inexact
    Runtime Error: COMPUTE_SIN_LOSS (catchable)
  • Cause: Result of tan inexact
    Runtime Error: COMPUTE_TAN_LOSS (catchable)

CX_SY_UNSUPPORTED_FUNCTION

  • Cause: Illegal function for calculation type decfloat34
    Runtime Error: COMPUTE_UNSUPPORTED_DECF_FUNC

CX_SY_ZERODIVIDE

  • Cause: Division by 0 (type p)
    Runtime Error: BCD_ZERODIVIDE (catchable)
  • Cause: Division by 0 (type f)
    Runtime Error: COMPUTE_FLOAT_ZERODIVIDE (catchable)
  • Cause: Division by 0 (type i)
    Runtime Error: COMPUTE_INT_ZERODIVIDE (catchable)
  • Cause: Division by 0 (type decfloat)
    Runtime Error: COMPUTE_DECFLOAT_ZERODIVIDE


Non-Catchable Exceptions

  • Cause: p field contains an incorrect BCD format
    Runtime Error: BCD_BADDATA
  • Cause: p field does not contain a correct algebraic sign
    Runtime Error: BCD_NO_SIGN





CL_GUI_FRONTEND_SERVICES - Frontend Services   BAL_S_LOG - Application Log: Log header data  
This documentation is copyright by SAP AG.

Length: 17182 Date: 20240329 Time: 031205     sap01-206 ( 187 ms )