2008 Mar 27 8:03 AM
Hello experts:
Thank you in advance for all your replies.
READ TABLE VALUE WITH KEY KONPKEY BINARY SEARCH.
how does this statement work? would you please explain it with an example? cheers
couldn't thank you more.
Best regards.
Frank
2008 Mar 27 8:15 AM
Hello,
Make sure that the internal table that is used for READ statement should be sorted(either manually using SORT statement or using a SORTED internal table declaration)
Suppose there are values in internal table itab like
1
2
3
4
5
6
7
Here When u use READ TABLE itab WITH KEY (fieldname) = ' value ' BINARY SERACH.
It finds out which is the lowest and highest value ie low = 1 and high = 7.
Now it finds the middle value low + high / 2 ie 1 + 7 / 2 = 4
Then it checks IF mid > value
then it returns values 1 2 3 (hope u got it)
elseif mid < value.
then it returns values 5 6 7
elseif mid = value.
then it returns 4
endif.
it works as the same n required times
Hope this helps.
Neeraj
Hello experts:
Thank you in advance for all your replies.
READ TABLE VALUE WITH KEY KONPKEY BINARY SEARCH.
how does this statement work? would you please explain it with an example? cheers
couldn't thank you more.
Best regards.
Frank
2008 Mar 27 8:06 AM
2008 Mar 27 8:15 AM
Hello,
Make sure that the internal table that is used for READ statement should be sorted(either manually using SORT statement or using a SORTED internal table declaration)
Suppose there are values in internal table itab like
1
2
3
4
5
6
7
Here When u use READ TABLE itab WITH KEY (fieldname) = ' value ' BINARY SERACH.
It finds out which is the lowest and highest value ie low = 1 and high = 7.
Now it finds the middle value low + high / 2 ie 1 + 7 / 2 = 4
Then it checks IF mid > value
then it returns values 1 2 3 (hope u got it)
elseif mid < value.
then it returns values 5 6 7
elseif mid = value.
then it returns 4
endif.
it works as the same n required times
Hope this helps.
Neeraj
2008 Mar 27 8:16 AM
Hi,
For example in your internal table you have 100 records.You want to Read 80th record.
READ TABLE ITAB WITH KEY num = '80' BINARY SEARCH.
Instead of searching till 80th record,First system will divide the reocrds half .
means 1- 50 and 51-100. Now system will compare the records
80 will be in between the 51-100.Again sytem wil divide the records half. 51-75 and 76-100.
Again system will divide the records again half 76-88 and 89 to 100.
Like that it will check with the number(80) .So searchnig will be fast.
NOTE. For correct result you have sort the internal table .Othewise you will get wrong result
2008 Mar 27 8:17 AM
the command binary search will work if the no of records is very huge ...
it will read the value with the key value ...if it had 1000000 records if it is binary search in the first hit it checks in the first 50000 and if it is not available again it will search in the next 25000 records if it is not available in the next hit it will search in the next 12500 it is not available it will search in the next 6250 ..like this ..with in the 10 hits or just more it will catch the cxact record...it will improve the performance time of the program..
regards,
venkat.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |