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

about mest loop

Former Member
0 Likes
809

hi forks,

i have some doubts about the nest loop

when i write the code in this type

loop at itab1 into lfc_itab1.

loop at itab2 into lfc_itab2 where k1 = lfc_itab1-k1.

......

endloop.

endloop.

but my leader told me to write in this way

sort itab2 by k1 ascending.

loop at itab1 into lfc_itab1.

read table itab2 with key k1 = lfc_itab1-k1 binary seach.

li_tabix = sy-tabix.

loop at itab2 form li_tabix.

if lfc_itab1-k1 = lfc_itab2-k1.

endif.

endloop.

endloop.

i also agree with what he said,but i write test code

it return the opposite result .i use record (100100,10001000,10000*10000)

dose anyone tell which will be better

thanks in advance

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
683

Hi,

In ur case second logic is better , first one is call as LINEAR SEARCH and asecond one is called as BINARY SEARCH.

in LINEAR search ALL entries of itab are processed where as in Binary search entries processaed are logrihtm in no.

Binary serach is like getting desired page in a book using index, say if u want to search 41st page in 100 page book so in binary seach, if u opeend first time at 50 then it will search first half only, in second pas if u opened 30 page then it iwll search second half and so on...

Jogdand M B

3 REPLIES 3
Read only

Former Member
0 Likes
683

Can u send me the full code..

2 logic is better than 1st logic

Read only

Former Member
0 Likes
684

Hi,

In ur case second logic is better , first one is call as LINEAR SEARCH and asecond one is called as BINARY SEARCH.

in LINEAR search ALL entries of itab are processed where as in Binary search entries processaed are logrihtm in no.

Binary serach is like getting desired page in a book using index, say if u want to search 41st page in 100 page book so in binary seach, if u opeend first time at 50 then it will search first half only, in second pas if u opened 30 page then it iwll search second half and so on...

Jogdand M B

Read only

Former Member
0 Likes
683

The second logic is better, but still has problems. Check:

/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops

You need to exit the inner loop if the keys are not equal.

Rob