2007 Aug 14 4:42 AM
how to use binary search after read statement.
2007 Aug 14 4:47 AM
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
2007 Aug 14 4:47 AM
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
2007 Aug 14 4:48 AM
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.
2007 Aug 14 4:51 AM
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.