ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Assignments → Assigning Structure Components → CORRESPONDING - Component Operator
CORRESPONDING - Lookup table
Other versions:
7.31 | 7.40 | 7.54
Syntax
... CORRESPONDING dtype|#( itab FROM lookup_tab
USING [KEY key_name] s1 = t1 s2 = t2 ...
[mapping] ) ...
Effect
This variant of the component operator
CORRESPONDING can only be used for internal tables. The expression constructs an internal
table from the components of the internal table itab and a lookup table
lookup_tab. The lines of the internal table come from a comparison of itab
and lookup_tab. The target type specified using dtype
or # must be a table type. The parameters itab
and lookup_tab expect internal tables whose row type must be structured.
Also, itab must be convertible to the target type. itab and lookup_tab are
general expression positions.
The result of the expression is created in the following steps:
- First, an intermediate result of the type of the internal table
itabis constructed as follows: For each row initab, a row is searched for in lookup tablelookup_tabthat has the same content in the columnss1,s2, ... as the columnst1,t2, ... of the row initab. The search must take place using a sorted table key or a hash key (see below). If the key is not unique, the first row found is used.
- If no row like this is found, a row with the unchanged content of the row in
itabis inserted into the intermediate result.
- If a row like this is found, a row is inserted into the intermediate result that is the result of
an assignment of the row found in
itabto the current row inlookup_tab. By default, the assignment is made in accordance with the rules ofMOVE-CORRESPONDINGfor structures with the addition EXPANDING NESTED TABLES, with the exception that the components used for searches are not assigned by default: The componentss1,s2, ... fromlookup_tabused for searches are by default not assigned to the identically named components ofitaband the componentst1,t2, ... fromitabused for searches are not assigned the identically named components fromlookup_tab.
- The intermediate result of the type of the table
itabis assigned to the result of the expression in accordance with the regular assignment rules for internal tables and, if necessary, converted to the target type.
This means that the component by component assignment takes place between the lookup table lookup_tab
as the source table and an intermediate result with the type of itab as the
target table. A mapping rule mapping
can be used to override the default assignment of identically named components and the default exclusion
of the components s1, s2, ... and t1,
t2, ... It is not possible to specify the same internal table for itab
and lookup_tab, otherwise there can be a runtime error CORRESPONDING_SELF.
The search for the row in lookup_tab must take place using a sorted table key or a hash key:
- If the addition
KEYis not specified, a sorted table or a hashed table must be specified forlookup_tab.
- If the addition
KEYis specified, the keykey_namespecified after it is used. The following can be specified forkey_name:
- A secondary key using its name
- The primary key using its predefined name
primary_keyor using an alias. If the primary key is specified,lookup_tabmust be a sorted table or a hashed table.
The comparison fields s1, s2, ... must cover the full table key.
Notes
- Unlike the basic form, this variant
does not have the addition
DEEP. Instead, it always behaves as ifDEEPwere specified. The additionBASEcannot be specified either.
- Generally, the type of
itaband the target type must be identical.
- In one common use case, an existing internal table
itabis enriched with information from the lookup tablelookup_tab. Here, the constructor expression is assigned to the same internal table as specified foritab. In this case, the expression is optimized internally to work directly withitabwithout creating an intermediate result.
- If the constructor expression is not assigned to the internal table specified for
itabor if this table is not known statically, the temporary intermediate result with the typeitabmust be created in full. This produces a syntax check warning that can be hidden by a pragma.
- If the same table is specified for
itabandlookup_tab, a temporary copy of the table must be created as a target table of the assignment and a syntax check warning that can be hidden is produced here too. If this is not detected until runtime, the information needed to create the necessary temporary copy of the target object is missing and runtime error CORRESPONDING_SELF occurs.
Example
Rows of internal table itab1 that are present in internal table itab2 are passed to itab1.
TYPES:
BEGIN OF line,
value TYPE i,
comment TYPE string,
END OF line,
itab1 type STANDARD TABLE OF line WITH EMPTY KEY,
itab2 TYPE HASHED TABLE OF line WITH UNIQUE KEY value.
DATA(itab1) = VALUE itab1( for i = 1 UNTIL i >= 10 ( value = i ) ).
DATA(itab2) = VALUE itab2( ( value = 2 comment = `...` )
( value = 3 comment = `...` )
( value = 5 comment = `...` )
( value = 8 comment = `...` ) ).
itab1 = CORRESPONDING itab1( itab1 FROM itab2 USING value = value ).
cl_demo_output=>display( itab1 ).