read table with key ... binary search - key sequence?!
consider this scenario:
data: lt_mbew type table of mbew. field-symbols: <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 = ...
Why? Could not explain from documentation.
Please explain, thanks.
Naimesh Patel replied
It is mentioned in the READ Table Documentation, found here: http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb373d358411d1829f0000e829fbfe/frameset.htm
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.