2008 Aug 14 8:03 AM
hi!!
how to move records of two internal tables into one internal table?? and both the internal table has different fields....
regards
Puneet
hi!!
how to move records of two internal tables into one internal table?? and both the internal table has different fields....
regards
Puneet
2008 Aug 14 8:10 AM
Hi,
For this u need to have at least one common field on ur two internal tables.
IF so,
declare a final internal table with all fields u reqire.
loop through one internal table.
move the values to final internla table.
now read the second internla table with that common field and move those values to final internla table.
2008 Aug 14 8:10 AM
Hi,
Try this way,
As you are talking that both the internal table has differerent structure then use Move-corresponding.
Loop at itab1 into wa1.
Clear wa2.
Move-corresponding wa1 to wa2.
Append wa2 to itab2.
Eendloop.Regards,
Sujit
2008 Aug 14 8:20 AM
Hi puneet,
If you want to move tha data from two different internal tables into a single internal table, you should have atleast one common field in these two tables.
Suppose you have f1, f2, f3 in itab1 and f1, f4, f5, f6 in itab2.
wa_tab1, wa_tab2, wa_tab3 are the work areas of internal tables itab1,itab2 and itab3 respectively.
Then do the following:
Loop at itab1 into wa_tab1.
wa_tab3-f1 = wa_tab1-f1.
wa_tab3-f2 = wa_tab1-f2.
wa_tab3-f3 = wa_tab1-f3.
Read table itab2 into wa_tab2 with key f1 = wa_tab1-f1.
wa_tab3-f4 = wa_tab2-f4.
wa_tab3-f5 = wa_tab2-f5.
wa_tab3-f6 = wa_tab2-f6.
append wa_tab3 to itab3.
endloop.
Hope this will help you.
Regards,
Nitin.
2008 Aug 14 9:05 AM
Hi puneet,
here is the sample code just go through this....
tables:mara,makt.
data:begin of wa_itab,
matnr type mara-matnr,
ernam type mara-ernam,
end of wa_itab.
data:begin of wa_itab1,
maktx type makt-maktx,
spras type makt-spras,
end of wa_itab1.
data:begin of wa_itab2,
matnr type mara-matnr,
ernam type mara-ernam,
maktx type makt-maktx,
spras type makt-spras,
end of wa_itab2.
data:itab like wa_itab occurs 0.
data:itab1 like wa_itab1 occurs 0.
data:itab2 like wa_itab2 occurs 0.
select matnr ernam from mara into table itab up to 5 rows.
select maktx spras from makt into table itab1 up to 5 rows.
loop at itab into wa_itab.
wa_itab2-matnr = wa_itab-matnr.
wa_itab2-ernam = wa_itab-ernam.
INSERT wa_itab INTO itab INDEX 1.
endloop.
loop at itab1 into wa_itab1.
wa_itab2-maktx = wa_itab1-maktx.
wa_itab2-spras = wa_itab1-spras.
INSERT wa_itab2 INTO itab2 INDEX 1.
endloop.
loop at itab2 into wa_itab2.
write:/ wa_itab2-matnr ,
wa_itab2-ernam ,
wa_itab2-maktx ,
wa_itab2-spras.
endloop.
i hope u will get some help...
Thanks & Regards
Ashu Singh.