Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Read Itab binary search not working.

Former Member
0 Kudos
4,334

Hi,

I have the following issue:

From a table, I am picking up 5 fields into an internal table (in the correct sequence):

A B C D E.

Now, I am sorting the above internal table as follows:

sort itab by A B C descnding.

Now, I am writing the read stmt as follows:

read table itab into wa_itab with key

A = var1

B = var2

C = car3

Binary Search.

But, the read fails in most of the cases even though the exact values exist in the itab. It does not fail always, but fails for majority of the cases, though the exact matches are present in the itab.

If I remove the Binary Search option, it works fine.

Could you please let me know if I am missing out on anything here?

Please let me know if any more information is needed.

Thank You,

Anjana Banerjee

1 ACCEPTED SOLUTION

Former Member
0 Kudos
812

Sort in Descending order does not give the correct results when using read with binary search. You need to sort it in the ASCENDING order to use binary search.

3 REPLIES 3

kesavadas_thekkillath
Active Contributor
0 Kudos
812

I remember in one of the thread Thomas Zloch saying that binary search must be sorted in ascending order.

Its correct the binary search algorithm divides the data into segements and searched from left to right. If its in descending order your binary search will fail in the first rule itself. ( Remember the traversal is always left to tight )

Former Member
0 Kudos
813

Sort in Descending order does not give the correct results when using read with binary search. You need to sort it in the ASCENDING order to use binary search.

Clemenss
Active Contributor
0 Kudos
812

Hi anjana,

please do not ask questions before reading the online help:

["The standard table must be sorted in ascending order by the specified search key. "|http://help.sap.com/saphelp_nw73/helpdata/en/fc/eb373d358411d1829f0000e829fbfe/frameset.htm]

Regards,

Clemens