Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BINARY SEARCH addition gives an error message

Former Member
0 Likes
2,861

Hi. My codes below (which uses BINARY SEARCH) gives an error message.

Any idea why? thanks.

Error Message: The addition "BINARY SEARCH" cannot be used with index access or general tab search.

**********************************************************

REPORT ZKK_BINARY_SEARCH.

TABLES: ZSCSDM_ED.

DATA: ITAB_VAL TYPE TABLE OF ZDM_A_CC01 WITH HEADER LINE.

DATA: ITAB_ERR TYPE TABLE OF ZSCSDM_ED WITH HEADER LINE.

SELECT * INTO CORRESPONDING FIELDS OF TABLE ITAB_VAL FROM ZDM_A_CC01

WHERE LOAD_ID = 000045 AND USER_STATUS <> 'D'.

TABLES: T005 .

DATA: BEGIN OF ITAB_REF0011_LINE,

LAND1 TYPE T005-LAND1,

END OF ITAB_REF0011_LINE.

DATA: ITAB_REF0011 LIKE TABLE OF ITAB_REF0011_LINE WITH HEADER LINE.

SELECT LAND1 FROM T005

INTO CORRESPONDING FIELDS OF TABLE ITAB_REF0011.

LOOP AT ITAB_VAL.

DATA: TEMP LIKE LINE OF ITAB_REF0011.

SORT ITAB_REF0011.

READ TABLE ITAB_REF0011 WITH TABLE KEY

LAND1 = ITAB_VAL-ABTEI

BINARY SEARCH.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,663

SORT ITAB_REF0011 by LAND1. " Sort the table by LAND1
LOOP AT ITAB_VAL.
DATA: TEMP LIKE LINE OF ITAB_REF0011.
SORT ITAB_REF0011.
READ TABLE ITAB_REF0011 WITH KEY " Changed WITH TABLE to WITH KEY
LAND1 = ITAB_VAL-ABTEI
BINARY SEARCH.
ENDLOOP.

Hi. My codes below (which uses BINARY SEARCH) gives an error message.

Any idea why? thanks.

Error Message: The addition "BINARY SEARCH" cannot be used with index access or general tab search.

**********************************************************

REPORT ZKK_BINARY_SEARCH.

TABLES: ZSCSDM_ED.

DATA: ITAB_VAL TYPE TABLE OF ZDM_A_CC01 WITH HEADER LINE.

DATA: ITAB_ERR TYPE TABLE OF ZSCSDM_ED WITH HEADER LINE.

SELECT * INTO CORRESPONDING FIELDS OF TABLE ITAB_VAL FROM ZDM_A_CC01

WHERE LOAD_ID = 000045 AND USER_STATUS <> 'D'.

TABLES: T005 .

DATA: BEGIN OF ITAB_REF0011_LINE,

LAND1 TYPE T005-LAND1,

END OF ITAB_REF0011_LINE.

DATA: ITAB_REF0011 LIKE TABLE OF ITAB_REF0011_LINE WITH HEADER LINE.

SELECT LAND1 FROM T005

INTO CORRESPONDING FIELDS OF TABLE ITAB_REF0011.

LOOP AT ITAB_VAL.

DATA: TEMP LIKE LINE OF ITAB_REF0011.

SORT ITAB_REF0011.

READ TABLE ITAB_REF0011 WITH TABLE KEY

LAND1 = ITAB_VAL-ABTEI

BINARY SEARCH.

ENDLOOP.

7 REPLIES 7
Read only

Former Member
0 Likes
1,663

Hi

READ TABLE ITAB_REF0011 WITH KEY

LAND1 = ITAB_VAL-ABTEI

BINARY SEARCH.

use this

if it is table key then it wil be unique so need of searching

regards,

Venkatesh

Read only

Former Member
0 Likes
1,664

SORT ITAB_REF0011 by LAND1. " Sort the table by LAND1
LOOP AT ITAB_VAL.
DATA: TEMP LIKE LINE OF ITAB_REF0011.
SORT ITAB_REF0011.
READ TABLE ITAB_REF0011 WITH KEY " Changed WITH TABLE to WITH KEY
LAND1 = ITAB_VAL-ABTEI
BINARY SEARCH.
ENDLOOP.
Read only

0 Likes
1,663

Hi all, thanks for the help. really appreciate it.

Another question is, if we use BINARY SEARCH on an internal table, do we have to sort the internal table first?

Read only

Former Member
0 Likes
1,663

read table should have INTO.

because u have to retrieve the information into any variable then only it will work

Read only

Former Member
0 Likes
1,663

Hi,

If you dont want to retrive data

just use transporting no-fields.

in additions

now you can check the sy-subrc .

Regards,

siva

Read only

Former Member
0 Likes
1,663

yes,

u need to sort based on the fields that u are using in read statement, else the result need not be accurate

Read only

Former Member
0 Likes
1,663

yes it's compulsary if u want to use binary search u should use sort before using read statement.

read statement must have into ,

u just check it out