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

merge between 2 itabs

Former Member
0 Likes
879

i have 1 itab

matnr lbkum min

1111 2 X

and another itab (2)

matnr lgort bwart

1111 10 601

i want to merge between them and have 1 itab that have all the data in 1 line

i have 1 itab

matnr lbkum min

1111 2 X

and another itab (2)

matnr lgort bwart

1111 10 601

i want to merge between them and have 1 itab that have all the data in 1 line

9 REPLIES 9
Read only

Former Member
0 Likes
848

data: begin of itab_final occurs 0.

matnr type matnr

lbkum type lbkum

min type min

lgort type lgort

bwart type bwart

end of itab.

itab_final[] = itab1[]

loop at itab_final.

read table itab2 with key matnr = itab_final-matnr.

itab_final-lgort = itab2-lgort.

itab_final-bwart = itab2-bwart.

modify itab_final.

endloop.

Read only

Former Member
0 Likes
848

Hi Liat,

If MATNR is the key field then take and internal table with all the fields, say it_outtab. Now loop at on table and read the other table's records with key MATNR. Then pass all these values to the it_outtab work area and append the same to it_outtab. Hope this may help you...

Thanks and Regards,

Bharat Kumar Reddy.V

Read only

Former Member
0 Likes
848

HI,

Create a table with the fields of both the tables.


loop at itab1.
 read table itab2 with key matnr = itab1-matnr.
 if sy-subrc = 0.
  move-correspond itab1 to itab3.
  move-correspond itab1 to itab3.
  append itab3.
 endif.
endloop.

Regards,

Ravi

Note : Please mark the helpful answers

Read only

0 Likes
848

i want to give point but i dont see them

Read only

0 Likes
848

Ravi why i need to make move-corresponding 2 times

Read only

0 Likes
848

Hi,

One move statement for each table will be required.

Take a look at my other posts where I have answered a similar one.

Points - Don't worry about it, do it when you can.

Regards,

Ravi

Read only

Former Member
0 Likes
848

Hello Liat,

As the two internal tables are having different structure, u will have to create a 3rd internal table with all the fields from both the internal tables. Now loop through the first internal table, clearing the work area first and then moving the fields to the work area and appending.after u have doen with all the records perfrom the same for secod table. U can then sort the table on matnr.

Read only

Former Member
0 Likes
848

Hi lia tal,

i hope ur prob will solved if u declare another table (itab3) as below..

data:begin of itab3 occurs 0.

include structure itab1.

include structure itab2.

data:end of itab3.

Regards,

Kiran

Read only

Former Member
0 Likes
848
data : begin of itab occurs 0 ,
 
        matnr like ztab-matnr,
        lbkum like ...
        min   like ..
        lgort like ...
        bwart like ..
       end of itab.

loop at itab1.
   Loop at itab2 where matnr = itab1-matnr.
   if sy-subrc eq 0.
      itab-matnr  = itab1-matnr.
      itab-lbknum = itab1-lbknum.
      itab-min    = itab1-min.
      itab-lgort  = itab2-lgort.
      itab-bwart  = itab2-bwart.
      Append itab.
      clear itab.
   endif.
  endloop.
endloop.

where itab1 is ur first table and itab2 is ur second table