Application Development 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: 

Merge all internal tables

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

anversha_s
Active Contributor
0 Kudos

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

10 REPLIES 10

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

former_member404244
Active Contributor
0 Kudos

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

Former Member
0 Kudos

use append lines of itab1 to itab like this.

regards

shiba dutta

Former Member
0 Kudos

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.

anversha_s
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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.

jayanthi_jayaraman
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

0 Kudos

if you need to append the values of all the tables in to ifinal then use

append lines of itab1 to ifinal