06-28-2007 2:57 PM
hi friends,
i have a problem with an internal table. it is filled with entries like:
A 1
A 2
A 3
B 5
C 2
C 3
Now, what i want to achieve is <b>DELETE the Entries that do not have duplicates</b> so in that case, B should be deleted. how to do this ?
help will be appreciated and points will be awarded immediately for sure.
Thanks,
Clemens
06-28-2007 5:08 PM
Hi,
Assume itab1 has given entries.
itab2[] = itab1[].
SORT itab2 BY field1.
DELETE ADJACENT DUPLICATES FROM itab2 comparing field1.
loop at itab1.
READ TABLE itab2 with key field1 = itab1-field1 BINARY SEARCH.
if sy-subrc <> 0.
delete itab1.
endif.
endloop.
06-28-2007 3:08 PM
hi,
sort table first.
loop at internal table into workarea1.
move wa1 to workarea2.
compare workarea 2 to wa1.
if there are not same delete.
clear workarea1.
endloop.
Thanks,
Deepti
06-28-2007 3:25 PM
A 1
A 2
A 3
B 5
C 2
C 3
take one temp internal table.
it_temp[] = it_tab[].
sort it_temp by field1.
delete adjacent duplicates from it_temp from it_temp comparing field1.
now it_temp will have unque records.
loop at it_tab.
loop at it_temp where field1 = it_tab-field1.
endloop.
if sy-subrc ne 0.
delete it_tab.
endif.
endloop.
Regards
Vijay
06-28-2007 3:27 PM
Consider something like this. I haven't tested but the general logic might be useful.
get adjacent duplicates
sort itab1 by field1 field2.
copy to a work table
itab2[] = itab1[].
data: temp type itab1.
loop at itab1.
if temp is initial.
temp = itab1.
else.
if temp = itab1.
counter = counter + 1.
else.
counter = 0.
endif.
endif.
if (counter > 1).
delete itab2 where field1 = temp-field1 and field2 = temp-field2.
clear temp.
endif.
endloop.
06-28-2007 3:28 PM
Few ways to do this, here is one.
report zrich_0001 .
types: begin of ttab,
fld1 type c,
fld2 type c,
end of ttab.
data: itab1 type table of ttab with header line.
itab1 = 'A1'. append itab1.
itab1 = 'A2'. append itab1.
itab1 = 'A3'. append itab1.
itab1 = 'B5'. append itab1.
itab1 = 'C2'. append itab1.
itab1 = 'C3'. append itab1.
data: counter type i.
loop at itab1.
clear counter.
loop at itab1 where fld1 = itab1-fld1.
counter = counter + 1.
endloop.
if counter = 1.
delete itab1.
endif.
endloop.
loop at itab1.
write:/ itab1-fld1, itab1-fld2.
endloop.
REgards,
RIch Heilman
06-28-2007 3:32 PM
Sort the table.
Loop at the table.
For each loop pass, read the next entry (SY-tabix + 1). If they are not the same, it's not a duplicate and delete the record from the loop.
No, I don't think this works.
Rob
Message was edited by:
Rob Burbank
06-28-2007 5:08 PM
Hi,
Assume itab1 has given entries.
itab2[] = itab1[].
SORT itab2 BY field1.
DELETE ADJACENT DUPLICATES FROM itab2 comparing field1.
loop at itab1.
READ TABLE itab2 with key field1 = itab1-field1 BINARY SEARCH.
if sy-subrc <> 0.
delete itab1.
endif.
endloop.