ABAPCOMPUTE_ARITH - COMPUTE ARITH
ABAP Short Reference RFUMSV00 - Advance Return for Tax on Sales/PurchasesThis documentation is copyright by SAP AG.
arith_exp - Arithmetic Expressions
Syntax
... [+|-] operand1
[{+|-|*|/|DIV|MOD|**} [+|-] operand2
[{+|-|*|/|DIV|MOD|**} [+|-] operand3
... ]] ... .
Effect
An arithmetic expression expresses a calculation. The result of an arithmetic expression is a numeric value of thecalculation type assigned to the arithmetic expression. In an arithmetic expression arith_exp, you can use thearithmetic operators+, -, *, /, DIV, MOD, or ** to associate an operand operand1 with one or more operands operand2, operand3 ...Brackets arealso possible. Arithmetic expressions are used in the COMPUTE statement or atread positions of certain expressions (from Release 7.1).
The operand positions operand are general expression positions, that is you can specifypredefined functions,functional methods, or compound arithmetic expressions. The arithmetic operators +, -, *, /, DIV, MOD, and ** associate two adjacentoperands. When the expression is evaluated, a numeric value is calculated and associated with the next adjacent operand. The priority of this association depends on theoperators 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-likeexpresions are specified as operands, they are listed from left to right before the remainder of the expression is evaluated and the return codes to be used in the appropriate operand positions are buffered. Here,character-like processing functions andstring expressions are only possible as arguments ofdescription functions.
Notes
- You must pay attention to whether the value of a data object that is also used as an operand is changedin 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 and string expressions cannot be mixed.Descriptionfunctions that are used as operands for arithmetic expressions can, however, contain string expressions as arguments.
Example
The following program excerpt computes the hyperbolic sine with the Eulerian formula in calculation type decfloat16 and with thepredefined function sinh in calculation type f and displays the difference.
DATA: x TYPE i,
result1 TYPE decfloat16,
result2 TYPE f,
diff TYPE decfloat16.
DO 2001 TIMES.
TRY.
x = sy-index - 1001.
result1 = ( ( exp( x ) - exp( -1 * x ) ) / 2 ).
result2 = sinh( x ).
diff = abs( result1 - result2 ).
IF diff <> 0.
WRITE: / x, diff STYLE cl_abap_math=>scientific.
ENDIF.
CATCH cx_sy_conversion_overflow cx_sy_arithmetic_overflow.
ENDTRY.
ENDDO.
Exceptions
Catchable Exceptions
- 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)
- 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
- Cause: Operand cannot be interpreted as a number
Runtime Error: CONVT_NO_NUMBER (catchable)
- 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)
- 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)
- Cause: Illegal function for calculation type decfloat34
Runtime Error: COMPUTE_UNSUPPORTED_DECF_FUNC
- 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
CPI1466 during Backup BAL_S_LOG - Application Log: Log header data
This documentation is copyright by SAP AG.
Length: 15634 Date: 20120522 Time: 035819 triton ( 286 ms )






