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

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.

Exceptions

Catchable Exceptions

CX_SY_ARG_OUT_OF_DOMAIN

CX_SY_ARITHMETIC_OVERFLOW

CX_SY_CONVERSION_NO_NUMBER

CX_SY_CONVERSION_OVERFLOW

CX_SY_PRECISION_LOSS

CX_SY_ZERODIVIDE

Non-Catchable Exceptions