ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Assignments → Assigning Components → Assigning Components: Examples
Component Operator, Components of Two Arguments
This example demonstrates the component operator with FROM ... USING
.
Other versions:
7.31 | 7.40 | 7.54
Source Code
DATA(out) = cl_demo_output=>new( ).
out->begin_section( `itab1`
)->write( itab1 ).
out->next_section(
`itab2`
)->write( itab2 ).
itab1 = CORRESPONDING #(
itab1 FROM itab2
USING KEY mkey b1 = a1 b2 = a2 ).
out->next_section(
`itab1 = CORRESPONDING #( itab1 FROM itab2 USING ... )`
)->write( itab1 ).
itab1 = CORRESPONDING #(
itab1 FROM itab2
USING KEY mkey b1 = a1 b2 = a2
MAPPING a1 = a1 a2 = a2 b1 = b1 b2 = b2 c2 = d2 ).
out->next_section(
`itab1 = CORRESPONDING #( itab1 FROM itab2 USING ... MAPPING ... )`
)->write( itab1 ).
itab3 = CORRESPONDING #(
itab1 FROM itab2
USING KEY mkey b1 = a1 b2 = a2 ) ##operator.
out->next_section(
`itab3 = CORRESPONDING #( itab1 FROM itab2 USING ... )`
)->write( itab3 ).
out->display( ).
Description
This example joins two internal tables itab1
and itab2
in a constructor expression with the component operator CORRESPONDING
, which uses the
components of two arguments.
- The first assignment specifies the condition
b1 = a1 b2 = a2
without a mapping rule afterUSING
. Initab2
, one row is found for the first and third row ofitab1
and its identically named components are assigned to the corresponding row ofitab1
.b1
andb2
fromitab2
anda1
anda2
fromitab1
are ignored here. The only identically named component isc1
. All other components keep their preceding value fromitab1
. The second row is taken unchanged fromitab1
.
- In the second assignment, the default handling by specifying a mapping rule a1
= a1 a2 = a2 b1 = b1 b2 = b2 c2 = d2 is overridden by specifying a mapping relationship for all
components ignored until now. Accordingly, the content of all components in the first and third row of
itab1
are modified.
- Finally, the third assignment demonstrates the assignment of the expression to an internal table
itab3
that does not have the type ofitab1
but is compatible with it. The full result of the expression is assigned toitab3
. The pragma##operator
hides the syntax check warning stating that a temporary copy ofitab1
needs to be created.