ABAP - Keyword Documentation →  ABAP - Programming Language →  Processing Internal Data →  Assignments →  Assigning Structure Components →  CORRESPONDING, Component Operator → 
Mail Feedback

CORRESPONDING, Lookup Table

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 result 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 line type must be structured. In addition, 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:

This means that the component by component assignment takes place between the lookup table lookup_tab as the source table and an interim 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, ... The same internal table can only be specified for itab and lookup_tab if this is known statically. If it is only known at runtime, the expression cannot be evaluated and the runtime error CORRESPONDING_SELF occurs.

The search for the line in lookup_tab must take place using a sorted table key or a hash key:

The comparison fields s1, s2, ... must completely cover the used table key.

Hints

Example

Lines of internal table itab1 that exist 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 ) ).
FINAL(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 ).

Executable Examples