To assign the value of a data object <f1> to a variable <f2>, use the following statement:
MOVE <f1> TO <f2>.
or the equivalent statement
<f2> = <f1>.
The contents of <f1> remain unchanged. <f1> does not have to be a variable - it can also be a literal, a text symbol, or a constant. You must always specify decimal points with a period (.), regardless of the user’s personal settings.
Multiple value assignments in the form
<f4> = <f3> = <f2> = <f1>.
are also possible. ABAP processes them from right to left as follows:
MOVE <f1> TO <f2>.
MOVE <f2> TO <f3>.
MOVE <f3> TO <f4>.
In the MOVE statement (or when you assign one value to another with the equal sign), it is not possible to specify the field names dynamically as the contents of other fields. If you need to do this, you must use
field symbols .There are three possible outcomes of assigning <f1> to <f2>:
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, the contents of a source field with an elementary data type can be assigned to a target field with any other data type. The single exception to this rule is that it is not possible to assign values between type D fields and type T fields. ABAP even supports assignments between a structure and an elementary field, or between two structures.
DATA: T(10) TYPE C,
NUMBER TYPE P DECIMALS 2,
COUNT TYPE I.
T = 1111.
MOVE '5.75' TO NUMBER.
COUNT = NUMBER.
Following these assignments, the fields T, NUMBER, and COUNT have the values ‘1111 ’, 5.75, and 6 respectively. When you assign the number literal 1111 to T, it is converted into a character field with length 10. When you assign NUMBER to COUNT, the decimal number is rounded to an integer (as long as the program attribute Fixed pt. arithmetic has been set).
Assigning Values Between Components of Structures
To move values between the components of structures, use the statement
MOVE-CORRESPONDING <struct1> TO <struct2>.
This statement moves the contents of the components of structure <struct1> to the components of <struct2> that have identical names.
When it is executed, it is broken down into a set of MOVE statements, one for each pair of fields with identical names, as follows:
MOVE STRUCT1-<ci> TO STRUCT2-<c i>.
Any necessary type conversions occur at this level. This process is different to that used when you assign a whole structure using the MOVE statement, where the
conversion rules for structures apply.
DATA: BEGIN OF ADDRESS,
FIRSTNAME(20) VALUE 'Fred',
SURNAME(20) VALUE 'Flintstone',
INITIALS(4) VALUE 'FF',
STREET(20) VALUE 'Cave Avenue,
NUMBER TYPE I VALUE '11'.
POSTCODE TYPE N VALUE '98765'.
CITY(20) VALUE 'Bedrock',
END OF ADDRESS.
DATA: BEGIN OF NAME,
SURNAME(20),
FIRSTNAME(20),
INITIALS(4),
TITLE(10) VALUE 'Mister',
END OF NAME.
MOVE-CORRESPONDING ADDRESS TO NAME.
In this example, the values of NAME-SURNAME, NAME-FIRSTNAME and NAME-INITIALS are set to 'Flintstone’, ‘Fred’, and 'FF'. NAME-TITLE retains the value 'Mister'.