Numerical Operations

To process numeric data objects and assign the resulting value to a data object, you can use either the COMPUTE statement or the assignment operator (=).

The syntax for the COMPUTE statement is as follows:


COMPUTE <n> = <expression>.

The use of the keyword COMPUTE is optional. In other words, you could also write the statement as follows:


<n> = <expression>.

The effect of both statements is identical.

The result of the mathematical operation specified in <expression> is assigned to the field <n>. The assignment operator (=) works as described in the Basic Assignments section.

ABAP executes a numerical operation with a numerical precision that corresponds to one of the numerical data types I, P, or F. The numerical precision is defined by the operand of the numerical operation that has the highest hierarchy level. The system treats the target field <n> and floating-point functions also as operands. ABAP converts all numbers of a numerical operation before its execution into the hierarchically highest data type that occurs in the operation. Then the system executes the operation with the converted numbers (see Type Conversions). If necessary, the system converts the result back to the data type of the target field after the execution.

In ABAP, the sequence of type conversions during numerical operations is different from other programming languages. Especially, you can influence the numerical precision of the whole operation with the data type of the target field.

In mathematical expressions, you can combine operations in any permutation and specify them in parentheses.

The order of evaluation is:

  1. expressions in parentheses
  2. functions
  3. ** (exponentiation)
  4. *, /, MOD, DIV (multiplications, divisions)
  5. +, - (additions, subtractions)

The mathematical operations specified in <expression> are described in the following topics:

Performing Arithmetic Operations

Using Mathematical Functions

The processing of the following data types is of special interest:

Processing Packed Numbers

Processing Date and Time Fields