Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Binary Search need clarification

Hi All,

I am facing a problem here in binary search. I will try to explain the situation with an example.

Internal table : it_vbap

Fields : vbeln posnr qty

Index 1 100 10 5

index 2 100 10 5

index 3 100 20 5

index 4 100 20 5

index 5 100 30 5

index 6 100 30 5

the abap code is this.

sort it_vbap by vbeln posnr.

read table it_vbap into ls_vbap with ket

vbeln = ls_vbap-vbeln

psonr = ls_vbap-posnr

binary search.

If sy-subrc = 0.

write : 'index :' sy-tabix.


My question here is does it always write index 1,3,5 (means in the all the case it should return the first record ), otherwise it can also return 1, 3, 6.

Pay attendtion the posnr are the same for every two records.

The internal table not only contains 6 six records , my question was however not depends on the number of records in the internal table, the binary search will return the first sorted key record in the table or not.

Please post your views.

Thanks & regards,


Former Member
Not what you were looking for? View more on this topic or Ask a question