SAP SUBTRACT MULTIPLY DIVIDE ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID SUBTRACT
ID MULTIPLY
ID DIVIDE
• SUBTRACT ABAP Statement
• FROM SUBTRACT (obsolete)
• MULTIPLY ABAP Statement
• BY MULTIPLY (obsolete)
• DIVIDE ABAP Statement
• BY DIVIDE (obsolete)

SUBTRACT, MULTIPLY, DIVIDE

ABAP_SYNTAX_OBS
SUBTRACT dobj1 FROM dobj2.
MULTIPLY dobj2 BY dobj1.
DIVIDE dobj2 BY dobj1.

What does it do?
These statements have the same effect as the statements
dobj2 -= dobj1.
dobj2 *= dobj1.
dobj2 /= dobj1.
that are the same as
dobj2 = dobj2 - dobj1.
dobj2 = dobj2 * dobj1.
dobj2 = dobj2 / dobj1.
The content of dobj2
has the content of dobj1 subtracted,
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 must be numeric. Only data objects can be specified and no calls or other expressions. The calculation type is determined as for an arithmetic expression.
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.



Latest notes:

The statements shown here have been fully replaced by calculation assignments with the operators -=, *=, and /= in which the operands can also be specified as expressions.
NON_V5_HINTS
ABAP_HINT_END



Example ABAP Coding

The variables n1 and n2 both have the value 1.50 after the calculation statements. The calculations are done with the obsolete calculation statements and with the corresponding calculation assignments.
ABEXA 00695
ABAP_EXAMPLE_END



Runtime Exceptions



Catchable Exceptions

CX_SY_ARITHMETIC_OVERFLOW
Reason for error:
Overflow in arithmetic operation (type p)
Runtime error:
BCD_OVERFLOW
Reason for error:
Integer overflow in addition
Runtime error:
COMPUTE_INT_PLUS_OVERFLOW
CX_SY_CONVERSION_OVERFLOW
Reason for error:
Overflow in arithmetic operation (type p, with specified length)
Runtime error:
BCD_FIELD_OVERFLOW
CX_SY_ZERODIVIDE
Reason for error:
Division by 0 (type p)
Runtime error:
BCD_ZERODIVIDE
Reason for error:
Division by 0 (type f)
Runtime error:
COMPUTE_FLOAT_ZERODIVIDE
Reason for error:
Division by 0 (type i)
Runtime error:
COMPUTE_INT_ZERODIVIDE

Non-catchable Exceptions

Runtime error:
ADD_FIELDS_ILLEGAL_ACCESS
Reason for error:
p field does not contain the correct BCD format
Runtime error:
BCD_BADDATA
ABAP_NONCAT_END

Return to menu