10-02-2008 1:01 PM
Hi,
I have an internal table with these records.
How to delete records that are not the same?
10RR10 | 60 | 20
10RR10 | 60 | 21
10RR10 | 59 | 13
10RR10 | 59 | 13
10RR10 | 57 | 20
10RR10 | 57 | 21
Result should be this:
10RR10 | 59 | 13
10RR10 | 59 | 13
tnx, Adibo.
10-02-2008 1:59 PM
A possible solution:
data: l_count type i.
sort itab1 by field1 field2 field3.
itab2[] = itab1[]. " itab1 is your original table
loop at itab1.
l_count = 0.
loop at itab2 where field1 = itab1-field1
and field2 = itab1-field2
and field3 = itab1-field3.
l_count = l_count + 1.
endloop.
if l_count eq 1.
delete itab1.
endif.
endloop.
10-02-2008 1:12 PM
If you know the value of the fields you want to keep:
delete internal_table
where column_1 ne '10RR10'
or column_2 ne '59'.
Hope that helps,
Michael
10-02-2008 1:16 PM
Hi, TNX!
That's the problem. I dont know the value of the fields..It could be any value.
I just have to keep same records..
Adibo
10-02-2008 1:13 PM
Hi!
DATA: lv1 LIKE itab-f1, lv2 LIKE itab-f1, lv3 LIKE itab-f1.
SORT: itab BY f1 f2 f3.
LOOP AT itab.
AT NEW f3.
MOVE itab-f1 TO lv1.
MOVE itab-f2 TO lv2.
MOVE itab-f3 TO lv3.
ENDAT.
IF NOT (itab-f1 = lv1 AND itab-f2 = lv2 AND itab-f3 = lv3 ).
DELETE itab.
ENDIF.
ENDLOOP.
Regards
Tamá
10-02-2008 1:22 PM
Hello
Try this logic:
data: table1 like XXX,
table2 like XXX.
* in table1 - your data
table2[] = table1[].
delete adjacent duplicates from table2.
loop at table2.
read table1 with key field1 = table2-field1 field2 = table2-field2 field3 = table2-field3.
if sy-subrc = 0.
delete table1 index sy-tabix.
endif.
endloop.
10-02-2008 1:59 PM
A possible solution:
data: l_count type i.
sort itab1 by field1 field2 field3.
itab2[] = itab1[]. " itab1 is your original table
loop at itab1.
l_count = 0.
loop at itab2 where field1 = itab1-field1
and field2 = itab1-field2
and field3 = itab1-field3.
l_count = l_count + 1.
endloop.
if l_count eq 1.
delete itab1.
endif.
endloop.
10-02-2008 2:13 PM
Solved, TNX all!!
DATA: lv_count TYPE sy-index.
LOOP AT lt_zvehicle_partner INTO wa_zvehicle_partner.
lv_count = 0.
LOOP AT lt_zvehicle_partner_del INTO wa_zvehicle_partner_del
WHERE kenteken = wa_zvehicle_partner-kenteken
AND partner = wa_zvehicle_partner-partner
AND link_partner_fct = wa_zvehicle_partner-link_partner_fct.
lv_count = lv_count + 1.
ENDLOOP.
IF lv_count = 1.
DELETE lt_zvehicle_partner.
ENDIF.
ENDLOOP.