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

Regarding LOOP - Endloop Performance

Former Member
0 Likes
1,126

Dear All ,

I am using below code in my prg..

loop at itab.

loop at itab1 where matnr = itab-matnr.

endloop.

endloop.

IN this code itab is having only 1 row for particular matnr and in itab1 is having multiple row for particular matnr. and i am facing here performance issue . it is taking so much time. Because for particular matnr , program have to search matnr in whole itab1. so is there any code line i have to use so it can search directly matnr from itab1 and dont need to search whole table.... because here if itab is having m row and itab1 is having n row , than looping is happened mn times..

so , how can i reduce it ? please anybody know , than please help me for same...

Thank You ,

1 ACCEPTED SOLUTION
Read only

ravi_lanjewar
Contributor
0 Likes
1,075

Hi,


loop at itab.
loop at itab1 where matnr = itab-matnr.

endloop.
endloop. 

 itab1 is having multiple row for particular matnr

define tab1 table as sorted table with non-unieque key matnr.

and also used the field-symbols instead of work area.


loop at itab Assigning <fs_itab>.
loop at itab1 assigning <fs_itab1> where matnr = <fs_itab>-matnr.

endloop.
endloop. 

Define

field-symboles <fs_itab> has type of itab table type.

<fs_itab1> has type of itab1 table type.

It will give better performance, Don't used the parallel cursor technique.

Try it it will resolve your problem

9 REPLIES 9
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,075

Hello

You should definitely have a look at the MUST read blog written by Rob Burbank:

[JOINS vs. FOR ALL ENTRIES - Which Performs Better?|https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/6050] [original link is broken] [original link is broken] [original link is broken];

Regards

Uwe

Read only

sarang_gujrati2
Explorer
0 Likes
1,075

hi,

u can use parallel cursor technique to improve performance .

sample code is like :

sort: lt_vbpa by kunnr, "Sorting by key is very important

lt_kna1 by kunnr. "Same key which is used for where condition is used here

loop at lt_vbpa into wa_vbpa.

read lt_kna1 into wa_kna1 " This sets the sy-tabix

with key kunnr = wa_vbpa-kunnr

binary search.

if sy-subrc = 0. "Does not enter the inner loop

v_kna1_index = sy-tabix.

loop at lt_kna1 into wa_kna1 from v_kna1_index. "Avoiding Where clause

if wa_kna1-kunnr <> wa_vbpa-kunnr. "This checks whether to exit out of loop

exit.

endif.

            • Your Actual logic within inner loop ******

endloop. "KNA1 Loop

endif.

endloop. " VBPA Loop

Regards,

Sarang

Read only

0 Likes
1,075

Hi Sarang

Thanks to give me sample code of parallel cursor technique..

Can u just what is meaning of binary search ? how it works ?

And here in your secong loop

loop at lt_kna1 into wa_kna1 from v_kna1_index.

if lt_konv is having multiples row for particular Kunnr.. than its read only 1 time than how it works ?

Read only

0 Likes
1,075

Can u just what is meaning of binary search ? how it works ?

Please understand binary search,sorted tables etc before getting into the coding

Hi,

You can search the documentations and read how the sorted tables work .

Let me explain how binary search works

consider the below entries in your internal table. You must

sort the internal table before doing a binary search.

You will know the importance of sorting when you understand the functionality.

This is just a rough explanation.Suppose you want to get the record

which holds the value 10, when you use a binary search.

the contents are divided into two segements like

1

2

6

7

***

9

10

13

17

18

It takes the left segement and does a left traversal, if the value is found its

returned else it takes the right segement and again divides it

like

9

10

***

13

17

18

It again does the same left traversal, here the data is found.it stops and exits.

Experts correct me if im wrong

Read only

0 Likes
1,075

Hi Keshav,

Thanks for your explanation......

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,075

Data:itab1 type sorted table of type1 with non-unique key matnr.

Just declare your matnr as above and use the same nested loop.

Read only

0 Likes
1,075

Hi ,

Keshav , thanks for reply...in your declaration what is meaning of type1.. And how it works can u explain in brief ?....

Read only

ravi_lanjewar
Contributor
0 Likes
1,076

Hi,


loop at itab.
loop at itab1 where matnr = itab-matnr.

endloop.
endloop. 

 itab1 is having multiple row for particular matnr

define tab1 table as sorted table with non-unieque key matnr.

and also used the field-symbols instead of work area.


loop at itab Assigning <fs_itab>.
loop at itab1 assigning <fs_itab1> where matnr = <fs_itab>-matnr.

endloop.
endloop. 

Define

field-symboles <fs_itab> has type of itab table type.

<fs_itab1> has type of itab1 table type.

It will give better performance, Don't used the parallel cursor technique.

Try it it will resolve your problem

Read only

0 Likes
1,075

Hi Ravishankar,

Thanks for ur help.. Its really works and easy than another method.......