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

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

Hi,

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 = ...

works correctly.

Why? Could not explain from documentation.

Please explain, thanks.

Regards

Clemens

replied

Clemens,

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.

Regards,

Naimesh Patel

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