2007 Aug 17 11:25 PM
I want to compare two internal tables itab1 and itab2 and delete entries from itab1 where are also present in itab2.
How to do that.
2007 Aug 17 11:33 PM
Hi,
loop at itab.
v_tabix = sy-tabix.
read table itab2 with key <<<key field >> = itab-<<<key field>>
if sy-subrc eq 0
delete itab index v_tabix.
endif.
endloop.
aRs
2007 Aug 17 11:34 PM
LOOP AT TAB1 ASSIGNING <FS_TAB1>.
READ TABLE TAB2 WITH KEY FIELD1 = <FS_TAB1>-FIELD1.
IF SY-SUBRC EQ 0.
W_TABIX = SY-TABIX.
DELETE TAB1 INDEX W_TABIX.
ENDIF.
ENDLOOP.
Greetings,
Blag.
Message was edited by:
Alvaro Tejada Galindo
2007 Aug 17 11:54 PM
It is not good practice to delete internal table within loop..
use one flag in internal table,if condition is meet then flag = 'X'.
loop at itab.
v_tabix = sy-tabix.
read table itab2 with key <<<key field >> = itab-<<<key field>>
if sy-subrc eq 0
flag = 'X'.
modify itab.
endif.
endloop.
delete itab where flag = 'X'.
Thanks
Seshu
2007 Aug 18 3:59 AM
sort itab1 by < field > ascending.
sort itab2 by < field > ascending.
loop at itab1.
wk_var = itab1-<>.
read table itab2 with key <field> = wk_var binary search.
if sy-subrc = 0.
delete itab1.
endif.
clear wk_var.
endloop.
2007 Aug 18 8:23 AM
Hii..
It is not Good Practice to use DELETE or APPEND on the Same ITAB within a LOOP.
Hence this can be the Right Solution for u.
**USE THIS METHOD WHEN THERE IS ONLY 1:1 MATCHING
SORT ITAB1 BY <<KEY FIELD>>
loop at ITAB2.
read table ITAB1 with key <<<key field >> = ITAB2-<<<key field>> BINARY SEARCH.
IF SY-SUBRC = 0.
v_tabix = sy-tabix.
delete itab1 index v_tabix.
endif.
endloop.
**OR YOU CAN ALSO USE... TO DELETE MULTIPLE ROWS AT A TIME
loop at ITAB2.
delete itab1 where <<KEYFIELD>> = ITAB2-KEYFIELD.
endloop.
<b>Reward if Helpful</b>