-3

I'm looking for an explanation of the concept of binary search in SAP. If my table has duplicates, how the search is done?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48

2 Answers2

2

Assuming that you have already read the extensive article on binary search as well as the ABAP documentation, you will probably have overlooked the following paragraph:

If there are multiple hits (due to an incomplete search key or duplicate entries in the table), binary searches (using the BINARY SEARCH addition in standard tables; automatic in sorted tables) also return the first hit in accordance with the order of the rows in the primary index. This is the row with the lowest row number.

vwegert
  • 18,371
  • 3
  • 37
  • 55
  • Yes i know that in case of duplicate it return the row with the lowest row number. But can u give me the algorithm?? – Amedeo Sookaloo Aug 30 '12 at 09:20
  • 1
    I have to correct myself - you didn't even attempt to read the Wikipedia article, did you? It's right there in the first paragraph. – vwegert Aug 30 '12 at 10:39
  • I have read the article and i know how it works in general.But can you give me the Binary search Algorithm of ABAP? – Amedeo Sookaloo Aug 30 '12 at 11:27
  • 3
    I don't understand your question. The algorithm isn't specific to the implementation, so there is no "ABAP binary search" as opposed to "C binary search" or "Java binary search". If you want to know how to use the built-in ABAP facilities, READ THE ABAP DOCUMENTATION. If you want to know how to implement binary search for yourself, READ THE WIKIPEDIA ENTRY and use basic ABAP skills. (Although any attempt to try would be a waste of time.) If you want to know how ABAP performs binary searches internally, ask the kernel developers - although I doubt you'll get an answer. – vwegert Aug 30 '12 at 11:39
0

I believe that the binary search in abap works like the normal binary search algorithm, but after it finds a record that matches the key, it goes up the table by index until the key is different. After that if returns the first hit in the table that matches your key.

alex
  • 1