Basic Assignment Operations

To assign either a value (literal) or the contents of a source field to a target field, you can use the MOVE statement or the assignment operator (=).

The syntax for the MOVE statement is as follows:

Syntax

MOVE <f1> TO <f2>.

The MOVE statement transports the contents of a source field <f1>, which can be any data object, to a target field <f2>, which must be a variable. <f2> cannot be a literal or a constant. The contents of <f1> remain unchanged.

The syntax for the assignment operator (=) is as follows:

Syntax

<f2> = <f1>.

The MOVE statement and the assignment operator have the same function.

Multiple assignments such as

<f4> = <f3> = <f2> = <f1>.

are possible. ABAP processes them from right to left as follows:

MOVE <f1> TO <f2>.
MOVE <f2> TO <f3>.
MOVE <f3> TO <f4>.

In the above statements, decimal points must always be specified with a period (.), regardless of the user’s master record.

The source and target fields can be of different data types. In contrast to other programming languages, where the assignment between different data types is often restricted to a small number of possible combinations, ABAP provides a wide range of automatic type conversions.

For example, you can assign the contents of a source field with an elementary data type to a target field with any other elementary data type (except data type D which cannot be assigned to data type T and vice versa). ABAP also supports assignment between structured data and elementary data objects or between data objects which have different structures.

For each assignment statement (with MOVE or the assignment operator), the system checks the data types of the source and target fields. If a type conversion is defined for that combination, it converts the contents of the source field to the data type of the target field and assigns it to the target field. For an overview of the possible type conversions and how they are defined in ABAP, see Type Conversions.

DATA: T(10),
NUMBER TYPE P DECIMALS 1,
COUNT TYPE P DECIMALS 1.

T = 1111.
MOVE '5.3' TO NUMBER.
COUNT = NUMBER.

The result of this assignment is that the fields T, NUMBER, and COUNT contain the values '1111 ', 5.3, and 5.3. Note that, when assigning the number literal 1111, the system converts it to a character string with a length of 10.

You cannot use the MOVE statement (or the assignment operator) for this purpose. Instead, you must use field symbols (see the description in the Working With Field Symbols section).