Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Assignments →  Assigning Components →  CORRESPONDING - Component Operator 

CORRESPONDING - Components of Two Arguments

Other versions: 7.31 | 7.40 | 7.54

Syntax


... CORRESPONDING dtype|#( itab1 FROM itab2 USING [KEY key_name] 
                                            s1 = t1 s2 = t2 ... mapping  ) ...

Effect

This variant can only be used for internal tables. The target type specified using dtype or # must be a table type. The parameters itab1 and itab2 expect internal tables whose row type must be structured. Also, itab1 must be convertible to the target type. itab1 and itab2 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 itab1 is constructed as follows: For each row in itab1, a row is searched for in itab2 that has the same content in the columns s1, s2, ... as the columns t1, t2, ... of the row in itab1. 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 itab1 is 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 itab2 to the current row in itab1. By default, the assignment is made in accordance with the rules of MOVE-CORRESPONDING for structures with the addition EXPANDING NESTED TABLES, with the exception that the components used for searches are not assigned by default: The components s1, s2, ... from itab2 used for searches are by default not assigned to the identically named components of itab1 and the components t1, t2, ... from itab1 used for searches are not assigned the identically named components from itab2.
  • The intermediate result of the type of the table itab1 is 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 itab2 as the source table and an intermediate result with the type of itab1 as the target table. The same internal table can also be specified for itab1 and itab2. 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 search for the row in itab2 must take place using a sorted table key or a hash key:

  • If the addition KEY is not specified, a sorted table or a hashed table must be specified for itab2.
  • If the addition KEY is specified, the key key_name specified after it is used. The following can be specified for key_name:
  • a primary key using its predefined name primary_key or using an alias. If the primary key is specified, itab2 must be a sorted table or a hashed table.

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


Notes

  • Unlike when using the components of an argument, this variant does not have the addition DEEP. Instead, it always behaves as if DEEP were specified. The addition BASE cannot be specified either.

  • Generally, the type of itab1 and the target type must be identical.

  • In one common use case, an existing internal table itab1 is enriched with information from another internal table itab2. Here, the constructor expression is assigned to the same internal table as specified for itab1. In this case, the expression is optimized internally to work directly with itab1 without creating an intermediate result.

  • If the constructor expression is not assigned to the internal table specified for itab1 or if this table is not statically identifiable, the temporary intermediate result with the type itab1 must be created in full. This produces a syntax check warning that can be hidden by a pragma.

  • If the same table is specified for itab1 and itab2, 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 a runtime error occurs.

Examples

See