ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Assignments → Assigning Structure Components → Assigning Components: Examples
Component operator, lookup table
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( `itab`
)->write( itab ).
out->next_section(
`lookup_tab`
)->write( lookup_tab ).
itab = CORRESPONDING #(
itab FROM lookup_tab
USING KEY mkey b1 = a1 b2 = a2 ).
out->next_section(
`itab = CORRESPONDING #( itab FROM lookup_tab USING ... )`
)->write( itab ).
itab = CORRESPONDING #(
itab FROM lookup_tab
USING KEY mkey b1 = a1 b2 = a2
MAPPING a1 = a1 a2 = a2 b1 = b1 b2 = b2 c2 = d2 ).
out->next_section(
`itab = CORRESPONDING #( itab FROM lookup_tab ` &&
`USING ... MAPPING ... )`
)->write( itab ).
jtab = CORRESPONDING #(
itab FROM lookup_tab
USING KEY mkey b1 = a1 b2 = a2 ) ##operator.
out->next_section(
`jtab = CORRESPONDING #( itab FROM lookup_tab USING ... )`
)->write( jtab ).
out->display( ).
Description
This example joins two internal tables itab
and itab2
in a constructor expression with the component operator CORRESPONDING
, which uses the
variant with lookup table.
- The first assignment specifies the condition
b1 = a1 b2 = a2
without a mapping rule afterUSING
. In thelookup_tab
, one row is found for the first and third row ofitab
and its identically named components are assigned to the corresponding row ofitab
, whereb1
andb2
fromlookup_tab
anda1
anda2
fromitab
are ignored here. The only identically named component isc1
. All other components keep their preceding value fromitab
. 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
itab
are modified.
- Finally, the third assignment still demonstrates the assignment of the expression to an internal
table
jtab
that does not have the type ofitab
but is compatible with it. The full result of the expression is assigned tojtab
. The pragma##operator
hides the syntax check warning stating that a temporary copy ofitab
needs to be created.