03-04-2009 4:15 AM
hi all,
i have to compare two internal tables based on 3 fields and if the lineitems with those fields are matching , i have to delete that line item from the first internal table.
03-04-2009 4:18 AM
Hi,
Use something like:-
sort itab1 by field1 field2 field3.
sort itab2 by field1 field2 field3.
loop at itab1.
read table itab2 with key field1 = itab1-field1
field2 = itab1-field2
field3 = itab1-field3.
if sy-subrc = 0.
delete itab1.
endif.
clear itab1.
endloop.
Hope this helps you.
Regards,
Tarun
03-04-2009 4:26 AM
Hi,
Try like this....
loop at itab into w_itab.
delete itab2 where <field name> eq w_itab-<fieldname>.
endloop.
Hope its helps
03-04-2009 4:28 AM
Hi
Is the combination of the three fields unique ?
If its is , use read else use loop to check condition
03-04-2009 4:29 AM
Hi,
Firstly create tmp table of type itab1 or u can also create table with only columns which are common in both tables.
select * into tmp from itab1 inner join itab2 where itab1-field1 = itab2-field1 and itab1-field2 = itab2-field2 and itab1-field3 = itab2-field3.
loop at tmp.
delete from itab1 where itab1-field1 = tmp-field1 and itab1-field2 = tmp-field2
and itab1-field3 = tmp-field3.
endloop.
Thanks,
Smita
03-04-2009 4:29 AM
Hi Dude,
sort table1 by field1 field2 field3.
sort table2 by field1 field2 field3.
loop at table1 into wa_table1.
read table table2 into wa_table2 with key field1 = wa_table1-field1
field2 = wa_table1-field2
field3 = wa_table1-field3.
if sy-subrc = 0.
delete table table1 from wa_table1.
endif.
clear table1.
endloop.
03-04-2009 7:14 AM
Hi use something below to sort the two internal tables after tables having all data .
sort table1 by field1 field2 field3."sorting two internal tables
sort table2 by field1 field2 field3.
loop at table1 into wa_table1."Comparing record by record whether they are equal.
read table table2 into wa_table2 with key field1 = wa_table1-field1
field2 = wa_table1-field2
field3 = wa_table1-field3.
if sy-subrc = 0." if yes delete
delete table table1 from wa_table1.
endif.
clear table1.
endloop.
Regards
03-04-2009 7:26 AM
hi,
sort int_table1 by field1 field2 field3.
sort int_table2 by field1 field2 field3.
loop at int_table1 into wa_table1.
delete int_table2 where field1 = wa_table1-field1 OR field2 = wa_table1-field2 OR field3 = wa_table1-field3.
endloop.
Regards
Ritesh J
03-04-2009 7:40 AM
loop at itab.
read table itab1 with key fieldname1 = itab-fieldname1
fieldname2 = itab-fieldname2.
if sy-subrc = 0.
delete itab.
endif.
endloop.
Regards,
Joan
03-04-2009 7:44 AM
Hi Santosh,
You can do like this:
Suppose you have two internal tables itab1 and itab2 having common field filed1 between them then,
Loop at itab1 into wa1 .
Read table itab2 into wa2 with key field1 = wa1-field1.
if sy-subrc = 0. "this will give 0 if there is any common data between the two internal tables data
delete itab1 from wa1.
endif.
endloop.
Hope it helps
Regrds
Mansi
Edited by: MANSI ASNANI on Mar 4, 2009 8:44 AM
03-04-2009 9:37 AM
Hi Santosh.
The following code is working and will meet ur purpose.
TYPES: BEGIN OF T_ITAB1,
FLD1(5) TYPE C,
FLD2(5) TYPE C,
FLD3(5) TYPE C,
END OF T_ITAB1.
TYPES: BEGIN OF T_ITAB2,
FLD1(5) TYPE C,
FLD2(5) TYPE C,
FLD3(5) TYPE C,
END OF T_ITAB2.
DATA: ITAB1 TYPE STANDARD TABLE OF T_ITAB1,
ITAB2 TYPE STANDARD TABLE OF T_ITAB2,
WA_ITAB1 LIKE LINE OF ITAB1,
WA_ITAB2 LIKE LINE OF ITAB2.
WA_ITAB1-FLD1 = 'AAAA'.
WA_ITAB1-FLD2 = '1111'.
WA_ITAB1-FLD3 = '2222'.
APPEND WA_ITAB1 TO ITAB1.
CLEAR WA_ITAB1.
WA_ITAB1-FLD1 = 'BBBB'.
WA_ITAB1-FLD2 = '6666'.
WA_ITAB1-FLD3 = '7777'.
APPEND WA_ITAB1 TO ITAB1.
CLEAR WA_ITAB1.
*********************************
WA_ITAB2-FLD1 = 'AAAA'.
WA_ITAB2-FLD2 = '1111'.
WA_ITAB2-FLD3 = '2222'.
APPEND WA_ITAB2 TO ITAB2.
CLEAR WA_ITAB2.
WA_ITAB2-FLD1 = 'CCCC'.
WA_ITAB2-FLD2 = '8888'.
WA_ITAB2-FLD3 = '9999'.
APPEND WA_ITAB2 TO ITAB2.
CLEAR WA_ITAB2.
*************************************
LOOP AT ITAB1 INTO WA_ITAB1.
LOOP AT ITAB2 INTO WA_ITAB2.
IF WA_ITAB2-FLD1 = WA_ITAB1-FLD1 AND WA_ITAB2-FLD2 = WA_ITAB1-FLD2.
DELETE ITAB1.
ENDIF.
ENDLOOP.
ENDLOOP.
Thanks and Regards
Suraj S Nair