ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Assignments → Assigning Components → Assigning Components: Examples
Component Operator, Mapping Rule
This example demonstrates the component operator with explicit mapping rules.
Other versions:
7.31 | 7.40 | 7.54
Source Code
DATA(out) = cl_demo_output=>new( ).
out->begin_section( `struct1`
)->write( struct1
)->next_section( `struct2`
)->write( struct2 ).
struct2 = CORRESPONDING #( struct1 ).
out->begin_section(
`struct2 = CORRESPONDING #( struct1 )`
)->write( struct2 ).
struct2 = CORRESPONDING #( struct1 MAPPING b4 = a3 ).
out->begin_section(
`struct2 = CORRESPONDING #( struct1 MAPPING b4 = a3 )`
)->write( struct2 ).
struct2 = CORRESPONDING #( struct1 MAPPING b4 = a1 ).
out->begin_section(
`struct2 = CORRESPONDING #( struct1 MAPPING b4 = a1 )`
)->write( struct2 ).
struct2 = CORRESPONDING #( struct1 EXCEPT a1 ).
out->begin_section(
`struct2 = CORRESPONDING #( struct1 EXCEPT a1 )`
)->write( struct2 ).
struct2 = CORRESPONDING #( struct1 MAPPING b4 = a3 EXCEPT a1 ).
out->begin_section(
`struct2 = CORRESPONDING #( struct1 MAPPING b4 = a3 EXCEPT a1 )`
)->write( struct2 ).
struct2 = CORRESPONDING #( struct1 MAPPING b4 = a3 EXCEPT * ).
out->begin_section(
`struct2 = CORRESPONDING #( struct1 MAPPING b4 = a3 EXCEPT * )`
)->write( struct2 ).
struct2 = CORRESPONDING #( struct1 EXCEPT * ).
out->begin_section(
`struct2 = CORRESPONDING #( struct1 EXCEPT * )`
)->write( struct2 ).
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.
- If no mapping rule is used, the identically named components
a1anda2are assigned and the other components remain initial.
- The mapping rule
MAPPING b4 = a3assigns the componenta3to the componentb4too.
- The mapping rule
MAPPING b4 = a1assigns the componenta1twice, tob4and to the identically named componenta1.
- The mapping rule
EXCEPT a1assigns only the componenta2to the identically named component, since the componenta1is excluded.
- Alongside the identical name assignment, the mapping rule MAPPING b4 = a3 EXCEPT
a1 assigns the component
a3to the componentb4anda1is excluded from the identical name assignment.
- The mapping rule
EXCEPT *does not assign any components and all components of the result remain initial.