Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Delete ALL Duplicates

Former Member
0 Likes
1,471

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!

12 REPLIES 12
Read only

Former Member
0 Likes
1,420

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

Read only

Former Member
0 Likes
1,420

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

Read only

Former Member
0 Likes
1,420

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

Read only

Former Member
0 Likes
1,420

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

Read only

Former Member
0 Likes
1,420

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

Read only

0 Likes
1,420

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

Read only

Former Member
0 Likes
1,420

Thanks a lot, I've solved my problem

Read only

0 Likes
1,420

What did you do?

Rob

Read only

Former Member
0 Likes
1,420

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[].

Read only

0 Likes
1,420

That's a bit dangerous - your deleting multiple entries from a table that you're looping through.

Rob

Read only

0 Likes
1,420

Yes, you are correct; so...I'll use another table to delete entries.

Regards

Read only

Former Member
0 Likes
1,420

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