‎2006 Jan 23 10:30 PM
We have just updated our hardware to 64 bit. Now all of our programs that do a read with Binary search are failing that DON'T have a sort on them. Is anyone aware of any issues with this, and , should there always be a sort done before a read with Binary search?
Thanks
Mike
‎2006 Jan 23 10:35 PM
I think it just assumes the data is sorted correctly. If not it should just give a non-zero return code. What sort of failure are you getting?
And what release?
Rob
Message was edited by: Rob Burbank
‎2006 Jan 23 10:35 PM
I think it just assumes the data is sorted correctly. If not it should just give a non-zero return code. What sort of failure are you getting?
And what release?
Rob
Message was edited by: Rob Burbank
‎2006 Jan 24 12:54 AM
I am getting a sy-subrc = 4. The record I am trying to read is in the internal table, in debug, if I view the internal table it looks sorted. But it fails the read. When I put a sort statement in front of the read, sorting by the key I am reading, the program works.
‎2006 Jan 24 1:03 AM
Hi Michael,
PL sort the itab with key you are searching on ie
SORT <itab> BY <fld>.
READ TABLe <itab> with Key <fld> BINARY SEARCH.
SY-SUBRC = 4 means the required value was not found.
regards,
Suresh Datti
‎2006 Jan 24 2:02 AM
Well, it's odd that it just showed up after a hardware upgrade. I suppose that it's possible, that before the upgrade, the records were sorted correctly by some default routine that is not running now. The bottom line is that you're going to have to make sure the table is sorted.
Rob
‎2006 Jan 24 2:13 AM
when you say 'looks sorted' what do you mean?
What is the structure of your table?
For binary seacrh to 'work' the base table must be in the corect order but it doesn't actually have to have achieved this orderly state via a 'sort' command. It could, for example, have got that way from a select with an order by clause.
How are you populating your table? maybe the old release always happened to fill it in sequence but for some reason no longer does.
‎2006 Jan 24 4:04 AM
Hi Michael,
A Binary search is to be used only when the table is already sorted. When you read the SAP documentation, you will find out that the binary search simply assumes that the table you provide is already sorted.
If it is not sorted, like in your case, the search will not dump or anything. Only, it could fail.
I suggest you change the program to have the sort statement before the read statement. Or the other option is you can use a sorted table, so the contents will always be sorted based on the key you specify.
Hope this helps.
Rgds,
Prabhu.