12-20-2006 6:13 AM
Hi,
I want to merge itab1,itab2,itab3,itab4 to ifinal.how to merge this internal table.pls help me to solve this.
Thanks,
Rajendra.
12-20-2006 6:20 AM
hi,
chk this sample.
check this.
data : begin of itab1 occurs 0. "itab with work area.
key_field1 like ztable1-key_field1,
field1 like ztable1-field1,
field2 like ztable1-field2,
endof itab1.
data : begin of itab2 occurs 0. "itab with work area.
key_field2 like ztable2-key_field2,
field3 like ztable2-field3,
field4 like ztable2-field4,
endof itab2.
data : begin of itab_final occurs 0.
key_field1 like ztable1-key_field1,
field1 like ztable1-field1,
field2 like ztable1-field2,
field3 like ztable2-field3,
field4 like ztable2-field4,
endof itab_final.
put the date final(merged) internal table
*****************************************
LOOP AT ITAB1.
MOVE-CORRESPONDING TO ITAB1 to ITAB_FINAL.
READ TABLE ITAB2 WITH KEY FILED1 = ITAB1-FIELD1.
if sy-subrc = 0.
MOVE-CORRESPONDING TO ITAB2 to ITAB_FINAL.
endif,
READ TABLE ITAB3 WITH KEY FILED1 = ITAB1-FIELD1.
if sy-subrc = 0.
MOVE-CORRESPONDING TO ITAB2 to ITAB_FINAL.
endif,
append itab_final.
clear itab_final.
endloop
Rgds
Anver
12-20-2006 6:16 AM
sort itab1 by field1.
sort itab2 by field1.
sort itab3 by field1.
sort itab4 by field1.
loop at itab1.
move itab1-field to it_final-field.
read table itab2 with key field1 = itab1-field1 binary search.
if sy-subrc = 0.
move itab2-field to it_final-field2.
endif.
read table itab3 with key field1 = itab1-field1 binary search.
if sy-subrc = 0.
move itab3-field to it_final-field3.
endif.
read table itab4 with key field1 = itab1-field1 binary search.
if sy-subrc = 0.
move itab4-field to it_final-field4.
endif.
append it_final.
clear it_final.
endloop.
12-20-2006 6:17 AM
Hi,
Just read the data you need from those tables and append them to the final internal table. Loop the itab and read the data you require from it.
-Priyanka.
12-20-2006 6:18 AM
Hi Rajendra,
loop one internal table having more records and then read rst of the internal tables and then finally pass them to final internal table.
For example..
Loop at iatb1.
read table itab2 with key <field> = itab1-<field>.
if sy-subrc eq 0.
move itab2-<field> to ifinal-field.
read table itab3 with key <field1> = itab1-<field1>
if sy-subrc eq 0.
move itab3-field1 to ifinal-field1.
endif.
endif.
append ifinal.
endloop.
Regards,
nagaraj
12-20-2006 6:18 AM
12-20-2006 6:19 AM
Loop at ifinal and
then loop at all the other internal tables one after another specifying the conditions and then fetch the data you require.
eg.
loop at ifinal.
loop at itab1 where....
ifinal-field1 = itab1-field1.
modify ifinal transporting field1.
endloop.
loop at itab2 where....
endloop.
..
..
endloop.
12-20-2006 6:20 AM
hi,
chk this sample.
check this.
data : begin of itab1 occurs 0. "itab with work area.
key_field1 like ztable1-key_field1,
field1 like ztable1-field1,
field2 like ztable1-field2,
endof itab1.
data : begin of itab2 occurs 0. "itab with work area.
key_field2 like ztable2-key_field2,
field3 like ztable2-field3,
field4 like ztable2-field4,
endof itab2.
data : begin of itab_final occurs 0.
key_field1 like ztable1-key_field1,
field1 like ztable1-field1,
field2 like ztable1-field2,
field3 like ztable2-field3,
field4 like ztable2-field4,
endof itab_final.
put the date final(merged) internal table
*****************************************
LOOP AT ITAB1.
MOVE-CORRESPONDING TO ITAB1 to ITAB_FINAL.
READ TABLE ITAB2 WITH KEY FILED1 = ITAB1-FIELD1.
if sy-subrc = 0.
MOVE-CORRESPONDING TO ITAB2 to ITAB_FINAL.
endif,
READ TABLE ITAB3 WITH KEY FILED1 = ITAB1-FIELD1.
if sy-subrc = 0.
MOVE-CORRESPONDING TO ITAB2 to ITAB_FINAL.
endif,
append itab_final.
clear itab_final.
endloop
Rgds
Anver
12-20-2006 6:20 AM
Hi,
loop at itab.
read table itab1 with key fld1 = itab-fld1.
if sy-subrc eq 0.
move-corresponding itab to itab4.
endif.
read table itab2 with key fld1 = itab-fld1.
if sy-subrc eq 0.
move-corresponding itab1 to itab4.
endif.
append itab4.
Regards
amole
itab4 will have all the merged data from table
loop at itab4.
write:/itab4-fld1...
endloop.
12-20-2006 6:20 AM
Hi,
If itab1 and itab2 are having one common field,then
loop at itab1.
move-corresponding itab1 to ifinal.
loop at itab2 where f1 = itab1-f1.
move-corresponding itab1 to ifinal.
append ifinal.
endloop.
endloop.
12-20-2006 6:21 AM
Hi,
Declare ifinal with all the fields of all internal table.
and follow this code.
loop at itab1.
read table itab2 with key f1 = itab1-f1. (here f1 is common field in itab1 and itab2).
read table itab3 with key f2 = itab1-f2.
read table itab4 with key f3 = itab1-f3.
move: itab1-f1 to ifinal-f1,
itab2-( ) to ifinal-( ). (in the same way all the fields to ifianl)
append ifinal.
clear ifinal.
endloop.
thanks,
srinivas
12-20-2006 6:22 AM
if you need to append the values of all the tables in to ifinal then use
append lines of itab1 to ifinal