ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Assignments → Assigning Structure Components → CORRESPONDING - Component Operator
CORRESPONDING - Base Form
Other versions:
7.31 | 7.40 | 7.54
Syntax
... { CORRESPONDING dtype|#( [DEEP]
[BASE ( base )]
struct|{itab [
duplicates]} ) }
| { CORRESPONDING dtype|#( [BASE ( base )]
struct|{itab [
duplicates]}
mapping ) } ...
Addition
Effect
This variant of the component operator
CORRESPONDINGconstructs a result with the target type specified using dtype
or # from the components of a parameter struct or itab. struct and itab are
general expression positions.
- If the target type is a structured type, a structure
structmust be used as a parameter. The expression creates a structure of the target type. The target structure is either initial or is assigned the value ofbaseafter the optional addition BASE as a start value. The target structure is then by default assigned the identically named components ofstructin accordance with the rules ofMOVE-CORRESPONDINGfor structures.
- If the target type is a table type, an internal table
itabmust be used as a parameter. The expression creates an internal table of the target type. The target table is either initial or is assigned the value ofbaseafter the optional addition BASE as a start value. The target table is then by default assigned the identically named columns ofitabin accordance with the rules ofMOVE-CORRESPONDINGfor internal tables using the addition KEEPING TARGET LINES. Here, the addition duplicates can be used to define the behavior with respect to duplicate rows occurring in a target table with unique table keys.
If the addition DEEP is specified, the assignment is made in the same way
as with the addition EXPANDING
NESTED TABLES of the statement MOVE-CORRESPONDING. A mapping rule
mapping can
be used to override the matching name assignment rule of MOVE-CORRESPONDING.
If a mapping rule is specified, the addition DEEP is set implicitly. It is not allowed to be set explicitly.
Notes
- An assignment of structures
struct2 = CORRESPONDING #( struct1 ).
BASE is not the same as an assignment
MOVE-CORRESPONDING struct1 TO struct2.
MOVE-CORRESPONDING, all not identically named components in struct2
keep their value. If the result of the constructor expression is assigned, however, they are assigned
the value from there. This value is initial for ignored components. This behavior can be overridden using the addition BASE.
- In the case of an assignment of a parameter to the target type and its assignment to a data object
dobj = CORRESPONDING type( ... ).
Example
Assignment of four identically named components of standard table spfli_tab to a temporarily sorted table of type flights on an operand position.
TYPES:
BEGIN OF flight,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
cityfrom TYPE spfli-cityfrom,
cityto TYPE spfli-cityto,
END OF flight.
TYPES
flights TYPE SORTED TABLE OF flight WITH UNIQUE KEY carrid connid.
SELECT *
FROM spfli
INTO TABLE @DATA(spfli_tab).
cl_demo_output=>display( CORRESPONDING flights( spfli_tab ) ).
Executable Examples
Addition
... BASE ( base ) ...
Effect
The addition BASE can be used to specify a start value base for the new structure or internal table. base is a
functional operand position in which a database convertible to the target type can be specified.
If the addition BASE is specified, the value of base is assigned to the target structure or target table in accordance with the general
assignment rules before the remainder of the expression
is evaluated. Here, the addition duplicates
after itab can be used to define the behavior with respect to duplicate rows occurring in a target table.
Notes
- Unlike the operators
NEWandVALUE, parentheses must be placed aroundbaseinCORRESPONDING.
- Unlike the operators
NEWandVALUE, the data type ofbaseis not used inCORRESPONDINGto determine a result type specified using#.
- The addition
BASEcan be used with the component operator to replace the statementMOVE-CORRESPONDINGas follows:
- An assignment of structures
struct2 = CORRESPONDING #( BASE ( struct2 ) struct1 ).
is the same as an assignment
MOVE-CORRESPONDING struct1 TO struct2.
- An assignment of internal tables
itab2 = CORRESPONDING #( BASE ( itab2 ) itab1 ).
is the same as an assignment
MOVE-CORRESPONDING itab1 TO itab2 KEEPING TARGET LINES.
Example
Assignment of results of the component operator without and with addition BASE
to existing structures of the same content. The value of the component that is not available in the source structure is only retained if BASE is used.
DATA:
BEGIN OF src,
a TYPE i VALUE 1,
b TYPE i VALUE 2,
END OF src,
BEGIN OF target1,
b TYPE i VALUE 11,
c TYPE i VALUE 12,
END OF target1.
DATA(target2) = target1.
target1 = CORRESPONDING #( src ).
target2 = CORRESPONDING #( BASE ( target2 ) src ).
cl_demo_output=>new( )->write( target1 )->display( target2 ).