The new use of CORRESPONDING key word with MAPPING & EXCEPT combination allows more powerful data transfer between two structures. The below post shows some variants of it.
Program
TYPES: BEGIN OF add1,
name(20), city(20), pin(20), phone_num(10),email_id(20),
END OF add1.
TYPES: BEGIN OF add2,
name(20),city(20),state(10),phone(10),email_id(20),
END OF add2.
DATA(my_add1) = VALUE add1(
name = ‘Developer’
city = ‘Bangalore’
pin = ‘560088’
phone_num = ‘11223344’
email_id = ‘dev_email@yhhoo.com’ ).
WRITE:/ ‘Address 1’.
WRITE:/1 ‘Name’, 22 ‘City’, 45 ‘PIN’, 55 ‘Phone_num’, 70 ‘Email_id’.
WRITE:/1 my_add1–name, 22 my_add1–city, 45 my_add1–pin,
55 my_add1–phone_num, 70 my_add1–email_id.
ULINE.
” Creating data object my_add2 of add2 from data object my_add1 of add1
” Using corresponding
DATA(my_add2) = CORRESPONDING add2( my_add1 ).
WRITE:/ ‘Address 2’.
WRITE:/1 ‘Name’, 22 ‘City’, 45 ‘State’, 70 ‘Phone’, 85 ‘Email_id’.
WRITE:/1 my_add2–name, 22 my_add2–city, 45 my_add2–state,
70 my_add2–phone, 85 my_add2–email_id.
Output : only matching fields are passed from my_add1 to my_add2 structure.
Program
TYPES: BEGIN OF add1,
name(20), city(20), pin(20), phone_num(10),email_id(20),
END OF add1.
TYPES: BEGIN OF add2,
name(20),city(20),state(10),phone(10),email_id(20),
END OF add2.
DATA(my_add1) = VALUE add1(
name = ‘Developer’
city = ‘Bangalore’
pin = ‘560088’
phone_num = ‘11223344’
email_id = ‘dev_email@yhhoo.com’ ).
WRITE:/ ‘Address 1’.
WRITE:/1 ‘Name’, 22 ‘City’, 45 ‘PIN’, 55 ‘Phone_num’, 70 ‘Email_id’.
WRITE:/1 my_add1–name, 22 my_add1–city, 45 my_add1–pin,
55 my_add1–phone_num, 70 my_add1–email_id.
ULINE.
” Creating data object my_add2 of add2 from data object my_add1 of add1
” Using corresponding with MAPPING addition for unmatched fields names
DATA(my_add2) = CORRESPONDING add2( my_add1 MAPPING phone = phone_num ).
WRITE:/ ‘Address 2’.
WRITE:/1 ‘Name’, 22 ‘City’, 45 ‘State’, 70 ‘Phone’, 85 ‘Email_id’.
WRITE:/1 my_add2–name, 22 my_add2–city, 45 my_add2–state,
70 my_add2–phone, 85 my_add2–email_id.
Output : only matching fields are passed from my_add1 to my_add2 structure and also the fields specified in the MAPPING condition .
Program
TYPES: BEGIN OF add1,
name(20), city(20), pin(20), phone_num(10),email_id(20),
END OF add1.
TYPES: BEGIN OF add2,
name(20),city(20),state(10),phone(10),email_id(20),
END OF add2.
DATA(my_add1) = VALUE add1(
name = ‘Developer’
city = ‘Bangalore’
pin = ‘560088’
phone_num = ‘11223344’
email_id = ‘dev_email@yhhoo.com’ ).
WRITE:/ ‘Address 1’.
WRITE:/1 ‘Name’, 22 ‘City’, 45 ‘PIN’, 55 ‘Phone_num’, 70 ‘Email_id’.
WRITE:/1 my_add1–name, 22 my_add1–city, 45 my_add1–pin,
55 my_add1–phone_num, 70 my_add1–email_id.
ULINE.
” Creating data object my_add2 of add2 from data object my_add1 of add1
” Using corresponding with MAPPING addition for unmatched fields names
” with EXCEPT addition for restricting fields from moving
DATA(my_add2) = CORRESPONDING add2( my_add1 MAPPING phone = phone_num
EXCEPT city email_id ).
WRITE:/ ‘Address 2’.
WRITE:/1 ‘Name’, 22 ‘City’, 45 ‘State’, 70 ‘Phone’, 85 ‘Email_id’.
WRITE:/1 my_add2–name, 22 my_add2–city, 45 my_add2–state,
70 my_add2–phone, 85 my_add2–email_id.
Output : only matching fields except the fields specified in the EXCEPT condition are passed from my_add1 to my_add2 structure and also the fields specified in the MAPPING condition . So here the CITY field & EMAIL_ID field though matches but not passed to the target structure due to EXCEPT condition.
Thank you for another magnificent post. Where else could anybody get that type of information in such an ideal way of writing? I’ve a presentation subsequent week, and I am at the search for such information.
LikeLike