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

Assignments

Background

For explicit assignments in which the value of a source is assigned to a target, ABAP contains the general assignment operator = and the special casting operator ?=. Statements with these operators

lhs =|?= rhs.

enable assignments of

to variables that can also be declared inline and to writable expressions.

Alongside the assignment operators, two obsolete statements exist for historical reasons that can also perform assignments:

MOVE source TO|?TO destination.
assigns a source source to a target destination. It covers some of the operators performed by the assignment operators = and ?=.
COMPUTE lhs =|?= rhs.
has the same semantics as lhs =|?= rhs. The keyword COMPUTE can be written in front of each assignment with the assignment operators = and ?= where the left side is not an inline declaration, but is ignored.

Rule

Assignments with the assignment operators = and ?= only

Use the assignment operators instead of the statement MOVE. Do not use the keyword COMPUTE in front of assignments.

Details

Assignments with the assignment operators = and ?= implement the most global concept. The right side is a general expression position and the left side is a declaration position (except in down casts).

The statements MOVE and COMPUTE have the following drawbacks:

The statements MOVE and COMPUTE were created at a time when assignments were only made between individual data objects and calculations were exclusively arithmetic. Neither of these statements is appropriate in a modern, expression-oriented ABAP program that exploits all options on the left and right sides of an assignments.

Note

The optional addition EXACT of the statements MOVE and COMPUTE, which produces lossless assignments and lossless calculations, has been replaced in full by the lossless operator EXACT.

Bad example

The following source code shows a simple assignment using MOVE and the assignment of an arithmetic expression after COMPUTE.

DATA text1 TYPE string.
DATA text2 TYPE string.
...
MOVE text1 TO text2.

DATA result TYPE decfloat34.
DATA number1 TYPE i.
DATA number2 TYPE i.
...
COMPUTE result = number1 * number2.

Good example

The following source code shows the same example as above but without specifying the keywords MOVE and COMPUTE. This makes inline declarations possible on the left side.

DATA text1 TYPE string.
...
DATA(text2) = text1.

DATA number1 TYPE i.
DATA number2 TYPE i.
...
DATA(result) = CONV decfloat34( number1 * number2 ).