2008 Jul 21 6:13 AM
2008 Jul 21 6:15 AM
hi,
SORT the table on the fields on Which you are going to Apply BINARY Search.
Regards
Sumit Agarwal
2008 Jul 21 6:33 AM
2008 Jul 21 6:16 AM
2008 Jul 21 6:16 AM
Hi Prabhakar,
First you search the SDN for such basic questions and even though you cannot find then post it.
Regards,
Chandra Sekhar
2008 Jul 21 6:17 AM
Hi,
Sorting the table is the prerequisite for the binary search.
Edited by: chandrika chireddy on Jul 21, 2008 7:17 AM
2008 Jul 21 6:18 AM
Hi,
I didn't get your query exactly..
If you want to sort through binary search then try this one..
READ TABLE WITH KEY BINARY SEARCH.
Example is shown below:
Field1 Field2
-
John 12345
Alice 23478
Sam 54321
john 50000
DATA: BEGIN OF ICODE OCCURS 0,
FIELD1(5),
FIELD2(5),
END OF ICODE.
READ TABLE ICODE WITH KEY FIELD1 = 'John' BINARY SEARCH.
2008 Jul 21 6:18 AM
Hi,
Sort the table by the key fields............
before performing a binary search...
2008 Jul 21 6:18 AM
Hi prabhakar,
If you read entries from standard tables using a key other than the default key, you can use a binary search instead of the normal linear search. To do this, include the addition BINARY SEARCH in the corresponding READ statements.
READ TABLE <itab> WITH KEY <k1> = <f1>... <kn> = <fn> <result>
BINARY SEARCH.
The standard table must be sorted in ascending order by the specified search key. The BINARY SEARCH addition means that you can access an entry in a standard table by its key as quickly as you would be able to in a sorted table.
Binary search repeatedly divides the search interval in half. If the value to be searched is less than the item in the middle of the interval, the search is narrowed to the lower half, otherwise the search is narrowed to the upper half.
one pre-requisite for binary search is that table has to be sorted in ascending order,
E.g.
say Itab[] has 5 entries.
10
20
30
40
50,
Now say you want to serach value 20.
Binary serach divides the sorted internal table into 2 halves 5/2 gives
1) 10
20
30
2) 40
50
Now it compares the value to be searched(i.e. 10) with last entry of the first half
if search value is less than last entry of first half it again performs this division on first half of the table.
else compares search value with first entry of 2nd half search value is greater or equal to first entry of second half it dividies the second half till the seasrch value is found.
Note: you cannot do binary search on tables sorted in descending order.
thnks
anurodh
2008 Jul 21 6:19 AM
hi,
sorting the elements or fields is a prerequisite for binary search..for more details you can log on to saptechnical.com
2008 Jul 21 6:21 AM
2008 Jul 21 6:32 AM
hi,
sorting the elements or fields is a prerequisite for binary search..for more details you can log on to saptechnical.com.
note:you cannot sort the elements in descending order in binary search