2007 Aug 01 5:34 PM
Hello everybody, I'm in a trouble so I've decided to post here.
I have an internal table with several duplicates, and I need to delete ALL of them.
I'm using this sentences:
SORT <table> BY <fields>.
DELETE ADJACENT DUPLICATES FROM <table> COMPARING <fields>.
After that, my table still has a record; and I want to delete ALL records with duplicates.
Can somebody help me??
Thanks a lot!
Hello everybody, I'm in a trouble so I've decided to post here.
I have an internal table with several duplicates, and I need to delete ALL of them.
I'm using this sentences:
SORT <table> BY <fields>.
DELETE ADJACENT DUPLICATES FROM <table> COMPARING <fields>.
After that, my table still has a record; and I want to delete ALL records with duplicates.
Can somebody help me??
Thanks a lot!
2007 Aug 01 5:39 PM
ur doing the correct way... may be one of keys ur using in delete statement varies in the internal table due to which ur seeing duplicate entries, but actually, it might that one of the field has different value.... check all field which u have used in delete statement.
also, all fields used in delete statement need to be used in sort statement as well...
Award Points
2007 Aug 01 5:44 PM
You'll have to loop through the table and compare keys. If there are records with duplicate keys, set a (new) flag field on the table as 'X'.
Then delete from the table where the flag is 'X'.
If you try to delete the records in the loop, you may run into problems with sy-tabix.
Rob
2007 Aug 01 5:47 PM
Hi,
You are doing it correctly. check the sort fields and the fields in the delete statement.
let us say your internal table has these records.
itm qty
10 123
10 135
10 140
sort itab by itm.
delete adjacent duplicates from itab comparing itm
after this internal table will contain only one entry.... 10 123 or can be any from this..
is this ur secnerion that you even want to delte this record too ...
then here is the logic.
data : lv_coutn type i.
sort itab by itm.
ktab = itab.
loop at itab.
loop at ktab where itm = itab-itm.
lv_count = lv_count + 1.
endloop.
if lv_count eq 1.
append itab to jtab.
endif.
clear lv_count.
endloop.
end of this jtab will only contains the entries unique in itab.
Thanks
mahesh
2007 Aug 01 6:03 PM
Hi,
If DELETE ADJACENT DUPLICATES is not working then you can do the following.
Sort ITAB by field.
Declare one more internal table (e.g.: JTAB) of having same struture as ITAB. Now loop the internal table into work area. And use the Control Break AT NEW filed.
and append the values to the 2nd internal table. at the end Assing the Values of JTAB to ITAB.
ITAB[] = JTAB[].
Reward points if helpful answer.
Ashvender
2007 Aug 01 6:09 PM
Thanks everybody, but I wan to delete ALL ocurrences with duplicates.
For example:
My table:
Field1 Field 2
10 123
10 123
10 123
20 123
I want to get this:
Field1 Field2
20 123
Message was edited by:
Ole22
2007 Aug 01 6:17 PM
Hi,
Try the follwoiing:
Sort ITAB by field2.
Now use the procedure I have declared in prevous reply. Means loop the internal table & use control break AT NEW field2. And append in the 2nd internal table.
Ashvender
2007 Aug 01 6:41 PM
2007 Aug 01 7:12 PM
2007 Aug 01 7:19 PM
DATA: contador TYPE i.
SORT t_datos BY connid.
Se declara otra tabla igual y se copian los datos
t_datos2[] = t_datos[].
Se recorre lap primera
LOOP AT t_datos.
CLEAR contador.
Se recorre la segunda tabla con el campo que queremos vigilar
LOOP AT t_datos2 WHERE connid = t_datos-connid.
Se incrementa el contador
ADD 1 TO contador.
Si hay más de un registro repetido para el mismo campo
(En este caso CONNID)
IF contador GT 1.
Se borran todas las entradas
DELETE t_datos2 WHERE connid = t_datos-connid.
ENDIF. " contador GT 1
ENDLOOP. " t_datos2
ENDLOOP. " t_datos1
Restauramos t_datos.
t_datos[] = t_datos2[].
2007 Aug 01 8:16 PM
That's a bit dangerous - your deleting multiple entries from a table that you're looping through.
Rob
2007 Aug 01 9:09 PM
Yes, you are correct; so...I'll use another table to delete entries.
Regards
2007 Aug 02 2:56 PM
Problem and all solution would be much simpler, if you would phrase the problem more suitably: You don't want to delete, you want the keep the unique entries!
Solution was given above, just move to unique ones to another table, don't delete anything in between.
Siegfried
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |