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

about search

Former Member
0 Likes
575

how to use binary search after read statement.

how to use binary search after read statement.

4 REPLIES 4
Read only

gopi_narendra
Active Contributor
0 Likes
551

sort itab1 by field.
sort itab by field.
loop at itab1.
  read table itab with key field = itab1-field binary search. " Binary Search
    if sy-subrc = 0.
      <do ur requirement>
    endif.
  clear : itab, itab1.
endlooop.

Regards

Gopi

Read only

Former Member
0 Likes
551

Hi,

Prior to using Binary search , it is mandatory to SORT the table by the field u r going to use in BInary Search , then use Binary SEARCH.

Ex:

Sort itab1 by f1.

loop at itab2 into w_itab2.

read table itab1 into w_itab1 with key f1 = w_itab2-f1 Binary search.

if sy-subrc = 0.

........

......

endif.

Revert back if any issues,

Reward with poinst if helpful.

Regards,

Naveen

Message was edited by:

Naveen Deva

Read only

Former Member
0 Likes
551

Hi,

BINARY SEARCH is a component of the READ statement. You could use like this way:

READ TABLE t_table

INTO wa_table

WITH KEY ebeln = p_ebeln

BINARY SEARCH.

But the table t_table should be sorted first using SORT t_table BY field... command.

For a sorted table, you could use binary search by using WITH TABLE KEY as below:

READ TABLE t_table

INTO wa_table

WITH TABLE KEY ebeln = p_ebeln.

t_table is declared as:

DATA t_table TYPE SORTED TABLE OF structure WITH NON-UNIQUE KEY ebeln.

Read only

Former Member
0 Likes
551

Hi Anshu,

It becomes very necessary and important to do a binary search after read statement. The search for the record required needs to be quickly found and is done through the binary search.

But remember to sort the internal table before you binary search as the internal table first needs to be sorted.

read table inttab with key field = inttab1 binary search.

Hope this solves your query.

Reward points if useful.

Thanks,

Tejus.