MOVE-CORRESPONDING - itab
7.31 | 7.40 | 7.54
MOVE-CORRESPONDING [EXACT] itab1 TO itab2.
[EXPANDING NESTED TABLES] [KEEPING TARGET LINES].
This variant of the statement
internal tables to be
itab2. It searches for
all similarly named components in the row types of
and assigns them from
itab2 in accordance with the rules below.
- If the row type is structured, the components are the structure components.
A non-structured row type is handled like a structure with a single component. The type of the component
is the row type of the internal table (elementary), is a table itself, or is a reference variable. The component has an internal name that is the same for all tables.
If there are components with the same name, the target table
itab2 is deleted
without the addition
KEEPING TARGET LINES and the same number of initial
rows are inserted as exist in the source table
itab1. The rows of the source
table are then extracted sequentially (in the same order as in the statement
LOOP) and the content of each row is assigned to the corresponding row
in the target table in accordance with the rules for
MOVE-CORRESPONDING [EXACT] for structures. Finally, the
table keys and associated
table indexes are updated (if necessary) in the target table in accordance with the rules
insertions in internal tables. The relevant exceptions are raised if uniqueness is violated.
If there are no components with the same name, no assignment is made and the target table is left unchanged.
MOVE-CORRESPONDINGnever has an effect when an internal table with a non-structured row type is assigned to an internal table with a structured row type (or when the assignment is the other way round).
MOVE-CORRESPONDINGhas the same effect on the assignment of an internal table with non-structured row type to a similar table as a regular assignment.
If an internal table,
itab, is assigned to itself using
MOVE-CORRESPONDING, the statement is ignored. This also means that the rows are not deleted first and then filled again.
The convertibility of the components, if known, is checked statically. If the convertibility cannot be identified statically, a runtime error is only raised if an assignment is really performed.
... EXPANDING NESTED TABLES
If this addition is specified, the individual rows are assigned in accordance with the rules for
MOVE-CORRESPONDING [EXACT] with
EXPANDING NESTED TABLES specified, and tabular components are resolved at every hierarchy level.
If the addition is not specified, the individual rows are assigned in accordance with the rules for
MOVE-CORRESPONDING [EXACT] without
EXPANDING NESTED TABLES specified, and tabular components are assigned in accordance with the
assignments or lossless assignments.
... KEEPING TARGET LINES
This addition stops the target table
itab2 from being deleted. Instead, it
appends the same number of initial rows as exist in the source table
The rows of the source tables are then mapped to these rows. The table keys and indexes are then updated across all rows. If no identically named components are found, the target table remains unchanged.
KEEPING TARGET LINES is only effective on the rows of
itab2. It cannot be effective on nested tables, even when specified with the addition
EXPANDING NESTED TABLES. This is because nested tables are always resolved in new initial rows.
Assignment of four identically named components of standard table
spfli_tab to a sorted table
TYPES: BEGIN OF flight, carrid TYPE spfli-carrid, connid TYPE spfli-connid, cityfrom TYPE spfli-cityfrom, cityto TYPE spfli-cityto, END OF flight. DATA flights TYPE SORTED TABLE OF flight WITH UNIQUE KEY carrid connid. SELECT * FROM spfli INTO TABLE @DATA(spfli_tab). MOVE-CORRESPONDING spfli_tab TO flights. cl_demo_output=>display( flights ).