2006 Nov 29 2:09 PM
Hi all,
when I was reading an internal table with binary search I was not getting proper results but when I was reading internable without binary search means I was getting perfect results .What might be the reason.
Thanks,
Balaji.
2006 Nov 29 2:10 PM
A pre-requisite to use binary search is that you should have sorted the table by the field with which you are searching.
Have you done that.
Regards,
Ravi
Note - Please mark all the helpful answers
2006 Nov 29 2:11 PM
Hi Balaji,
Sort the internal table, before you use the binary search.
sort itab by key1.
read table itab with key key1 = value1 binary search.
Hope this helps.
2006 Nov 29 2:12 PM
Hi Balaji,
Before read the internal table you have to sort the internal table what you are reading for example
SORT IT_EKKO BY EBELN.
READ TABLE IT_EKKO WITH KEY EBELN = IT_EKPO-EBELN BINARY SEARCH.
Thanks
Vikranth Khimavath
Message was edited by:
Khimavath Vikranth
2006 Nov 29 2:13 PM
hi Balaji,
Check
http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb373d358411d1829f0000e829fbfe/frameset.htm
Regards,
Santosh
2006 Nov 29 2:13 PM
HI,
Sort the internal table on the key always before using binary search.
Sort itab by key1.
read table itab with key1 = value binary earch.
Hope this helps.
2006 Nov 29 2:13 PM
Hi Balaji,
You need to SORT the internal table with the field you are using in BINARY SEARCH.
SORT ITAB BY MATNR.
READ TABLE ITAB WITH KEY MATNTR = <VALUE> BINARY SEARCH.
Thanks,
Vinay
2006 Nov 29 2:15 PM
Hi
You internal table should be sorted by the key (all the fields in WITH KEY) what you are using for READ. Use the fields in <b>Order</b> in both the places.
Regards
Surya.
2006 Nov 29 2:24 PM
Hi,
It is required to sort the internal table by the fields that you are using to read the table.
If you want to read table t_itab with vbeln and posnr and use binary search then you need to sort
t_itab by vbeln posnr.
read table t_itab into wa_itab with key vbeln = <sales order>
posnr = <item >
binary search.
If the table is sorted then only binary search works else not..
Hope this makes it clear.
Regards,
Shahu
2006 Nov 29 4:45 PM
Hi all,
thanks for all your replies.I sorted the internal table as u all said.Suppose I have three fields field1,field2,field3 in the internal table itab.I am sorting using only field1 and field2 but not field3.I am reading the internal table with all the three fields.In this scenarion I am using binary search .But the results are not perfect .The results are perfect in the absence of binary search in this scenario.
So do I need to sort all the three fields field1,field2,field3 to get correct results.
Thanks,
Balaji
2006 Nov 29 4:47 PM
2024 May 23 10:40 AM
Hello,
sort your internal table.
SORT itab BY EBELN.
LOOP AT itab2 ASSIGNING FIELD-SYMBOL(<WA_ITM>).
READ TABLE itab INTO DATA(WA) WITH KEY EBELN = <WA_ITM>-ebeln BINARY SEARCH.
endloop.