Entering content frameAssigning Values with MOVE Locate the document in its SAP Library structure

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>:

  1. The data objects <f1> and <f2> are fully compatible, that is, their data types, field length, and number of decimal places are identical. The contents of source field <f1> are transferred byte by byte into the target field <f2> without any further manipulation. The MOVE statement is most efficient when this is the case.
  2. The data objects <f1> and <f2> are incompatible. This is the case, for example, if the two fields have the same type, but different lengths. The contents of the source field <f1> are converted so that they are compatible with the data type of <f2>, and are then transferred. This procedure only works if a conversion rule exists between the data types of <f1> and <f2>. Type conversions make the MOVE statement less efficient. How much less efficient depends on the individual conversion.
  3. The data objects <f1> and <f2> are incompatible, and no conversion is possible. The assignment is not possible. If this can be recognized statically, a syntax error occurs. If it is not recognized before the program is run, a runtime error occurs.

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.

Example

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.

Example

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'.

This graphic is explained in the accompanying text

 

 

 

Leaving content frame