Application Development and Automation 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: 
Read only

Performance improvement inside the loop

Former Member
0 Likes
2,028

Hi Experts,

I have to do the performance tuning of the program.

I have inside the loop 2 select statement.

Loop at itab.

select single servorder from vbak into table itab1 where vbeln eq itab-vbeln.

if sy-subrc eq 0.

select single * from zzsdflightinfo into table it_flightinfo where zzservorder eq itab1-vbeln.

endloop.

what i have done is the taken 2 select statement out side the loop and used for all entries statement and using read table

inside the loop, i have read the data.

Can any one this way we can do best performannce improvement or any other method is there for above code

Regards,

Udupi

11 REPLIES 11
Read only

Former Member
0 Likes
1,586

Hi,

One request from my side,

Don't use select statement inside loop.

If your client side, they will send you out.

Remove that one.

Rearrange your program.

Regards,

vijay

Read only

0 Likes
1,586

Hi Vijay,

Thanks for your reply.

Program written long before.

requirement come to us to tuning.. thats what i told, i have taken out select statement from loop and used for all entries and used inside reaad statement. this is best way to performaance.

Read only

0 Likes
1,586

Hi ,

You have to do like this only by using for all entries.but if you need to call loop inside the loop only means first select the entries outside the loop and use the Parallel cursor method.

Best way is select all the entries from outside of the loop using for all entries and use read statement to read the entries inside the loop with binary search .

Thanks

Mani

Read only

0 Likes
1,586

Hi,

very good.

Try to use always read statement and provide statement.

try to avoid loop inside loop as much as possible.

If your using for HR module, use LDB.

Regards,

vijay

Read only

Former Member
0 Likes
1,586

Thanks for all reply.

I have writen like this

if not itab[] is initial.

select vbeln zzservord into table it_vbak from vbak

for all entries in itab where vbeln eq itaab-vbeln.

endif.

if it_vbak[] is not initital.

select * from zzsdflight into table it_flightinfo w

for all entries in it_vbak

where zzservorder eqq it_flightinfo-zzservorder.

endif.

loop at itab.

read table it_vbak with key vbeln eq it_vbak-vbeln.

if sy-subrc eq 0.

read table it_flightinf with key zzservorder eq it_vbak-zzserovrder

if subrc eq 0.

endif.

endif.

any suggestion to improve performaance in this.

Regards,

udupi

Read only

0 Likes
1,586

Hi,

Use binary search in read statement. before that sort both internal tables followed by key fields.

Thank you.

Regards,

Balaji.

Read only

0 Likes
1,586

Hi,

In addition to this Befor reading the Tables in the loop SORT the internal tables by Key and use the Binary search addition to your READ statement if your internal table is a standard internal table .this will increase your program perfromance more.

Thanks

Mani

Read only

0 Likes
1,586

Hi abap udupi,

   

1.  first sort itab[].

if sy-subrc eq 0.

sort itab[] by vbeln.

endif.

2. then need to delete duplicate entries.

    delete adjacent duplicates from itab[] comparing vbeln.

3. need to delete all blank joining fields.

    delete itab[] where vbeln eq space.

when use read table statement use binary search. but before use it sort it_vbak by vbeln.

loop at itab.

sort it_vbak by vbeln.

read table it_vbak into wa_vbak with key vbeln eq itab-vbeln.

follow it......it will be helpful to you...this is the best performance tuning

Read only

Former Member
0 Likes
1,586

Hello ABAP Udupi,

U'r code above looks just fine. Try using EPC check and Sql Trace after activating u'r program.

You can consider following points to tune performance when working with a loop.

1. Sort the Tables based on key fields using " BY " keyword.

2. Use Read table statements within the loop based on binary key search.

3. Use Parallel cursor processing Technique when using Loop within a Loop.

4. Clear the work area after Endloop.

Plz reward points if it helps.

Thanks

Vivek

.

Read only

0 Likes
1,586

Just some additions to Vivek's answers.

1. You can use internal table of TYPE SORTED TABLE OF(saves the sort statement) with UNIQUE/NON-UNIQUE KEY keyyy(the value on which you are retrieving data)

2. You can use loop with where clause for nested loops. Else if data is huge, you can use parallel cursor also. Both of them work efficiently.

3. Clear the work areas just before endloop.

Read only

0 Likes
1,586

And still some millisecs to gain:

If you don't need them, don't read them.

Your read statement should explicitly state, which fields you need to know by adding

... transporting f1 f2 f3.

Even faster, use field-symbols instead of workarea. But beware of unintentional changes.

read table .... assigning <fs>.

Every memory transport consumes time.

Regards

Jörg