COMPUTE - arith_exp
Syntax
[COMPUTE] result = [+|-] operand1
[{+|-|*|/|DIV|MOD|**} [+|-] operand2
[{+|-|*|/|DIV|MOD|**} [+|-] operand3
... ]].
Effect
In an arithmetic expression, you can use arithmetic operators
to link an operand operand1 with one or more operands operand2, operand3, and so on;
parentheses are possible. Arithmetic expressions can only be used in the COMPUTE statement. Each arithmetic expression has a
calculation type.
The operands operand can be numeric data objects,
predefined functions,
functional methods, or compound arithmetic expressions. The
arithmetic operators +, -,
*, /,
DIV, MOD, and **
link two adjacent operands. When the expression is evaluated, a numeric value is calculated and linked with the next adjacent operand. The priority of this link depends on the
operators used.
Each operand can be preceded by the prefixes + or
-, in any order and separated by one more blank characters. The effect of using a prefix is the same as specifying the expression +1
* or -1 *, which means that a prefix has the same priority as a multiplication.
If functional methods are specified
as operands, they are executed from left to right before the remainder of the expression is evaluated and the return values are buffered for use at the relevant operand positions.
Notes
-
You must pay attention to whether 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 precedes the functional method, its value will always be changed by the method before it is evaluated.
-
If a single data object is specified as an operand without a prefix, this does not represent a complete
arithmetic expression. In this case, the COMPUTE statement
has the same effect as the MOVE statement.
Example
The first assignment is equivalent to a COMPUTE statement
and sets result to the value "731036" - that is, the number
of days since 01.01.0001. In contrast, the second assignment is equivalent to a
MOVE statement and sets result to the value"20020704".
DATA: result TYPE string,
date TYPE d VALUE '20020704'.
result = + date.
result = date.
Example
The following program excerpt contains two arithmetic expressions. The second expression calculates the difference that results from calculating the hyperbolic sine with the Eulerian formula or with the
predefined function sinh
DATA: x TYPE f,
result TYPE f.
DO 2001 TIMES.
TRY.
x = sy-index - 1001.
result = ( ( exp( x ) - exp( -1 * x ) ) / 2 )
- sinh( x ).
IF result <> 0.
WRITE: / x, result.
ENDIF.
CATCH cx_sy_arithmetic_error. "outside value range
ENDTRY.
ENDDO.
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 ATAN
Runtime error: COMPUTE_ATAN_DOMAIN (catchable)
-
Cause: Invalid call of COSH
Runtime error: COMPUTE_COSH_DOMAIN (catchable)
-
Cause: Invalid call of COS
Runtime Error: COMPUTE_COS_DOMAIN (catchable)
-
Cause: Invalid call of EXP
Runtime error: COMPUTE_EXP_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: Invalid argument when using powers
Runtime Error: COMPUTE_POW_DOMAIN (catchable)
-
Cause: Invalid call of SINH
Runtime Error: COMPUTE_SINH_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 TANH
Runtime Error: COMPUTE_TANH_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 in division (type F)
Runtime Error: COMPUTE_FLOAT_DIV_OVERFLOW (catchable)
-
Cause: Overflow in subtraction (type F)
Runtime Error: COMPUTE_FLOAT_MINUS_OVERFLOW (catchable)
-
Cause: Overflow in addition (type F)
Runtime Error: COMPUTE_FLOAT_PLUS_OVERFLOW (catchable)
-
Cause: Overflow in multiplication (type F)
Runtime Error: COMPUTE_FLOAT_TIMES_OVERFLOW (catchable)
-
Cause: Overflow in |-2147483648|
Runtime Error: COMPUTE_INT_ABS_OVERFLOW (catchable)
-
Cause: Integer overflow in division
Runtime Error: COMPUTE_INT_DIV_OVERFLOW (catchable)
-
Cause: Integer overflow in subtraction
Runtime Error: COMPUTE_INT_MINUS_OVERFLOW (catchable)
-
Cause: Integer overflow in addition
Runtime Error: COMPUTE_INT_PLUS_OVERFLOW (catchable)
-
Cause: Integer overflow in 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 when using powers
Runtime Error: COMPUTE_POW_RANGE (catchable)
-
Cause: Overflow in SINH
Runtime Error: COMPUTE_SINH_OVERFLOW (catchable)
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 in arithmetic operation (type P, with specified length)
Runtime Error: BCD_FIELD_OVERFLOW (catchable)
-
Cause: Operand too large or (interim) result too large
Runtime Error: CONVT_OVERFLOW (catchable)
CX_SY_PRECISION_LOSS
-
Cause: Result of COS inaccurate
Runtime Error: COMPUTE_COS_LOSS (catchable)
-
Cause: Result of SIN inaccurate
Runtime Error: COMPUTE_SIN_LOSS (catchable)
-
Cause: Result of TAN inaccurate
Runtime Error: COMPUTE_TAN_LOSS (catchable)
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)
Non-Catchable Exceptions
-
Cause: P field does not contain a correct BCD format
Runtime Error: BCD_BADDATA
-
Cause: P field does not contain a correct plus/minus
sign Runtime Error: BCD_NO_SIGN