Skip to Content
0
Former Member
Feb 23, 2009 at 03:10 PM

Select Statement within a Loop

146 Views

Hi All,

I am currently having a problem with the optimization of my code. The code works well, but i want to know how can i avoid the use of select within a loop as shown..

let us suppose that i have 5 tables -> tab1, tab2, tab3, tab4, and tab5 having corresponding internal tables intab1.... intab5

unrelated to all of these, i am getting an internal table (intab) from a function module FM1. This internal table has fields f1,f2,f3,f4,f5 which are keys in tab1....tab5

Finally i have an output table (out_tab) which has all the fields of tab1, tab2...tab5.... corresponding workarea for this is wa_out_tab.

This is the code that i have written so far.

call function 'fm1'
importing xyztab = intab.

loop at intab into wa_intab.

clear wa_out_tab.

select * from tab1 into intab1 where f1 eq wa_intab-f1.

..
//copy all fields from intab1 into corresp. fields of wa_out_tab

select * from tab2 into intab2 where f2 eq wa_intab-f2.

...
//copy all fields from intab1 into corresp. fields of wa_out_tab

select * from tab3 into intab3 where f3 eq wa_intab-f3.

..
//copy all fields from intab1 into corresp. fields of wa_out_tab

select * from tab4 into intab4 where f4 eq wa_intab-f4.

..
//copy all fields from intab1 into corresp. fields of wa_out_tab

select * from tab5 into intab5 where f5 eq wa_intab-f5.
//copy all fields from intab1 into corresp. fields of wa_out_tab


append wa_out_tab to out_tab


endloop.



My problem is that i cannot find a way to removed the numerous select statements within the loop.

Please Help.

Best Regards,

Mazin