Skip to Content

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

read table with key ... binary search - key sequence?!


consider this scenario:

  lt_mbew type table of mbew.
  <mbew>  type mbew.
select matnr bwkey stprs into corresponding fields of table  lt_mbew where ...
sort lt_mbew by matnr bwkey.
read table lt_mbew assigning <mbew>
  with key
    bwkey = ...
    matnr = ...

fails sometimes (sy-subrc = 4).

read table lt_mbew assigning <mbew>
  with key
    matnr = ...
    bwkey = ...

works correctly.

Why? Could not explain from documentation.

Please explain, thanks.





It is mentioned in the READ Table Documentation, found here:

The standard table must be sorted in ascending order by the specified search key. The BINARY SEARCH addition means that you can access an entry in a standard table by its key as quickly as you would be able to in a sorted table.

Since your Search Key is BWKEY and MATNR, your table must be sorted by BWKEY MATNR in this sequence.


Naimesh Patel

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question