09-22-2008 9:11 AM
Hi,
I have an internal table itab on which I am using READ inside a loop. The READ on itab is being used multiple times inside the loop with different keys.
I have sorted itab with 3 keys before the loop. In one of the READs I am using all the 3 keys but in another READ I am using first 2 keys only.
So is the code fine with BINARY SEARCH on these READs cos I have sorted with 3 keys but Reading with 2 keys in some places.
Please let me know your suggestions.
Thanks,
Abhishek
09-22-2008 9:30 AM
Yes it will work if you have exactly don what you have said. it will not work if you READ with 2nd and 3rd key.
09-22-2008 9:13 AM
Always use READ statement with Binary Search to avoid performance issues.
Thanks
Sudharshan
09-22-2008 9:16 AM
>
> Please let me know your suggestions.
> Abhishek
What Suggestions you need?
I don't think you asked anything in your question.
09-22-2008 9:19 AM
I want to know that if I sort an internal table with 3 keys but in the READ I use the first 2 keys then is it fine to BINARY SEARCH in this READ or not as I dont have the full keys in READ as in the SORT.
Thanks,
Abhishek
09-22-2008 9:25 AM
You don't need to add BINARY SEARCH to your READ statement when working with a sorted table and read WITH TABLE KEY. It's always an implicit binary search.
If you use the first two fields of a three field table key, performance should be OK. You might not get a unique entry though with READ, so maybe a LOOP AT ... WHERE would be better here?
Thomas
09-22-2008 9:17 AM
hi,
binary search is pre requisit for read.
check this,
http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb373d358411d1829f0000e829fbfe/content.htm
Regards,
Anirban
09-22-2008 9:19 AM
Hi,
This is because when you have sorted the table with 3 keys and using binary search reading with two fields...it might show abnormal results.
Thus before reading the table with two keys ..sort the table with same two keys.
Thanks,
Parul.
09-22-2008 9:22 AM
Hi,
What are the fields that you are using in Read table WITH KEY, the internal table must be sorted with those KEY fields first. If you want to use multiple Read table statements and each time you need to read it by different keys, then make temporary tables of same type and pass the data to those new internal tables then sort those with keys and use those tables in the loop statement..
Rgds,
Bujji
09-22-2008 9:30 AM
Yes it will work if you have exactly don what you have said. it will not work if you READ with 2nd and 3rd key.
09-22-2008 9:32 AM
Hi,
For the binary search, the table must be sorted by the specified search key in ascending order. Otherwise the search will not find the correct row.
09-22-2008 9:53 AM
I don't know whu i couldn't edit my previous post...so I'am posting again.
Try to visualize the binary search algorithm then it will be clear to you that this will work.
09-24-2008 5:46 AM
Hello Abishek,
Sorting with three fields and reading with first two fields using binary search will work very much fine.
Regards
Farzan
09-24-2008 5:59 AM
Hi,
Remember always use the same keys in sorting whenever you are using binary search else reduce performance & data may erronous.
Thanks,
Krishna...
09-24-2008 11:06 AM
no problem searching with 2 keys. you will only get 1 record where there is the possibility that more records meet your search-values. But that is also possible with 3 keys if they do not uniquely identify each record.
Regards,
Guido