01-10-2008 4:58 AM
Hi,
There are any chances that the Read statement with Binary search option to fail, even though the key exists??
Here the itab is sorted in descending order. and then some duplicates are removed using the delete adjacent statement.
Regards,
Sandhip.
01-10-2008 5:05 AM
Hi,
No it cannot fail unless there is no matching record.
Check ones again the record exist in both the tables( loop table and Read table).
revrt back if any issues
regards
Naveen
01-10-2008 5:28 AM
Hi Naveen,
One more clarification.. the order of sorting matters or not??
Regards,
Sandhip
01-10-2008 5:30 AM
Hi SANDY ,
The order of sorting does not matter .
Please check out how the Binary search technique works , so that you can understand it better.
Regards
Arun
01-10-2008 5:31 AM
Hi Sandy,
When u Binary Search with a Key make sure you have first sorted your internal table with the same Key.
Regards,
Sonal
01-10-2008 5:32 AM
No matter of sorting for Binary Search. If U sort ascending and ur value is in first half, the search moves to the top half of the records and if u sort in descending order, search moves to the last half and proceeds further.
awrd points if helpful
Bhupal
01-10-2008 5:08 AM
Hi,
And make sure the table is sorted by the same key which is used in the binary Search..
Regards,
Sonal
01-10-2008 5:10 AM
Hi sandy
There are no chances that a read statement fails because of binary search
The problem may come with With Key ... binary search is used to increase the searching process
Before using Binary search first sort your internal table
Donot forgot to reward points if helpful
Hitesh
01-10-2008 5:11 AM
Hi,
Check the following program:
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE STANDARD TABLE OF LINE.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
SORT ITAB BY COL2.
READ TABLE ITAB WITH KEY COL2 = 20 INTO LINE BINARY SEARCH.
WRITE: 'SY-SUBRC =', SY-SUBRC.
The program fills a standard table with a list of square numbers and sorts them into ascending order by field COL2. The READ statement uses a binary search to look for and find the line in the table where COL2 has the value 20. The sy-subrc is 8 because its fail.
Regards,
Bhaskar
01-10-2008 5:12 AM
Hi Sandy,
Table should be sorted in Ascending order
Also make sure Key for sort and binary search should be same.
Regards,
Mohaiyuddin
01-10-2008 5:30 AM
sort table by the same key with which the table is read.
regards,
kushagra
01-10-2008 5:34 AM
Hi,
Here is an example:
sort itab1 by a b c.
loop at itab2 into wa_itab2.
read table itab1 into wa_itab1
with key a = wa_itab2-a
b = wa_itab2-b
c = wa_itab2-c
binary search.
if sy-subrc = 0.
wa_output-a = wa_itab1-a.
endif.
endloop.
Another alternative is to use sorted tables.
Hope it helps...
P.S. Please award points if it helps...
01-10-2008 6:06 AM
Hi Sanddy,
In binary search the table entreis are divided into two equal parts and it will search for data in only one half depending on comparision of the middle value with value you entered.so for this searching type table must be sorted.
for any doubt plz reply.
With Regards.