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

Former Member
0 Likes
586

Hi

How to do binary search while doing record retirieval?

What is the code need to be written for tht?

1 ACCEPTED SOLUTION
Read only

former_member188770
Active Participant
0 Likes
555

Hi ,

Please see the below code

READ TABLE ITAB INTO WA

WITH KEY K = 'X'

BINARY SEARCH.

The table should be of type sorted table or Oder the table and then use the Binary search.

Thanks,

Poonam.

4 REPLIES 4
Read only

former_member188770
Active Participant
0 Likes
556

Hi ,

Please see the below code

READ TABLE ITAB INTO WA

WITH KEY K = 'X'

BINARY SEARCH.

The table should be of type sorted table or Oder the table and then use the Binary search.

Thanks,

Poonam.

Read only

Former Member
0 Likes
555

Hi Jeeva Anto,

Here is the code of using binary search:

data:

begin of i_table oocurs 0,

var1 type i,

var2(10) type c,

end of i_table.

Let i_table have some random data.

First sort the table.

Sort i_table by var1.

Read table i_table with key var1 = 10 binary search.

if sy-subrc eq 0." If search is found

" Do your oprations here using i_table header

endif.

Hope this helps you definitely.

Regards,

Rama chary.Pammi

Read only

0 Likes
555

Hi

Thx....

Read only

Former Member
0 Likes
555

thx