Show TOC Start of Content Area

Numeric 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 fixed 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.      Features

       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

 

End of Content Area