‎2013 Jan 19 6:00 AM
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
‎2013 Jan 19 6:03 AM
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
‎2013 Jan 19 6:07 AM
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.
‎2013 Jan 19 6:14 AM
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
‎2013 Jan 19 6:26 AM
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
‎2013 Jan 19 7:32 AM
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
‎2013 Jan 19 7:39 AM
Hi,
Use binary search in read statement. before that sort both internal tables followed by key fields.
Thank you.
Regards,
Balaji.
‎2013 Jan 19 7:41 AM
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
‎2013 Jan 19 7:51 AM
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
‎2013 Jan 19 7:53 AM
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
.
‎2013 Jan 19 9:38 AM
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.
‎2013 Jan 21 10:46 AM
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