ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Assignments → Assigning Components → Assigning Components: Examples
Component Operator, Nested Mapping Rule
This example demonstrates the component operator with a nested mapping rule.
Other versions:
7.31 | 7.40 | 7.54
Source Code
DATA(out) = cl_demo_output=>new( ).
out->begin_section( `struct1`
)->write( CORRESPONDING out1( struct1 )
)->write( struct1-istruct
)->write( struct1-itab ).
struct2 = CORRESPONDING #( struct1 ).
out->next_section(
`struct2 = CORRESPONDING #( struct1 )`
)->write( CORRESPONDING out2( struct2 )
)->write( struct2-istruct
)->write( struct2-jtab ).
struct2 = CORRESPONDING #( struct1 MAPPING jtab = itab ).
out->next_section(
`struct2 = CORRESPONDING #( struct1 MAPPING jtab = itab )`
)->write( CORRESPONDING out2( struct2 )
)->write( struct2-istruct
)->write( struct2-jtab ).
struct2 = CORRESPONDING #( struct1 MAPPING
( istruct = istruct MAPPING b1 = a1 EXCEPT a2 )
( jtab = itab MAPPING b1 = a1 ) ).
out->next_section(
`struct2 = CORRESPONDING #( struct1 MAPPING ( ... ) )`
)->write( CORRESPONDING out2( struct2 )
)->write( struct2-istruct
)->write( struct2-jtab ).
out->display( ).
Description
The example assigns the result of a constructor expression with the component operator CORRESPONDING that uses the
components of an argument struct1 to a compatible structure struct2. Various
mapping rules are demonstrated. The structures contain a substructure and a tabular component.
- If there is not mapping rule, the identically named components
a2andistructare assigned at the top level. The substructureistructis resolved and the componenta2is assigned here. The tabular components are not identically named and are not assigned.
- The mapping rule
MAPPING jtab = itabis used to assign the tabular component too. Here, only the identically named columna2is respected.
- The nested mapping rule
MAPPING ( istruct = istruct MAPPING b1 = a1 EXCEPT a2 )
( jtab = itab MAPPING b1 = a1 )
- specify a mapping relationship for the components of the substructure
istruct. Here,istruct = istructmust be specified at the top level.
- define a mapping for the tabular components. Here, a mapping is also nested for their columns.
a2 of the substructure, excluded using EXCEPT.