CORRESPONDING - Lookup table
7.31 | 7.40 | 7.54
... CORRESPONDING dtype|#( itab FROM lookup_tab
USING [KEY key_name] s1 = t1 s2 = t2 ...
[mapping] ) ...
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
lookup_tab. The target type specified using
# must be a table type. The parameters
lookup_tab expect internal tables whose row type must be structured.
itab must be convertible to the target type.
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 in
itab, a row is searched for in lookup table
lookup_tabthat has the same content in the columns
s2, ... as the columns
t2, ... of the row in
itab. 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 in
lookup_tab. By default, the assignment is made in accordance with the rules of
MOVE-CORRESPONDINGfor structures with the addition EXPANDING NESTED TABLES, with the exception that the components used for searches are not assigned by default: The components
s2, ... from
lookup_tabused for searches are by default not assigned to the identically named components of
itaband the components
t2, ... from
itabused for searches are not assigned the identically named components from
- 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
as the source table and an intermediate result with the type of
itab as the
target table. A mapping rule
can be used to override the default assignment of identically named components and the default exclusion
of the components
s2, ... and
t2, ... It is not possible to specify the same internal table for
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 for
- If the addition
KEYis specified, the key
key_namespecified after it is used. The following can be specified for
- 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
s2, ... must cover the full table key.
- Unlike the basic form, this variant
does not have the addition
DEEP. Instead, it always behaves as if
DEEPwere specified. The addition
BASEcannot 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 table
lookup_tab. Here, the constructor expression is assigned to the same internal table as specified for
itab. In this case, the expression is optimized internally to work directly with
itabwithout 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 type
itabmust be created in full. This produces a syntax check warning that can be hidden by a pragma.
- If the same table is specified for
lookup_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.
Rows of internal table
itab1 that are present in internal table
itab2 are passed to
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 ).