2010 Apr 06 4:03 AM
Hi,
I want to use the binary search in below Read please give me solution....
LOOP AT it_vbfa_temp ASSIGNING <fs_vbfa_temp>.
CLEAR is_ekbz1.
READ TABLE it_ekbz1 INTO is_ekbz1 WITH KEY xblnr = <fs_vbfa_temp>-deliv flag = space.
IF sy-subrc = 0.
w_tabix = sy-tabix.
is_ekbz1-tknum = <fs_vbfa_temp>-shipno.
is_ekbz1-flag = 'X'.
MODIFY it_ekbz1 FROM is_ekbz1 INDEX w_tabix TRANSPORTING tknum flag.
ENDLOOP.
2010 Apr 06 4:19 AM
Hi Srinivas,
<li>If you want to use BINARY SEARCH with READ statement, First thing , Table must be sorted by Key fields which you mention in WITH KEY <key1> <key2>.
Thanks
Venkat.O
SORT it_ekbz1 by xblnr flag.
"Then use read with BINARY SEARCH.
2010 Apr 06 7:24 AM
Dear Venkat,
I am modifying the key filed which is using in the search. If i used the binary search it is failing in lot of cases.
Reagrds,
Srinivas
2010 Apr 06 7:30 AM
How have you defined the table IT_EKBZ1 ? And in the code snippet you have posted i do not see you modifying the key field.
BR,
Suhas
2010 Apr 06 7:34 AM
Dear Suhas,
I am modifying the fieild FLAG which is using in the Read Statement inside the loop. Thats why i am unable to sort it before the loop and unable to use Binary search.
Reagrds,
Srinivas.
2010 Apr 06 7:45 AM
Sorry. My bad !!
I dont understand why your BINARY SEARCH fails ? Do you have multiple records for the same keys in you table IT_EKBZ1 ?
BR,
Suhas
2010 Apr 06 4:38 AM
Hi Srininas ,
Please do like below
SORT it_ekbz1 by xblnr.
LOOP AT it_vbfa_temp ASSIGNING <fs_vbfa_temp>.
CLEAR is_ekbz1.
READ TABLE it_ekbz1 INTO is_ekbz1 WITH KEY xblnr = <fs_vbfa_temp>-deliv flag = space BINARY SEARCH.
IF sy-subrc = 0.
w_tabix = sy-tabix.
is_ekbz1-tknum = <fs_vbfa_temp>-shipno.
is_ekbz1-flag = 'X'.
MODIFY it_ekbz1 FROM is_ekbz1 INDEX w_tabix TRANSPORTING tknum flag.
ENDLOOP.
Thanks,
Chinmay
Edited by: Chinmay Kumar Ghosh on Apr 6, 2010 9:08 AM
2010 Apr 06 4:48 AM
Hi Srininas,
To use binary search you need to first sort the table preferabely with the field you want to use as the key in the read statement.
Once you have done this you can use the addition Binary search in the read statement.
So in your case before the Loop statement use
Sort table it_ekbz1 by xblnr .
and the modified read statement will look like
READ TABLE it_ekbz1 INTO is_ekbz1 WITH KEY xblnr = <fs_vbfa_temp>-deliv flag = space binary search.
Regards,
Arun
2010 Apr 06 5:02 AM
First sort the internal table on the key fields used in the read statement, then add the keyword "BINARY SEARCH" at the end of Read Statement.
Regards
Vinod
2010 Apr 06 7:21 AM
Dear All,
If we are modifying any field which is using in the binary search in side the loop the binary search will not work ..Thats why i am unable to use binary search woth sorting the key Fields.
But i have to use binary beacuse of the more number of records in both the tables.
Reagrds,
Srinivas.
2010 Apr 06 7:45 AM
Hi,
Thanks for the inputs given.. Please find the solution for the same ....
CLEAR is_ekbz1.
is_ekbz1-flag = 'X'.
MODIFY it_ekbz1 FROM is_ekbz1 TRANSPORTING flag WHERE flag IS INITIAL.
SORT it_ekbz1 BY ebeln xblnr lifnr flag.
LOOP AT it_vbfa_temp ASSIGNING <fs_vbfa_temp>.
CLEAR is_ekbz1.
READ TABLE it_ekbz1 INTO is_ekbz1 WITH KEY xblnr = <fs_vbfa_temp>-deliv flag = 'X' BINARY SEARCH.
IF sy-subrc = 0.
w_tabix = sy-tabix.
is_ekbz1-tknum = <fs_vbfa_temp>-shipno.
is_ekbz1-flag = space.
MODIFY it_ekbz1 FROM is_ekbz1 INDEX w_tabix TRANSPORTING tknum flag.
ENDLOOP.
Regards,
Srinivas
Edited by: Srininas on Apr 6, 2010 12:16 PM
Edited by: Srininas on Apr 6, 2010 12:17 PM
2010 Apr 06 8:04 AM
CLEAR is_ekbz1.
is_ekbz1-flag = 'X'.
MODIFY it_ekbz1 FROM is_ekbz1 TRANSPORTING flag WHERE flag IS INITIAL.
SORT it_ekbz1 BY ebeln xblnr lifnr flag.
LOOP AT it_vbfa_temp ASSIGNING <fs_vbfa_temp>.
CLEAR is_ekbz1.
READ TABLE it_ekbz1 INTO is_ekbz1 WITH KEY xblnr = <fs_vbfa_temp>-deliv flag = 'X' BINARY SEARCH.
IF sy-subrc = 0.
w_tabix = sy-tabix.
is_ekbz1-tknum = <fs_vbfa_temp>-shipno.
is_ekbz1-flag = space.
MODIFY it_ekbz1 FROM is_ekbz1 INDEX w_tabix TRANSPORTING tknum flag.
SORT it_ekbz1 BY ebeln xblnr lifnr flag.
ENDLOOP.
2010 Apr 06 9:22 AM
Sry In my las reply sorting wrong
Correct one is SORT it_ekbz1 By xblnr flag.
Regards,
Srinivas