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

Reg : Read statement using Binary Search....

Former Member
0 Likes
674

I have an Internal Table as below

Value Description

100 Product

2008 Production Year

05 Production Month

I am using Read statement with Binary Search for getting Production Month.

Read table itab with key Description = 'Production Month' binary search.

I am getting sy-subrc as 4 eventhough data is present in the table for Production Month.

What may be the problem.

1 ACCEPTED SOLUTION
Read only

vimalv
Active Participant
0 Likes
607

You have to sort the table by the KEY before using BINARY SEARCH.

say ur internal table is ITAB and you want to search with key PDATE,

then do SORT ITAB by PDATE.

then do.. READ TABLE ITAB .. WITH KEY PDATE = ... BINARY SEARCH.

4 REPLIES 4
Read only

vimalv
Active Participant
0 Likes
608

You have to sort the table by the KEY before using BINARY SEARCH.

say ur internal table is ITAB and you want to search with key PDATE,

then do SORT ITAB by PDATE.

then do.. READ TABLE ITAB .. WITH KEY PDATE = ... BINARY SEARCH.

Read only

former_member585060
Active Contributor
0 Likes
607

Hi,

First Sort the itab with Description field, then use the READ statement,

For BINARY SEARCH to be used, we have to sort the internal table before with the order of WHERE clause in READ statement.

Regards

Bala Krishna

Read only

Former Member
0 Likes
607

SORT internal table before you use BINARY SEARCH is the thumb rule.

Thanks

Kiran

Read only

Former Member
0 Likes
607

Hi suganya,

use

sort table itab ascending by <production month>.

Read table itab with key description = <production month> binary search.

Remember always, while using binary search always sort the internal table.

Regards,

Sakthi.