Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Assignments →  Assigning Components →  MOVE-CORRESPONDING 

MOVE-CORRESPONDING - structure

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


MOVE-CORRESPONDING [EXACT] struc1 TO struc2 
  [EXPANDING NESTED TABLES]
.

Addition

... EXPANDING NESTED TABLES

Effect

This variant of the statement MOVE-CORRESPONDING requires structures to be specified for struc1 and struc2. Meshes - as operands of statement MOVE-CORRESPONDING - are handled in the same way as normal structures and can also be specified.

The system searches for all components with the same name in struc1 and struc2 and the content of components in struc1 is assigned to the components with the same name in struc2. Other components are not affected.

Nested structures are fully expanded. The names of the components are compared down to the lowest common level. If the addition EXPANDING NESTED TABLES is not specified, the statement

struc2-comp = struc1-comp.

is executed for each component pair comp with the same name. Any associated conversion are performed and the relevant exceptions may be raised. In particular, if the components are table-like, the entire table body is mapped in accordance with the conversion rules for internal tables.

If the addition EXACT is specified for MOVE-CORRESPONDING the following lossless assignment is made for each identically named component pair comp

struc2-comp = EXACT #( struc1-comp ).

and the corresponding checks are performed. If an exception is raised, all components are assigned up to the component that raised the exception. This component, and all following components, are not assigned.

If struc1 or struc2 are empty customizing includes when the statement is executed (that is they do not contain any components), the statement is ignored. If struc1 is a structure that contains empty customizing includes as components, these are also ignored when the structure is evaluated.


Notes

  • If structures are specified for struc1 and struc2 and the structures are detectable statically, the names are compared once when the program is generated by the ABAP Compiler. If untyped field symbols or formal parameters are used, the names must be compared each time the statement is executed.
  • The compiler optimizes the MOVE-CORRESPONDING statement for structures so that sequences of components that have the same names in both structures are grouped and copied together. We therefore recommend that the relevant structures are constructed in the same way whenever possible.
  • MOVE-CORRESPONDING for structures ignores names that were only defined with the AS name addition of the INCLUDE statement or when structures were integrated into ABAP Dictionary. However, components that were renamed using the RENAMING WITH SUFFIX addition of the INCLUDE statement or similarly in ABAP Dictionary are not ignored.

Addition

... EXPANDING NESTED TABLES

Effect

This addition specifies that, for two components with the same name and which are both internal tables, no assignment is made and that the variant MOVE-CORRESPONDING [EXACT] for internal tables with the addition EXPANDING NESTED TABLES and without the addition KEEPING TARGET LINES is executed instead.

Tabular components are resolved at every hierarchy level and identically named components are mapped row by row. The target tables are deleted before a mapping.


Note

If one of two identically named components is an internal table and the other not, MOVE-CORRESPONDING is never possible, regardless of whether EXPANDING NESTED TABLES is used.


Example

In the following example, the structure struc1 contains the components:

  • struc1-comp1
  • struc1-struci-comp1
  • struc1-struci-comp2-col1
  • struc1-struci-comp2-col2
  • struc1-itab

The structure struc2 contains the components:

  • struc2-struci-comp1
  • struc2-struci-comp2
  • struc2-struci-comp3
  • struc2-itab

Over the length of the shorter path, the components struci-comp1, struci-comp2, and itab have the same name. These are assigned from struc1 to struc2 in both MOVE-CORRESPONDING statements. In struc1, struci-comp2 is self-structured; in struc2, struci-comp2 is elementary. When struc1-struci-comp2 is assigned to struc2-struci-comp2, the source field is documented as an elementary field of type c in accordance with the conversion rules for structures.

The components itab are table-like and have compatible row types. The statement MOVE-CORRESPONDING without the addition EXPANDING NESTED TABLE maps the table body and the content of itab in struc2 then matches the content of itab in struc1. If the addition EXPANDING NESTED TABLE is used, only the component col2 is mapped and col3 remains initial.

The components struc1-comp1 and struc2-struci-comp3 do not have any equivalents with the same name and are not taken into account in the assignment.

DATA: BEGIN OF line1, 
        col1 TYPE i, 
        col2 TYPE i, 
      END OF line1, 
      BEGIN OF line2, 
        col2 TYPE i, 
        col3 TYPE i, 
      END OF line2. 

DATA: BEGIN OF struc1, 
        comp1 TYPE c LENGTH 1 VALUE 'U', 
        BEGIN OF struci, 
          comp1 TYPE c LENGTH 1 VALUE 'V', 
          BEGIN OF comp2, 
            col1 TYPE c LENGTH 1 VALUE 'X', 
            col2 TYPE c LENGTH 1 VALUE 'Y', 
          END OF comp2, 
        END OF struci, 
        itab LIKE TABLE OF line1, 
     END OF struc1. 

DATA: BEGIN OF struc2, 
        BEGIN OF struci, 
          comp1 TYPE string, 
          comp2 TYPE string, 
          comp3 TYPE string, 
        END OF struci, 
        itab LIKE TABLE OF line2, 
     END OF struc2. 

line1-col1 = 11. line1-col2 = 12. 
APPEND line1 TO struc1-itab. 
line1-col1 = 21. line1-col2 = 22. 
APPEND line1 TO struc1-itab. 

MOVE-CORRESPONDING struc1 TO struc2. 
MOVE-CORRESPONDING struc1 TO struc2 EXPANDING NESTED TABLES.