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

ABAP code help

Former Member
0 Likes
1,189

Hi folks,

I need some help with the code. Here is the scenario...

I need to remove the duplicate applicant id records from the internal table. The issue is the applicantid is unqiue but the applicant name is the same. It is like this...

data begin of itab occurs 0,

pernr like p4002-pernr,

ename like pb0001-ename,

begda like p4002-begda,

objid like p4002-objid,

end of itab.

objid is the vacany number

I have records like

200000001, john Smith,20070101,50102221

200000002, john smith,20070101,50102221

200000010,Mary Kay,20070101,501023245,

200000003, lara Kane, 20070101,50102221

200000004, lara kane, 20070101,50102221

200000005, kathleen,20070101,501022343

I need to delete the records 2 and 4.

How can I do this?

Thanks in advance for your help,

VG

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,146

I think you want to:

LOOP AT itab.
  TRANSLATE itab-ename TO UPPER CASE.
  MODIFY itab TRANSPORTING ename.
ENDLOOP.

SORT itab BY ename.

DELETE ADJACENT DUPLICATES FROM itab COMPARING ename.

Rob

12 REPLIES 12
Read only

Former Member
0 Likes
1,146

sort by the column that has duplicate value and then use delete adjacent duplicates comparing that column.

G@urav.

Read only

0 Likes
1,146

If some names have letters in upper case and others don't, then translate all to upper case, then compare and delete.

DATA itab_aux LIKE itab OCCURS 0 WITH HEADER LINE.

itab_aux[] = itab[].

LOOP AT itab_aux.

TRANSLATE itab_aux-ename TO UPPER CASE.

MODIFY itab_aux.

ENDLOOP.

SORT itab_aux BY ename pernr.

DELETE ADJACENT DUPLICATES FROM itab_aux.

SORT itab_aux BY pernr.

LOOP AT itab.

READ TABLE itab_aux WITH KEY pernr = itab-pernr BINARY SEARCH.

IF sy-subrc NE 0.

DELETE itab.

ENDIF.

ENDLOOP.

Read only

0 Likes
1,146

before sorting and performing delete adjacent you may consider to change the data in same case using TRANSLATE statement

Read only

0 Likes
1,146

Thanks for the quick response. I already tried that. It did not work.

VG

Read only

0 Likes
1,146

Let us see the code that you are using to achieve this.

G@urav.

Read only

0 Likes
1,146

In most cases there is no need to translate the name to upper case it is the same the value in itab-ename is identical. even then the 'delete adjacent duplicates' is nto working.

Thanks in advance,

VG

Read only

0 Likes
1,146

OK....

after reading the data into the table,

sort itab ascending by ename.

delete adjacent duplicates from itab.

I checked in the debug mode it did not work..

Thanks,

VG

Read only

0 Likes
1,146

You may not need to worry about it in "most cases", but the ones you showed had a mixture of upper an lower case so you need to take care of that.

You need to use the COMPARING addition to DELETE ADJACENT DUPLICATES.

The code I showed should work.

Rob

Read only

0 Likes
1,146

delete adjacent duplicates from itab comparing ename.

G@urav.

Read only

Former Member
0 Likes
1,147

I think you want to:

LOOP AT itab.
  TRANSLATE itab-ename TO UPPER CASE.
  MODIFY itab TRANSPORTING ename.
ENDLOOP.

SORT itab BY ename.

DELETE ADJACENT DUPLICATES FROM itab COMPARING ename.

Rob

Read only

Former Member
0 Likes
1,146

Hi ,

For this first make the name as either or case ( lower or upper ) .

sort by id name .

delete adjacent duplicates from itab comparing name .

Please reward if useful.

Read only

0 Likes
1,146

Yep. I got it.

Thanks everyone. Shall award the points accordingly.

VG