Skip to content

ABAP Keyword Documentation →  ABAP Programming Guidelines →  Structure and Style →  Alternative Spellings 

Assignments and Calculations

Other versions: 7.31 | 7.40 | 7.54

Background

As well as the operator format, there are ABAP key words for assignments and some arithmetic calculations.

  • Assignments are performed using assignment operators =, ?= or alternatively by using the keyword MOVE with TO or ?TO.
  • The basic arithmetic operations, like all calculations, can be performed in an arithmetic expression or, alternatively, with one of the keywords ADD,SUBTRACT, MULTIPLY, or DIVIDE.

Rule

Using Operator Format

For assignments and calculations, use the operator format with the equals sign (=) instead of the ABAP keyword format.

Details

Assignments or calculations with the statements MOVE, ADD, SUBTRACT, MULTIPLY, or DIVIDE are often more difficult to read than the corresponding operator format. Calculations other than the basic arithmetic operations cannot be expressed by ABAP keywords in any case.

Exception

The command format allows the use of chained statements, which can be useful in these special cases:

ADD increment TO: sum_individual,
                  sum_total.

If arithmetic operations are in the form a = a + 1, where the target variable and one of the operands are identical, using the statements ADD, SUBTRACT and so on has the advantage of being easier on the eye, especially when the name of the target variable is relatively long:

SUBTRACT 1 FROM reference->structured_attribute-component.

It is immediately clear to the observer that the value of the specified variables is reduced by one. This may not be the case for the operator format, if it is not straightaway obvious that the target variable and one of the operands are identical. In such cases you can and should ignore the above rule. The primary concern is the readability of the source code.

Bad Example

The following source code shows the Down Cast of an interface reference variable to a class reference variable with the keyword MOVE.

DATA: cref TYPE REF TO cl_class,
      iref TYPE REF TO if_interface.
...
MOVE iref ?TO cref.

Good Example

The following source code shows the same example as above, but in the recommended operator format.

DATA: cref TYPE REF TO cl_class,
      iref TYPE REF TO if_interface.
...
cref ?= iref.