Hi Expert!
I have declare a sorted type table with NON -UNIQUE, and want to use Binary search in read statement. But while using bunary search in read statement I'm facing an error. The ERROR is
"Table LI_MARC is a SORTED TABLE or INDEX TABLE. The BINARY SEARCH
addition is only allowed for these tables if the key specified is an
initial part of the table key."
Please find detail
TYES: tt_marc TYPE SORTED TABLE OF marc WITH NON-UNIQUE KEY matnr,werks.
DATA: li_marc type tt_marc.
READ TABLE li_marc INTO marc WITH KEY matnr = i_mbew-matnr
werks = i_mbew-bwkey BINARY SEARCH .
To my understanding , there is no need to mention Bianry Search for sorted table TYPE. Please let me know can i use ?
Hello,
there is no need to mention Bianry Search for sorted table TYPE.
Yes, this is because for SORTED TABLEs binary search algorithm is used by default for READ TABLE. Although you can use BINARY SEARCH addition but it's use is redundant.
As for your case you've defined the KEY fields incorrectly 😊 There shouldn't be any "comma(s)" between the fields.
TYPES: tt_marc TYPE SORTED TABLE OF marc WITH NON-UNIQUE KEY matnr werks.
When you define it with commas
TYPES: tt_marc TYPE SORTED TABLE OF marc WITH NON-UNIQUE KEY matnr, werks.
the result is something like this:
TYPES: tt_marc TYPE SORTED TABLE OF marc WITH NON-UNIQUE KEY matnr. TYPES: werks.
Hence you were getting the syntax error!
BR,
Suhas
PS: As for MARC you can use UNIQUE KEY addition because MATNR & WERKS are the key fields in the table.
Add a comment