Application Development 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: 

delete adjacent duplicates

Former Member
0 Kudos

hi,

SORT itab ASCENDING BY xxx.

DELETE ADJACENT DUPLICATES FROM itab COMPARING xx.

1)can i do in a loop as i need to throw in error file for those repeated record.

2)the itab without header record is ok rite? our standard is not to use occurs but to define another working area. our standard is loop itab into wa

thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You can solve your prob using below code:

DATA: ind(1), p_val like itab-field1.

SORT itab ASCENDING field1.

LOOP AT itab INTO wa_itab.

CLEAR: p_val, ind.

ON CHANGE OF field1.

p_val = itab-field1.

ind = 'X'.

ENDON.

IF itab-field1 = p_val AND NOT ind IS INITIAL.

DELETE itab INDEX sy-tabix.

ENDIF.

ENDLOOP.

Thanks.

6 REPLIES 6

Former Member
0 Kudos

Hi,

1) You can do it in a loop..

2) You can use for without header line internal table also..

Thanks,

Naren

Former Member
0 Kudos

Hi,

DO you want to use the DELETE adjacent inside a loop?

That does not make sense.

If you want to move the duplicate records to a error file, then you have to sort the internal table, loop it and compare the first and next record. IF the key fields are not same move it to another internal table and delete the entry.

If you want to delete all the matching key fields from th internale table in one single shot then, sort the internal table and use delete adjacent duplicates.

Regards

Subramanian

Former Member
0 Kudos

Hi,

You can solve your prob using below code:

DATA: ind(1), p_val like itab-field1.

SORT itab ASCENDING field1.

LOOP AT itab INTO wa_itab.

CLEAR: p_val, ind.

ON CHANGE OF field1.

p_val = itab-field1.

ind = 'X'.

ENDON.

IF itab-field1 = p_val AND NOT ind IS INITIAL.

DELETE itab INDEX sy-tabix.

ENDIF.

ENDLOOP.

Thanks.

Former Member
0 Kudos

e_l,

1) Once you SORT your table by key fields and used Delete adjacent means

there won't be no duplicate records.

2) you can use it.

Thanks

0 Kudos

hi,

thanks

Former Member
0 Kudos

Hi,

Using of Delete adjacent duplicates in a Loop is not of use when you want to store the duplicate entries in an internal table.

Instead Loop at the internal table where itab-xxx = <value>.

<error_table> = itab-xxx.

delete itab index sy-index.

Endloop.

Regards,

Sowmya.