‎2008 Jun 25 3:54 PM
Hi,
I want to use binary search in my code, just not sure, how to do it right.
Let's say I have an IT with columns A B C D.
I want to search this table first based on value in A and later based on B.
How should I sort this table?
>sort IT by A B
>read table with key A = '1' binary search
>read table with key B = 'X' binary search
or
>sort IT by A
>read table with key A = '1' binary search
>sort IT by B
>read table with key A = 'X' binary search
?
What happens, if I sort this table by A and let the system search based on value in B?
Thank you,
Olian
‎2008 Jun 25 4:07 PM
‎2008 Jun 25 3:58 PM
Olien,
prefer SAP help by just pressing F1 in binary search.
may we somtimes wrong but SAP never.
Amit.
‎2008 Jun 25 4:03 PM
If you are in a loop with these searches you can better make copies of the IT for each sortfield
ITA[] = IT[].
sort ita by A.
read table with key A = '1' binary search
ITB[] = IT[].
sort itb by B.
read table with key B = 'X' binary search.
‎2008 Jun 25 4:05 PM
>
>sort IT by A
>read table with key A = '1' binary search
>sort IT by B
>read table with key B = 'X' binary search
That is the way to go (I corrected the typo).
Binary search is only effective when the table is sorted by the search fields. It only makes sense though if you perform multiple reads after sorting (e.g. inside a loop), since sorting itself costs some processing time.
Thomas
‎2008 Jun 25 4:07 PM
‎2008 Jun 25 4:26 PM
ad you only have to add binary search when the amount of lines in the IT is for instance >10.000
for IT with lines between 0 and 1000 it is not really rewarding.
I had certainly improved some programs in performance with addind binary search to a IT with 30.000 lines which had to be looped through for 5000 times.
kind regards
arthur