‎2007 Sep 11 6:49 AM
Hi All,
I have one issue while using the read table .Iam using Read table with binary search .but even though there is matching key Sy-subrc is returning 4.Since I used the binary search there is no need of using sort table before read.
Can some one help me to solve this issue .
Thanks in Advance
-Padma
‎2007 Sep 11 6:51 AM
example
FETCHING NAME1
SELECT werks
name1
FROM t001w
INTO TABLE t_name1
FOR ALL ENTRIES IN t_itab1
WHERE werks = t_itab1-werks.
SORT t_itab1 BY werks.
SORT t_name1 BY werks.
IF sy-subrc = 0.
LOOP AT t_itab1 INTO wa_itab1.
hold_tabix = sy-tabix.
READ TABLE t_name1 INTO wa_name1 WITH KEY werks = wa_itab1-werks
BINARY SEARCH.
IF sy-subrc = 0.
wa_itab1-name1 = wa_name1-name1.
MODIFY t_itab1 INDEX hold_tabix FROM wa_itab1.
ENDIF.
‎2007 Sep 11 6:50 AM
‎2007 Sep 11 6:51 AM
Hi,
u need to sort the table before using BINARY SEARCH in the read statement.
cud u pls give us the code....
here is a sample:
sort i_final by BUKRS .
LOOP AT i_final INTO w_final.
READ TABLE i_output INTO w_output WITH KEY
bukrs = w_final-bukrs
BINARY SEARCH.
ENDLOOP.
Regards,
Anjali
‎2007 Sep 11 6:51 AM
HI,
You must sort the table with key which u r using in Read statement before using Binary search.
Regards,
Balavardhan.K
‎2007 Sep 11 6:51 AM
example
FETCHING NAME1
SELECT werks
name1
FROM t001w
INTO TABLE t_name1
FOR ALL ENTRIES IN t_itab1
WHERE werks = t_itab1-werks.
SORT t_itab1 BY werks.
SORT t_name1 BY werks.
IF sy-subrc = 0.
LOOP AT t_itab1 INTO wa_itab1.
hold_tabix = sy-tabix.
READ TABLE t_name1 INTO wa_name1 WITH KEY werks = wa_itab1-werks
BINARY SEARCH.
IF sy-subrc = 0.
wa_itab1-name1 = wa_name1-name1.
MODIFY t_itab1 INDEX hold_tabix FROM wa_itab1.
ENDIF.
‎2007 Sep 11 6:52 AM
HI,
SORTING IS A PRE REQUISIT FOR BINARY SEARCH. BEFORE REAT TABLE ST SORT UR INTERNAL TABLE WITH A KEY FIELD AND TRY.
WITH REGARDS,
SURESH ALURI.
‎2007 Sep 11 6:52 AM
‎2007 Sep 11 7:01 AM
‎2007 Sep 11 7:04 AM
Hi,
<u><b>Binary Search in Standard Tables</b></u>
If you read entries from standard tables using a key other than the default key, you
can use a binary search instead of the normal linear search. To do this, include the addition BINARY SEARCH in the corresponding READ statements.
READ TABLE <itab> WITH KEY = <f> <result> BINARY SEARCH.
and
READ TABLE <itab> WITH KEY <k1> = <f1> ... <kn> = <fn> <result>
BINARY SEARCH.
The standard table must be sorted in ascending order by the specified search key. The BINARY SEARCH addition means that you can access an entry in a standard table by its key as quickly as you would be able to in a sorted table.
Example
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 = 16 INTO LINE BINARY SEARCH.
WRITE: 'SY-SUBRC =', SY-SUBRC.
The output is:
SY-SUBRC = 0
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 16.
Regards,
Bhaskar