‎2006 Nov 28 4:04 PM
Hi ,
how can i delete duplicate entries without sorting the table , my requirement is at the end the values should be in the same order as in the database and without the duplicate entries. i need to do this on the internal table (without using select distinct ).
Thanks & Regards
Syed
‎2006 Nov 28 4:06 PM
Hi,
SORT ITAB BY FIELD1.
ITAB2[] = ITAB[].
DELETE ADJACENT ........
LOOP AT ITAB.
COUNTER = 0.
LOOP AT ITAB2 WHERE FIELD1 = ITAB-FIELD1.
COUNTER = COUNTER + 1.
IF COUNTER > 1. EXIT. ENDIF.
ENDLOOP.
IF COUNTER > 1. DELETE ITAB. ENDIF.
ENDLOOP.
Thanks
manju
‎2006 Nov 28 4:21 PM
‎2006 Nov 28 4:07 PM
Try :
delete adjacent duplicates from itab comparing all fields .
Cheers.
‎2006 Nov 28 4:07 PM
Hi
<b>you cannot do it without sorting the internal table</b>
you need to sort on the key fields before you use the delete adjacent duplicate statement
‎2006 Nov 28 4:08 PM
Hello,
Delete adjacent duplicates from ITAB(internal table) .
Check if this works for you .if it does not then you can copy the itab into another table & use loop inside loop for checking the recods & if found delete the entry from first table.
Thanks.
null
‎2006 Nov 28 4:09 PM
Hi Syed,
Do like this:
Loop at itab1 into wa_itab1.
Loop at itab1 into wa_itab2 where kunnr eq wa_itab1-kunnr.
cnt = cnt + 1.
if cnt GT 1.
Delete itab1 from wa_itab2.
endloop.
clear cnt.
endloop.
Hope this helps.
Manish
Message was edited by:
Manish Kumar
‎2006 Nov 28 4:20 PM
Hi,
here is the example program which will delete the duplicate entries from the internal table along with original one without changing the order.
DATA : BEGIN OF ITAB1 OCCURS 0,
FIELD TYPE I,
END OF ITAB1,
ITAB2 LIKE ITAB1 OCCURS 0 WITH HEADER LINE,
COUNTER TYPE I.
ITAB1-FIELD = 1.
APPEND ITAB1.
ITAB1-FIELD = 2.
APPEND ITAB1.
ITAB1-FIELD = 3.
APPEND ITAB1.
ITAB1-FIELD = 4.
APPEND ITAB1.
ITAB1-FIELD = 4.
APPEND ITAB1.
ITAB1-FIELD = 5.
APPEND ITAB1.
LOOP AT ITAB1.
WRITE: ITAB1-FIELD, ' ' .
ENDLOOP.
ITAB2[] = ITAB1[].
DELETE ADJACENT DUPLICATES FROM ITAB1.
LOOP AT ITAB2.
COUNTER = 0.
LOOP AT ITAB1 WHERE FIELD = ITAB1-FIELD.
COUNTER = COUNTER + 1.
IF COUNTER > 1.
EXIT.
ENDIF.
ENDLOOP.
IF COUNTER > 1.
DELETE ITAB2.
ENDIF.
ENDLOOP.
LOOP AT ITAB1.
READ TABLE ITAB2 WITH KEY FIELD = ITAB2-FIELD.
IF SY-SUBRC <> 0.
DELETE ITAB1.
ENDIF.
ENDLOOP.
LOOP AT ITAB1.
WRITE: ITAB1-FIELD, ' ' .
ENDLOOP.
plz mark it , if useful
thanks
srini
‎2006 Nov 28 4:28 PM
Syed
Since you dont want to SORT as well not to use SELECT DISTINCT...you can use the below soln.
ITAB_TEMP[] = ITAB[].
SORT ITAB_TEMP.
DELETE DUPLICATE FROM ITAB_TEMP.
LOOP AT ITAB_TEMP.
LOOP at ITAB where f1 = itab_temp-f1.
if sy-tabix > 1.
delete itab.
endif.
endloop.
endloop.
Itab now has the required set of data !!