Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Join Internal Tables

anuradha_wijesinghe
Participant
0 Likes
608

I have ITAB like itab1 and itab2 ad bellow. I need to join that itabs as I have shown in bellow. Please let me know easy way for going that.

                                ITAB1
SOLI FIED1FIELD2PO
SO1LI1F11F21
SO2LI2F12F22
SO3LI3F13F23
                 ITAB2
SOLIPO
SO1LI1PO11
SO1LI1PO12
SO1LI1PO13
SO2LI2PO21
SO2LI2PO22
SO3LI3PO31
SO3LI3PO32
SO3LI3PO33

With join these table O need to get bellow table. Please tel me a method to do that please.

                            ITAB_FINAL
SOLI FIED1POFIELD2
SO1LI1F11PO11F21
SO1LI1F11PO12F21
SO1LI1F11PO13F21
SO2LI2F12PO21F22
SO2LI2F12PO22F22
SO3LI3F13PO31F23
SO3LI3F13PO32F23
SO3LI3F13PO33F23
3 REPLIES 3
Read only

philipdavy
Contributor
0 Likes
559

Hi Anuradha,

If I understood correctly,

  • You have the two internal tables ITAB1 and ITAB2 (already populated), loop through your second internal table and read the first internal table with key SO and LI.
  • Copy the required corresponding values from ITAB1 and ITAB2 into your final internal table.
  • Pseudo Code:

       Loop at itab2 into wa_itab2.

       Read itab1 into wa_itab1 with key SO = wa_itab2-SO and LI = wa_itab2-LI.

     * Copy the values required to populate the final internal table.
    
     if sy-subrc = 0.
      wa_final-SO = wa_itab2-SO.
      wa_final-LI   = wa_itab2-LI.
      wa_final-field1 = wa_itab1-field1.
      wa_final-PO = wa_itab2-PO.
      wa_final-field2 = wa_itab1-field2.
     append wa_final to itab_final.
     clear: wa_final.
    endif
Endloop.
Regards,
Philip.

      

Read only

Former Member
0 Likes
559

Hi,

For the above requirement, loop the ITAB2 and then read the ITAB1 with key fields as SO and LI.

Assign the corresponding fields to the final internal table.

Below is the sample code,

loop at it_tab2 into wa_tab2.

  read TABLE it_tab1 into wa_tab1 with KEY SO = wa_tab2-SO   LI = wa_tab2-LI.

  wa_final-SO = wa_tab2-SO.

  wa_final-LI = wa_tab2-LI.

  wa_final-FIELD1 = wa_tab1-field1.

  wa_final-PO = wa_tab2-po.

  wa_final-FIELD2 = wa_tab1-field2.

  APPEND wa_final to it_final.

ENDLOOP.

Read only

Former Member
0 Likes
559

loop at itab2 into wa_itab2.
   READ TABLE itab1 into wa_itab1 with key so = wa_itab2-so li = wa_itab2-li.
   MOVE-CORRESPONDING wa_itab1 to wa_final.
   MOVE-CORRESPONDING wa_itab2 to wa_final.
   append wa_final to it_final.
endloop.