‎2008 Mar 11 8:42 PM
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
‎2008 Mar 11 8:55 PM
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
‎2008 Mar 11 8:47 PM
sort by the column that has duplicate value and then use delete adjacent duplicates comparing that column.
G@urav.
‎2008 Mar 11 8:54 PM
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.
‎2008 Mar 11 8:56 PM
before sorting and performing delete adjacent you may consider to change the data in same case using TRANSLATE statement
‎2008 Mar 11 8:59 PM
Thanks for the quick response. I already tried that. It did not work.
VG
‎2008 Mar 11 9:01 PM
Let us see the code that you are using to achieve this.
G@urav.
‎2008 Mar 11 9:01 PM
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
‎2008 Mar 11 9:04 PM
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
‎2008 Mar 11 9:05 PM
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
‎2008 Mar 11 9:08 PM
delete adjacent duplicates from itab comparing ename.
G@urav.
‎2008 Mar 11 8:55 PM
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
‎2008 Mar 11 9:17 PM
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.
‎2008 Mar 11 9:23 PM
Yep. I got it.
Thanks everyone. Shall award the points accordingly.
VG