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 duplicates based on status

Former Member
0 Likes
1,416

Hi Experts,

I have data in my internal table like shown below:

WBS    OBJNR  STATUS
1234     123        E009

1234     123        E0011

I am using delete adjacent duplicated from ITAB comparing WBS OBJNR which delete entry with status E0011.

But want to delete duplicates comparing WBS OBJNR and status = E009 or E008 or E013

So that the entry E0011 is not deleted.

I dont want to loop my table and i wanted to know if how i can achieve this.

10 REPLIES 10
Read only

Former Member
0 Likes
1,373

hello,

not sure why you need E0011, but the above requirement cannot be done using delete adjacent duplicates. You will need some custom code. You need to explain more to understand what your need is. Thanks.

best regards,

swanand

Read only

0 Likes
1,373

We need records in internal table with status other than E009 or E008 or E013 i.e only if there are duplicate records comparing (wbs) we dont want records with status mentioned above.

Read only

0 Likes
1,373

you could delete these ( E009 or E008 or E013 ) from the internal table in that case.

Read only

0 Likes
1,373

I want to delete duplicates only and not the single entry with above status.

Anyways i am moving only the duplicates in another internal table and checking the status this was the only way i could figure out to do this.

Read only

0 Likes
1,373

Copy the original values to a temp table and do the processing.

it_data_ttemp[] = it_data[].

DELETE it_data_temp WHERE status EQ 'E009' OR status EQ 'E008'.

SORT it_data_temp BY wbs objnr.

DELETE ADJACENT DUPLICATES FROM it_data_temp COMPARING wbs objnr.

it_data_temp will have the unique entries and you can append them to it_data to continue processing.

Thanks,

Shambu

Read only

0 Likes
1,373

Hi Shambu,

Thanks for the reply

DELETE it_data_temp WHERE status EQ 'E009' OR status EQ 'E008'. this statement will also delete

single record but i want to delete only duplicated where status is E009 or E008

Read only

0 Likes
1,373

Are you telling that you want to keep entries for E011 even if they have duplicate entries but delete other like E008, E009 and so on?

Thanks,

Shambu

Read only

0 Likes
1,373

Hi Shambu,

Here is the scenario:

I want to delete only those duplicates where status is E009 or E008.

For below scenario after the logic i should get 2 records in my final o/p table

WBS    OBJNR  STATUS
1234     123        E009

1234     123        E0011

678       234       E009

Final o/p

1234     123        E0011

678       234       E009 ->even if this entry is with status E009 it is not duplicate

Read only

0 Likes
1,373

SORT it_data BY wms objnr status DESCENDING.

LOOP AT it_data INTO ls_data.

is_data = ls_data.

AT NEW objnr.

lv_first = 'X'.

ENDAT.

IF lv_first NE 'X'.

IF ( is_data-status EQ 'E008' OR is_data-status EQ 'E009' ) AND is_data-status NE 'E0011'.

DELETE it_data INDEX sy-tabix.

ENDIF.

ENDIF.

CLEAR lv_first.

ENDLOOP.

Check this and make sure E0011 comes on top of the internal table.

Read only

Former Member
0 Likes
1,373

Hi,

I think loop is very much required for this task. please check the attahed text file however it is not that much good for performance criterria but it is working as you required.

Amit