Entering content frameNumerical Operations Locate the document in its SAP Library structure

To assign the result of a mathematical calculation to a variable, use the COMPUTE statement or the assignment operator (=).

COMPUTE <n> = <expression>.

COMPUTE is optional, so you can also write the statement as follows:

<n> = <expression>.

The result of the mathematical operation specified in <expression> is assigned to the field <n>.

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 with the highest hierarchical level. In this context, the result field <n> and floating point functions (type F) also count as operands. The hierarchical order is F before P before I. Before performing the calculation, ABAP converts all of the operands into the highest-occurring data type. After the operation, the result is assigned to the result field using the same logic as the MOVE statement, that is, the system converts the result into the data type of the result field if necessary.

In ABAP, the sequence of type conversions during numerical operations is different from other programming languages. Note, in particular, that the data type of the result field influences the accuracy of the entire calculation.

In mathematical expressions, you can combine operations in any permutation and use any number of parentheses.

ABAP interprets mathematical expressions in the following order:

  1. Expressions in parentheses
  2. Functions
  3. ** (powers)
  4. *, / , MOD, DIV (multiplication, division)
  5. +, - (addition, subtraction)

The mathematical expressions that you can use in <expression> are described in the following sections:

Performing Arithmetic Operations

Mathematical Functions

Business Calculations

Date and Time Calculations

 

 

Leaving content frame