Application Development 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: 

Binary Search

Former Member
0 Kudos

Hi

How to do binary search while doing record retirieval?

What is the code need to be written for tht?

1 ACCEPTED SOLUTION

former_member188770
Active Participant
0 Kudos

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

former_member188770
Active Participant
0 Kudos

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.

Former Member
0 Kudos

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

0 Kudos

Hi

Thx....

Former Member
0 Kudos

thx