New way of using CORRESPONDING in ABAP

NEW STUFF

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
TYPESBEGIN OF add1,
                       name(20),  city(20) pin(20),  phone_num(10),email_id(20),
                END OF add1.
TYPESBEGIN OF add2,
                      name(20),city(20),state(10),phone(10),email_id(20),
                   END OF add2.
DATA(my_add1VALUE 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_add1name22 my_add1city45 my_add1pin,
               55 my_add1phone_num70 my_add1email_id.
ULINE.

” Creating data object my_add2 of add2 from data object my_add1 of add1
” Using corresponding

DATA(my_add2CORRESPONDING add2my_add1 ).
WRITE:‘Address 2’.
WRITE:/1 ‘Name’22 ‘City’45 ‘State’70 ‘Phone’85 ‘Email_id’.
WRITE:/1 my_add2name  22 my_add2city45 my_add2state,
                    70 my_add2phone, 85  my_add2email_id.

Output : only matching fields are passed from my_add1 to my_add2 structure.

1


Program

TYPESBEGIN OF add1,
                       name(20),  city(20) pin(20),  phone_num(10),email_id(20),
                END OF add1.
TYPESBEGIN OF add2,
                      name(20),city(20),state(10),phone(10),email_id(20),
                   END OF add2.
DATA(my_add1VALUE 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_add1name22 my_add1city45 my_add1pin,
               55 my_add1phone_num70 my_add1email_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_add2CORRESPONDING add2my_add1 MAPPING phone phone_num ).

WRITE:‘Address 2’.
WRITE:/1 ‘Name’22 ‘City’45 ‘State’70 ‘Phone’85 ‘Email_id’.
WRITE:/1 my_add2name  22 my_add2city45 my_add2state,
                    70 my_add2phone, 85  my_add2email_id.

Output : only matching fields are passed from my_add1 to my_add2 structure and also the fields specified in the MAPPING condition . 

2


Program

TYPESBEGIN OF add1,
                       name(20),  city(20) pin(20),  phone_num(10),email_id(20),
                END OF add1.
TYPESBEGIN OF add2,
                      name(20),city(20),state(10),phone(10),email_id(20),
                   END OF add2.
DATA(my_add1VALUE 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_add1name22 my_add1city45 my_add1pin,
               55 my_add1phone_num70 my_add1email_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_add2CORRESPONDING add2my_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_add2name  22 my_add2city45 my_add2state,
                    70 my_add2phone, 85  my_add2email_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.

3


 

One comment

  1. 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.

    Like

Leave a Reply