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: 

Optimizing an ABAP program...

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

7 REPLIES 7

Former Member
0 Kudos

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.

Former Member
0 Kudos

Instead of Select query inside LOOP, use FOR ALL ENTRIES in Select query.

Former Member
0 Kudos

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.

subbarao_ilam
Explorer
0 Kudos

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.

former_member203501
Active Contributor
0 Kudos

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.

rainer_hbenthal
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

optimized