ABAP_ARITHEXP > - Arithmetic Operators The table shows the possible arithmetic operators for arithmetic expressions>, their priority, and the order in which the calculation is performed. Within a parenthesis level>, calculations with operators of higher priority are performed before calculations with operators of lower priority. For adjacent operators of the same priority, the calculation is performed in the order specified. In the third column of the table below, 3 indicates the highest priority and 1 the lowest. The calculation is performed according to the calculation rule> for the current calculation type>. With the exception of **> , the operators have no effect on the calculation type. If the operator **> does not occur in an arithmetic expression, the calculation type is determined only by the data types involved. If **> is used, the calculation type is either decfloat34> or f>. It is decfloat34> if one of the operands involved is a decimal floating point number> and f> in all other cases. Operator>Calculation>Priority>Order> ABAP_KEY +>Addition of the operands1From left to right ABAP_KEY ->Subtraction of the right operand from the left1 From left to right ABAP_KEY *>Multiplication of the operands2From left to right ABAP_KEY />Division of the left operand by the right2From left to right ABAP_KEY DIV>Integer part of the division of the left operand by the right, with positive remainder2From left to right ABAP_KEY MOD>Positive remainder of the division of the left operand by the right; a remainder other than zero is always between zero and the size of the right operand2From left to right ABAP_KEY **>Left operand raised to the power of the right3 From right to left Division by the value 0 is undefined and raises a catchable exception. The only situation where division by 0 does not raise an exception is if the dividend is also 0. Here, the result is set to 0.
ABAP_PGL Prevent division by zero> ABAP_PGL_END
Latest notes:
Setting the result to 0 in a division by the value 0, where the dividend is 0 can be seen as an internal exception handling that sets the result to a predefined value in that case.
In ABAP, the result of a division for the calculation types> i>, int8>, p> , and decfloat34> is rounded commercially, whereas in most other programming languages any surplus decimal places are cut off.
The result of DIV> multiplied by operand2> plus the result of MOD> always produces operand1>. Therefore, the rule that the result of MOD> is always positive also affects the result of DIV>. The result of an integer division of two positive numbers with a remainder that is not equal to zero differs from the result of an integer division of two negative numbers with the same amounts. Likewise, for operands with different plus/minus signs, it is important which operand is positive and which is negative.
If, when raising to a power, the left operand is 0, the right operand must be greater than or equal to 0. If the left operand is negative, the right operand must be an integer. Otherwise, both cases raise a catchable exception.
To prevent the operator **> from producing the calculation type> f>, the built-in function ipow>> can be used for integer exponents for which the calculation type is determined by the argument.
The ABAP operators DIV> and MOD> behave differently with respect to the signs than the SQL operators DIV>> and MOD>>. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 This example demonstrates the functions of the three division operators, DIV>, MOD>, and />. The results are 4.7273>, 4.0000>, and 0.8000>. ABEXA 00826 ABAP_EXAMPLE_END
ABAP_EXAMPLE_VX5 The following table shows the results of integer divisions and their remainders. See also the example for the SQL operators DIV>> and MOD>>. operand1>operand2>DIV>MOD> 7321 -73-32 7-3-21 -7-332 ABAP_EXAMPLE_END