Corresponding Operator
You must have guessed that this will be replacement of move-corresponding from ECC . You are absolutely correct but this operator is much more powerful then move-corresponding. We can even use internal table in addition to structures and the feature which I like the most is that we can provide our own mapping rule which means it is no limited to columns with name.
TYPES : BEGIN OF ty_int1,
name TYPE char10,
value TYPE char20,
END OF ty_int1.
TYPES : tt_int1 TYPE STANDARD TABLE OF ty_int1 WITH DEFAULT KEY. " internal table
TYPES : BEGIN OF ty_deep,
region TYPE char5,
country TYPE char10,
ls_work_info TYPE tt_int1,
END OF ty_deep,
tt_deep TYPE STANDARD TABLE OF ty_deep WITH DEFAULT KEY.
DATA(lt_deep) = VALUE tt_deep(
(
region = 'APJ' country = 'INDIA'
ls_work_info = VALUE #(
( name = 'TECH' value = 'SAP' )
( name = 'DOMAIN' value = 'ABAP' )
)
) " first row
(
region = 'EMEA' country = 'UK'
ls_work_info = VALUE #(
( name = 'TECH' value = 'ML' )
( name = 'DOMAIN' value = 'PYTHON' )
)
) " second row
).
DATA(lt_deep2) = VALUE tt_deep(
(
region = 'APJ2' country = 'INDIA2'
ls_work_info = VALUE #(
( name = 'TECH2' value = 'SAP2' )
( name = 'DOMAIN2' value = 'ABAP2' )
)
) " first row
(
region = 'EMEA2' country = 'UK2'
ls_work_info = VALUE #(
( name = 'TECH2' value = 'ML2' )
( name = 'DOMAIN2' value = 'PYTHON2' )
)
) " second row
).
DATA(lt_int1) = VALUE tt_int1( ( name = 'TECH' value = 'SAP' )
( name = 'DOMAIN' value = 'ABAP' )
).
name TYPE char10,
value TYPE char20,
exp TYPE i,
END OF ty_int2,
tt_int2 TYPE STANDARD TABLE OF ty_int2 WITH DEFAULT KEY.
MOVE-CORRESPONDING ls_source TO ls_target. "Overwrite ls_target
*NEW
DATA(ls_target1) = CORRESPONDING ty_int1( ls_source ).
ls_target = VALUE #( name = 'DOMAIN' value = 'ABAP' exp = '5' ).
ls_target = CORRESPONDING #( BASE ( ls_target ) ls_source ).
*Create new table with extra column added as 'EXP'
DATA(lt_target2) = VALUE tt_int2(
).
* Changing back to original
lt_target2 = VALUE #(
( name = 'TECH2' value = 'SAP2' exp = '5' )
( name = 'DOMAIN2' value = 'ABAP2' exp = '10')
).
lt_target2 = CORRESPONDING #( BASE ( lt_target2 ) lt_int1 ) . “ Will append the values
MAPPING <column from target structure>
lt_target2 = CORRESPONDING #( BASE ( lt_target2 ) lt_int1 MAPPING name = value ) .
TYPES : BEGIN OF ty_int2,
name TYPE char10,
value TYPE char20,
END OF ty_int2,
tt_int2 TYPE STANDARD TABLE OF ty_int2 WITH DEFAULT KEY,
BEGIN OF ty_deep,
region TYPE char5,
country TYPE char10,
ls_work_info TYPE tt_int2,
END OF ty_deep,
tt_deep TYPE STANDARD TABLE OF ty_deep WITH DEFAULT KEY.
DATA(lt_deep) = VALUE tt_deep(
(
region = 'APJ' country = 'INDIA'
ls_work_info = VALUE #(
( name = 'TECH' value = 'SAP' )
( name = 'DOMAIN' value = 'ABAP' )
)
) " first row
(
region = 'EMEA' country = 'UK'
ls_work_info = VALUE #(
( name = 'TECH' value = 'ML' )
( name = 'DOMAIN' value = 'PYTHON' )
)
) " second row
).
DATA(lt_deep2) = VALUE tt_deep(
(
region = 'APJ2' country = 'INDIA2'
ls_work_info = VALUE #(
( name = 'TECH2' value = 'SAP2' )
( name = 'DOMAIN2' value = 'ABAP2' )
)
) " first row
(
region = 'EMEA2' country = 'UK2'
ls_work_info = VALUE #(
( name = 'TECH2' value = 'ML2' )
( name = 'DOMAIN2' value = 'PYTHON2' )
)
) " second row
).
·
Original values of tables :- 'Expanding nested tables' is used to expand deep structure and 'Keeping target lines' is used so that internal table data from lt_deep will not overwrite data of lt_deep2 but data will get appended.
No comments:
Post a Comment