This is continuation of my blog series:

  1. ABAP Lesser Known Heroes Series – Group Column : Part 1 | SAP Blogs
  2. ABAP Lesser Known Heroes Series – Value Operator : Part 2 | SAP Blogs
  3. ABAP Lesser Known Heroes Series – TYPE RANGE OF : Part 3 | SAP Blogs
  4. ABAP Lesser Known Heroes Series – APPEND CORRESPONDING : Part 4

You may know MOVE CORRESPONDING between tables and structures , CORRESPONDING # operators etc. But what about APPEND CORRESPONDING ?

I have rarely seen or anyone talking about this particular command in the forum.  So here you go.

SAP opened up a new world of possibilities when they came up with MOVE-CORRESPONDING and CORRESPONDING# between internal tables where you could even map the fields, traverse down to deep structures , fetch the fields excepting some columns and so on.

But what if you want to loop through an internal table, change some values based on condition and append the same to an internal table of slighlty different structure? For example please look at below code.

Types: Begin of ty_city_temp, 
       city_temp type ztemp, 
       longitude type zlongitude, 
       district  type zdistrict, 
       END OF ty_city_temp . 

Types: Begin of ty_city_temp_windy, 
       city_temp type ztemp, 
       END OF ty_city_temp_windy. 

DATA: lt_city_temps       TYPE TABLE OF ty_city_temp, 
      lt_city_temps_windy TYPE TABLE OF ty_city_temp_windy, 
      lv_windy            TYPE ABAP_BOOL .


IF lv_windy = ABAP_TRUE. 
LOOP AT lt_city_temps reference into data(lr_city_temp)  . 

lr_city_temp->city_temp  = lr_city_temp->city_temp - 3 . "Only an assumption that temperature will be 
                                                        "less by 3 degree celcius when windy 
APPEND CORRESPONDING ty_city_temp_windy( lr_city_temp->* ) TO       lt_city_temps_windy . 
ENDLOOP. 
ENDIF.
       

 

Here we are saved from declaring another structure of type ty_city_temp_windy and another MOVE-CORRESPONDING statement . we are using APPEND CORRESPONDING statement and adding to the internal table.

 

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x