ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Assignments → Assigning Components → Assigning Components: Examples
MOVE-CORRESPONDING for Structures
This example demonstrates the statement MOVE-CORRESPONDING for structures.
Other versions:
7.31 | 7.40 | 7.54
Source Code
out = cl_demo_output=>new( ).
fill_structures( ).
out->begin_section( `struct1` ).
display_structure1( ).
out->next_section( `struct2` ).
display_structure2( ).
out->begin_section(
`MOVE-CORRESPONDING` ).
MOVE-CORRESPONDING struct1 TO struct2.
display_structure2( ).
out->next_section(
`MOVE-CORRESPONDING EXPANDING NESTED TABLES` ).
MOVE-CORRESPONDING struct1 TO struct2 EXPANDING NESTED TABLES.
display_structure2( ).
out->display( ).
Description
MOVE-CORRESPONDING
and the available additions are used to declare two structures, struct1 and struct2, and assign them to each other.
struct1contains two elementary components,col1andcol2, and a tabular componentcol3with the componentscol1andcol2.
struct2contains two elementary components,col2andcol4, and a tabular componentcol3with the componentscol2andcol3.
The structures 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 struct1 and struct2 and the assignments work as follows:
MOVE-CORRESPONDING
col2 and col3
in struct2 have the same content as in struct1. Component col4 keeps its value.
MOVE-CORRESPONDING EXPANDING NESTED TABLES
col2 in struct2
has the same content as in struc1. col4 preserves
its value. The tabular component col3 is resolved and the identically named
component col2 found there. The original content of struct2-col3
is deleted. After the assignment, the column col2 has the same content as in struct1-col3, whereas the column col3 remains initial.