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

DUPLICATE ENTRIES

Former Member
0 Likes
969

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

8 REPLIES 8
Read only

Former Member
0 Likes
937

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

Read only

0 Likes
937

Hi

No bad Manju!

U've just only copied

We usually insert the link to the solution, not to past the solution.

Max

Read only

Former Member
0 Likes
937

Try :

delete adjacent duplicates from itab comparing all fields .

Cheers.

Read only

Former Member
0 Likes
937

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

Read only

Former Member
0 Likes
937

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

Read only

Former Member
0 Likes
937

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

Read only

srinivas_akiri
Active Participant
0 Likes
937

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

Read only

Former Member
0 Likes
937

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 !!