Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Assignments →  Assigning Components →  Assigning Components: Examples 

MOVE-CORRESPONDING for Internal Tables

This example demonstrates the statement MOVE-CORRESPONDING for internal tables.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA buffer LIKE itab2.
    out = cl_demo_output=>new( ).
    fill_tables( ).
    out->begin_section( `itab1` ).
    display_table1( ).
    out->next_section( `itab2` ).
    display_table2( ).
    buffer = itab2.

    out->begin_section(
      `MOVE-CORRESPONDING` ).

    MOVE-CORRESPONDING itab1 TO itab2.

    display_table2( ).
    itab2 = buffer.
    out->next_section(
      `MOVE-CORRESPONDING KEEPING TARGET LINES` ).

    MOVE-CORRESPONDING itab1 TO itab2 KEEPING TARGET LINES.

    display_table2( ).
    itab2 = buffer.
    out->next_section(
      `MOVE-CORRESPONDING EXPANDING NESTED TABLES` ).

    MOVE-CORRESPONDING itab1 TO itab2 EXPANDING NESTED TABLES.

    display_table2( ).
    itab2 = buffer.
    out->next_section(
      `MOVE-CORRESPONDING EXPANDING NESTED TABLES ` &&
      `KEEPING TARGET LINES` ).

    MOVE-CORRESPONDING itab1 TO itab2 EXPANDING NESTED TABLES
                                     KEEPING TARGET LINES.

    display_table2( ).
    out->display( ).

Description

MOVE-CORRESPONDING and the available additions are used to declare two internal tables, itab1 and itab2, and assign them to each other.

  • itab1 contains two elementary components, col1 and col2, and a tabular component col3 with the components col1 and col2.
  • itab2 contains two elementary components, col2 and col4, and a tabular component col3 with the components col2 and col3.

The internal tables are filled with values. For the output, the structured components are resolved to elementary components of an output table, output.

The statement MOVE-CORRESPONDING finds the identically named components col2 and col3 in itab1 and itab2 and the assignments work as followst:

  • MOVE-CORRESPONDING
The original content of itab2 is deleted. After the assignment, the columns col2 and col3 have the same content as in itab1, whereas col4 remains initial.
  • MOVE-CORRESPONDING KEEPING TARGET LINES
The original content of itab2 is preserved. Three new rows are added in which the columns col2 and col3 have the same content as in itab1, whereas col4 remains initial.
  • MOVE-CORRESPONDING EXPANDING NESTED TABLES
The original content of itab2 is deleted. After the assignment, the column col2 has the same content as in itab1 and col4 remains initial. The tabular component col3 is resolved and the identically named component col2 found there. The original content of itab2-col3 is deleted. After the assignment, the column col2 has the same content as in itab1-col3, whereas the column col3 remains initial.
  • MOVE-CORRESPONDING EXPANDING NESTED TABLES KEEPING TARGET LINES
The original content of itab2 is preserved. Three new rows are added, to which the same applies as to the results of the previous assignment.