Hi, CORRESPONDING # (formerly move-corresponding) can be used dynamically, you can examine the example below,
As an example, we draw the first 100 rows from the mara and determine our target table.
SELECT matnr, "-> material_code
mtart, "-> material_type
matkl "-> material_group
FROM mara
INTO TABLE @DATA(lt_mara) UP TO 100 ROWS.
DATA: BEGIN OF ls_malzeme,
malzeme_kodu TYPE mara-matnr,
malzeme_tipi TYPE mara-mtart,
malzeme_grubu TYPE mara-matkl,
END OF ls_malzeme,
lt_malzeme LIKE TABLE OF ls_malzeme.
* We create data from the types we will use for mapping,
DATA: ls_mapping TYPE cl_abap_corresponding=>mapping_info,
lt_mapping TYPE cl_abap_corresponding=>mapping_table.
* We fill the mapping table, there is an easier way, but I used the old still append below to make it look smooth
ls_mapping-level = 0.
ls_mapping-kind = cl_abap_corresponding=>mapping_component.
ls_mapping-srcname = 'MATNR'.
ls_mapping-dstname = 'MALZEME_KODU'.
APPEND ls_mapping TO lt_mapping.
ls_mapping-level = 0.
ls_mapping-kind = cl_abap_corresponding=>mapping_component.
ls_mapping-srcname = 'MTART'.
ls_mapping-dstname = 'MALZEME_TIPI'.
APPEND ls_mapping TO lt_mapping.
ls_mapping-level = 0.
ls_mapping-kind = cl_abap_corresponding=>mapping_component.
ls_mapping-srcname = 'MATKL'.
ls_mapping-dstname = 'MALZEME_GRUBU'.
APPEND ls_mapping TO lt_mapping.
* We instantiate class for Mapper
DATA(lr_dynamic_mapper) = cl_abap_corresponding=>create(
source = lt_mara
destination = lt_malzeme
mapping = lt_mapping ).
* Under the lr_dynamic_mapper object, we do the migration with the execute method.
lr_dynamic_mapper->execute(
EXPORTING
source = lt_mara
CHANGING
destination = lt_malzeme ).
The result is as follows 😊
