‎2007 Jun 11 8:08 AM
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
‎2007 Jun 11 12:46 PM
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
‎2007 Jun 11 8:39 AM
Can u send me the full code..
2 logic is better than 1st logic
‎2007 Jun 11 12:46 PM
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
‎2007 Jun 11 2:43 PM
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