Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Numeric Calculations 

+=, -=, *=, /= - Calculation Assignments

Other versions: 7.31 | 7.40 | 7.54

Syntax


lhs += 
  | -=
  | *=
  | /= rhs.

Effect

Calculation assignment with the

  • addition assignment operator +=
  • subtraction assignment operator -=
  • multiplication assignment operator *=
  • division assignment operator /=

These assignments have the same function as the following assignments of arithmetic expressions:

lhs = lhs + ( rhs ).

lhs = lhs - ( rhs ).

lhs = lhs * ( rhs ).
lhs = lhs / ( rhs ).

The content of lhs

  • has the result of the parenthesized expression rhs added to it,
  • or has the result of the parenthesized expression rhs subtracted from it,
  • or is multiplied by the result of the parenthesized expression rhs,
  • or is divided by the result of the parenthesized expression rhs,

and the result is assigned to lhs. The calculation type is determined accordingly.

The following applies to the operands lhs and rhs:

  • lhs is a result position and the following can be specified (if numeric):
Type inference with the character # is not currently possible in constructor expressions. Character-like expressions and bit expressions cannot be specified.

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.


Notes

  • Alongside data objects, calculation assignments also allow expressions in the operand positions. This makes them more powerful than the statements ADD, SUBTRACT, MULTIPLY, DIVIDE, and also makes these statements obsolete.
  • No inline declarations are possible for lhs.
  • Calculation assignments can currently only be specified as standalone statements. They cannot be used in expressions, for example after NEXT in reduction operator REDUCE.
  • See also the concatenation assignment operator (&&=).

Example

The variable n has the value 1.50 after the calculation assignments.

DATA n TYPE p DECIMALS 2. 

n += 1. 
n += 1. 
n += 1. 
n += 1. 
n -= 2. 
n *= 3. 
n /= 4.