ABAP Keyword Documentation → ABAP − Reference → Obsolete Language Elements → Obsolete Processing of Internal Data → Obsolete Calculation Statements
SUBTRACT, MULTIPLY, DIVIDE
Other versions:
7.31 | 7.40 | 7.54
Obsolete Syntax
SUBTRACT dobj1 FROM dobj2.
MULTIPLY dobj2 BY dobj1.
DIVIDE dobj2 BY dobj1.
Effect
These statements have the same effect as the statements
dobj2 = dobj2 - dobj1.
dobj2 = dobj2 * dobj1.
dobj2 = dobj2 / dobj1.
The content of dobj2
-
has the content of
dobj1
subtracted from it, -
or is multiplied by the content of
dobj1
, -
or is divided by the content of
dobj1
,
and the result is assigned to dobj2
. The data objects dobj1
and dobj2
have to be numeric. Only data objects can be specified and no calls or other expressions. The
calculation type is determined like an arithmetic expression.
Division by the value 0 is undefined and raises a handleable 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.
Note
The statements shown here have been replaced by
calculation assignments with the operators
-=, *=
,
and /=
in which the operands can also be specified as expressions.
Example
The variable n
has the value 1.50 after the calculation statements. See also the example for the corresponding
calculation assignments.
DATA n TYPE p DECIMALS 2.
ADD 1 TO n.
ADD 1 TO n.
ADD 1 TO n.
ADD 1 TO n.
SUBTRACT 2 FROM n.
MULTIPLY n BY 3.
DIVIDE n BY 4.
Exceptions
Handleable Exceptions
CX_SY_ARITHMETIC_OVERFLOW
-
Cause: Overflow in arithmetic operation (type
p
)
Runtime error:BCD_OVERFLOW
-
Cause: Integer overflow in addition
Runtime error:COMPUTE_INT_PLUS_OVERFLOW
CX_SY_CONVERSION_OVERFLOW
-
Cause: Overflow in arithmetic operation (type
p
, with specified length)
Runtime error:BCD_FIELD_OVERFLOW
CX_SY_ZERODIVIDE
-
Cause: Division by 0 (type
p
)
Runtime error:BCD_ZERODIVIDE
-
Cause: Division by 0 (type
f
)
Runtime error:COMPUTE_FLOAT_ZERODIVIDE
-
Cause: Division by 0 (type
i
)
Runtime error:COMPUTE_INT_ZERODIVIDE
Non-Handleable Exceptions
-
Cause:
p
field does not contain the correct BCD format
Runtime error:BCD_BADDATA