09-25-2008 2:43 PM
Hi All,
I have a requirement where I need to optimize the following code, it consists of the following format:
loop
select
select
endselect
select
endselect
if sy-subrc <> 0.
perform <<function module name>>
endselect
endloop
Following is the code:
-
loop at idtl.
refresh: ivbap,
ivbap2.
select obknr equnr sernr into (objk-obknr,objk-equnr,objk-sernr)
from objk where equnr eq idtl-equnr and
taser eq 'SER01' and
objvw eq 'S' and
sernr in s_sernr.
select lief_nr posnr into (ser01-lief_nr,ser01-posnr) from ser01
where obknr eq objk-obknr.
endselect.
if sy-subrc eq 0.
select vbelv posnv into (vbfa-vbelv,vbfa-posnv) from vbfa
where vbeln eq ser01-lief_nr and
posnn eq ser01-posnr and
vbtyp_v eq 'C'.
endselect.
if sy-subrc eq 0.
perform assign_component.
endif.
endif.
endselect.
endloop.
-
Please Help...
Thanks,
Vishal.
09-25-2008 2:46 PM
Hi,
Use
for all entries
option of the select stament.
Do this before the loop and inside the loop only read the record or if there are multiple entries for one enty , then loop.
regards,
Advait.
09-25-2008 2:46 PM
Hi,
Use
for all entries
option of the select stament.
Do this before the loop and inside the loop only read the record or if there are multiple entries for one enty , then loop.
regards,
Advait.
09-25-2008 2:47 PM
Instead of Select query inside LOOP, use FOR ALL ENTRIES in Select query.
09-25-2008 2:49 PM
Hi Vishal,
Instead using SELECT inside LOOP ....ENDLOOP, you can use FOR ALL ENTRIES in ITAB.
IF itab is not initial.
select obknr equnr sernr into table itab_objk
from objk where equnr eq itab-equnr and
taser eq 'SER01' and
objvw eq 'S' and
sernr in s_sernr.
endif.
Do all the select statement like the above.
I hope it will minimize the datbase load.
09-25-2008 2:52 PM
Write the all the select statements out side the loop
using 'for all entries'.
read the respective internal tables in the loop with appropriate
key using binary search.
09-25-2008 3:01 PM
hi it is better to use the for all entries...
here it is good if you use the select single statement.....
other wise use the for all entries statement ...and then use the read statement for this.
09-25-2008 3:07 PM
Throw away tables with header lines. Use standard tables and field symbols instead.
loop at itab assigning <p>.
This will avoid a lot of copying in memory.
10-03-2008 12:47 PM