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

Need to Optimize LOOP statement.

Former Member
0 Likes
2,737

Hi,

For Performance optimization I added READ with BINARY SEARCH instead SQL Query this part is working better.. But replacing SQL with LOOP ENDLOOP. is making the performance worse..

Below is the code for LOOP:

LOOP AT IT_OPS_BOM WHERE slot EQ zslot

AND zsku(11) EQ tmp_opsbom-zsku(11)

AND ZCOMP = ' '.

*Do some logic

ENDLOOP.

Can we do someting to Furthur optimize the LOOP.. ENDLOOP.. part?

No. of Records in IT_OPS_BOM is more than 2 Lac.

Thanks,

Preyansh

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,552

Hi Preyansh ,

If you want a loop..where...endloop structure to be optimized, explore the following possibilities:

1. Check if this table can be made as sorted with zslot, zsku, zcomp as the key. The condition here is that the table is initialized once and has little or no inserts.

2. sort the table by zslot, zsku, zcomp.

read table ...with key .... binary search.

if sy-subrc = 0.

l_index = sy-tabix.

endif.

loop at table from l_index.

if <zslot zsku zcomp> changing from the initial one, exit. endif.

.....

endloop.

Also, check if the offset in the where condition can be removed.

Hope this helps.

Regards

Hema

7 REPLIES 7
Read only

Former Member
0 Likes
1,553

Hi Preyansh ,

If you want a loop..where...endloop structure to be optimized, explore the following possibilities:

1. Check if this table can be made as sorted with zslot, zsku, zcomp as the key. The condition here is that the table is initialized once and has little or no inserts.

2. sort the table by zslot, zsku, zcomp.

read table ...with key .... binary search.

if sy-subrc = 0.

l_index = sy-tabix.

endif.

loop at table from l_index.

if <zslot zsku zcomp> changing from the initial one, exit. endif.

.....

endloop.

Also, check if the offset in the where condition can be removed.

Hope this helps.

Regards

Hema

Read only

0 Likes
1,552

Answered.

Thanks Hema.

Reply gave a good idea for implementing the optimization.

Regards,

Preyansh

Edited by: DWIVEDP on Jan 6, 2011 4:56 PM

Read only

0 Likes
1,552

Hi guys,

As your intention is restrict by these 3 fields and one of than is partial content I don't think the sort will help you a lot.

It's better to you have a new field zsku11 with this part first:

something like (my doubt here is if this overhead will have provide a effective solution as there's an implicit index reorganization):

LOOP AT IT_OPS_BOM ASSIGNING <fs_it_ops>.
  <fs_it_ops>-zsku11 = <fs_it_ops>-zsku(11).
ENDLOOP.

The table IT_OPS_BOM should be a sorted table by slot, zsku11 and zcomp.

So the LOOP will be optimized internally needing no special handling, you coding should be:

LOOP AT IT_OPS_BOM WHERE slot EQ zslot
AND zsku11 EQ tmp_opsbom-zsku(11)
AND ZCOMP = ' '.
*Do some logic
ENDLOOP.

Make sense you do this initial loop?

Is there another way to deal with this partial zsku? Maybe change the order to slot, zcomp and zsku with original suggestion sent by Hema should provide a good support.

Regards, Fernando Da Ros

Read only

0 Likes
1,552

I totally agree with you, Ros. This is what I meant by

Also, check if the offset in the where condition can be removed.

Thanks,

Hema

Read only

0 Likes
1,552

Hi Fernando,

It really made sence to optimize in described way.. my program is running much faster... Per feedback it got improved by 4 % extra. (My Other optimization brang the runtime by 35% less and now it is 39% lesser).

Thanks to Hema too. Her advice (2nd point which I understood) also brang 3% furthur optimization.. 32% to 35%)

Regards,

Preyansh

Read only

0 Likes
1,552

Hi Preyansh,

In fact Hema's and mine suggestions are the same in essence but different implementation.

Anyway, did you also tried to define the table as sorted on declaration?

If you did this you don't need the READ BINARY and the IF EXIT sequence inside the LOOP.

Regards, Fernando Da Ró

Read only

0 Likes
1,552

Hi Fernando,

No I didn't try with Sorted Table. Since I am reading the internal table with 3 Different combination at three places.

I am keeping the Interna table as standard table and SORTing it at 3 places with different fields.

Thanks,

Preyansh