Start of Content Area

Assigning Values with MOVE  Locate the document in its SAP Library structure

To assign the value of a data object source to a variable destination, use the following statement:

MOVE source TO destination.

or the equivalent statement

destination = source.

The content of source remains unchanged, source does not therefore 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 assignments

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 .

The source and target fields can be of different data types. The result of the value assignment depends on whether these data types are compatible and whether a type conversion can be performed. If there is no conversion rule between the data types in question, no assignment can be made.

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

The rules for value assignments between data objects also apply to structures. With the command

DATA: struct1 TYPE structure,
      struct2 TYPE structure.
struct1 = struct2.

two structures of the same type can be assigned to one another without difficulty. Here, the entire source structure is seen as a unit and copied to the source structure. It is then possible to access the components individually again. If the structures in question are not compatible, see the conversion rules for structures.

In practice, however, you will often only need to assign certain components of a structure to be certain components of another structure. ABAP has a special statement for this purpose:

MOVE-CORRESPONDING sourcestruct TO destinationstruct.

This statement assigns the contents of the components of structure sourcestruct to the components of the destinationstruct structure that have identical names.

When it is executed, it is broken down into a set of MOVEstatements, one for each pair of fields with identical names, as follows:

MOVE sourcestruct-comp1 TO destinationstruct-comp1.

MOVE sourcestruct-comp2 TO destinationstruct-comp2.

...

Any necessary type conversions are performed individually.

Example

DATA: BEGIN OF address,
        firstname(20) TYPE c VALUE 'Fred',
        surname(20) TYPE c VALUE 'Flintstone',
        initials(4) TYPE c VALUE 'FF',
        street(20) TYPE c VALUE 'Cave Avenue',
        number TYPE i VALUE '11',
        postcode(5) TYPE n VALUE '98765',
        city(20) TYPE c VALUE  'Bedrock',
      END OF address.

DATA: BEGIN OF name,
        surname(20) TYPE c,
        firstname(20) TYPE c,
        initials(4) TYPE c,
        title(10) TYPE c 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 always has the value ‘Mister’.

This graphic is explained in the accompanying text

 

 

End of Content Area