What does it do? An arithmetic expression expresses a calculation. The result of an arithmetic expression is a numeric value of the calculation type assigned to the arithmetic expression. In an arithmetic expression arith_exp, the arithmetic operators +, -, *, /, DIV, MOD, or ** can be used to join an operand operand1 with one or more operands operand2 , operand3 ... Brackets are also possible. Arithmetic expressions can occur in the reader 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 aregeneral expression positions, which means that numeric data objects, predefined functions, functional methods , or compound arithmetic expressions can be specified. The arithmetic operators +, -, *, /, DIV, MOD , and ** join two adjacent operands. When the expression is evaluated, a numeric value is calculated and joined with the next adjacent operand. The priority of this join 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 using a sign is the same as specifying the expression +1 * or -1 *, which means that a sign has the same priority as a multiplication.
If functional methods orcharacter-like expressions are specified as operands, they are listed from left to right and from inside to outside before the remainder of the expression is evaluated. The return values are buffered to be used in the corresponding operand positions. Here, character-like processing functions and string expressions are only possible as arguments of description functions. ABAP_HINTs Note whether the value of a data object that is also used as an operand is changed in a specified functional method. Even if an operand of this type precedes 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. Predefined functions that are used as operands for arithmetic expressions can, however, contain string expressions or bit expressions as arguments. If an arithmetic expression is specified as an argument of one of the overloaded numeric functions, the entire function works like an arithmetic expression. INTHINT A single functional method call, INTHINT that is included by parentheses, is not treated INTHINT like an arithmetic expression.
Example ABAP Coding The following program excerpt computes the hyperbolic sine with the Eulerian formula in calculation type decfloat34 and with the predefined function sinh in calculation type f and displays the difference. TYPES: BEGIN OF line, x TYPE string, y TYPE string, END OF line. DATA output TYPE TABLE OF line WITH EMPTY KEY.
DO 2001 TIMES. TRY. DATA(x) = sy-index - 1001. DATA(result1) = CONV decfloat16( ( exp( x ) - exp( -1 * x ) ) / 2 ). DATA(result2) = CONV f( sinh( x ) ). DATA(diff) = abs( result1 - result2 ). IF diff <(><<)>> 0. APPEND VALUE #( x = |{ x }| y = |{ diff STYLE = SCIENTIFIC }| ) TO output. ENDIF. CATCH cx_sy_conversion_overflow cx_sy_arithmetic_overflow. ENDTRY. ENDDO. cl_demo_output=>display( output ). ABAP Code Snippet
Runtime Exceptions
Catchable Exceptions
CX_SY_ARG_OUT_OF_DOMAIN
Reason for error:
Illegal argument in powers
Runtime error:
COMPUTE_POW_DOMAIN
CX_SY_ARITHMETIC_OVERFLOW
Reason for error:
Overflow in arithmetic operation (type p)
Runtime error:
BCD_OVERFLOW
Reason for error:
Overflow in arithmetic operation (all operands type p)
Runtime error:
COMPUTE_BCD_OVERFLOW
Reason for error:
Overflow in cosh
Runtime error:
COMPUTE_COSH_OVERFLOW
Reason for error:
Overflow or underflow in exp
Runtime error:
COMPUTE_EXP_RANGE
Reason for error:
Overflow in addition (type decfloat)
Runtime error:
COMPUTE_DECFLOAT_ADD_OVERFLOW
Reason for error:
Overflow in subtraction (type decfloat)
Runtime error:
COMPUTE_DECFLOAT_SUB_OVERFLOW
Reason for error:
Overflow in multiplication (type decfloat)
Runtime error:
COMPUTE_DECFLOAT_MUL_OVERFLOW
Reason for error:
Overflow in division (type decfloat)
Runtime error:
COMPUTE_DECFLOAT_DIV_OVERFLOW
Reason for error:
Overflow in division (type decfloat)
Runtime error:
COMPUTE_DECFLOAT_DIV_OVERFLOW
Reason for error:
Overflow in division (type f)
Runtime error:
COMPUTE_FLOAT_DIV_OVERFLOW
Reason for error:
Overflow in subtraction (type f)
Runtime error:
COMPUTE_FLOAT_MINUS_OVERFLOW
Reason for error:
Overflow in addition (type f)
Runtime error:
COMPUTE_FLOAT_PLUS_OVERFLOW
Reason for error:
Overflow in multiplication (type f)
Runtime error:
COMPUTE_FLOAT_TIMES_OVERFLOW
Reason for error:
Overflow in |-2147483648|
Runtime error:
COMPUTE_INT_ABS_OVERFLOW
Reason for error:
Integer overflow in division
Runtime error:
COMPUTE_INT_DIV_OVERFLOW
Reason for error:
Integer overflow after subtraction
Runtime error:
COMPUTE_INT_MINUS_OVERFLOW
Reason for error:
Integer overflow while adding
Runtime error:
COMPUTE_INT_PLUS_OVERFLOW
Reason for error:
Integer overflow in multiplication
Runtime error:
COMPUTE_INT_TIMES_OVERFLOW
Reason for error:
Invalid call of log10
Runtime error:
COMPUTE_LOG10_ERROR
Reason for error:
Invalid call of log
Runtime error:
COMPUTE_LOG_ERROR
Reason for error:
Overflow or underflow in powers
Runtime error:
COMPUTE_POW_RANGE
Reason for error:
Overflow in sinh
Runtime error:
COMPUTE_SINH_OVERFLOW
Reason for error:
Overflow in function round or rescale
Runtime error:
COMPUTE_ROUND_RESCALE_OVERFLOW
CX_SY_CONVERSION_NO_NUMBER
Reason for error:
Operand cannot be interpreted as a number
Runtime error:
CONVT_NO_NUMBER
CX_SY_CONVERSION_OVERFLOW
Reason for error:
Overflow in arithmetic operation (type p, with specified length)