05-18-2009 3:12 PM
Hi All,
I have internal table ITAB with duplicate rows as below.
ITAB-MATNR
A
B
C
C
D
E
E
i would like to delete all duplicate rows from ITAB (i.e both rows with of c and e) and these rows need to be copied into another internal table ITAB1.
Finally, ITAB should be with value A, B ,D and ITAB1 with value C,C,E,E.
How can I do this??
Edited by: Yogesh Chavan on May 18, 2009 4:13 PM
05-18-2009 3:17 PM
Hi,
use the syntax...
delete adjacebnt duplicate comparing fields.
first sort the field only which fields you wan to delete the Duplicates.
example :-delete adjacent duplicate from ITAB comparing matnr werks.
Regards,
Prabhudas
05-18-2009 3:16 PM
SORT and DELETE ADJACENT DUPLICATES perhaps?
First make a copy of the original table, do the sort and delete. Last, cross check the original table and the copy!
Edited by: Micky Oestreich on May 18, 2009 4:16 PM
05-18-2009 3:18 PM
05-18-2009 3:17 PM
Hi,
use the syntax...
delete adjacebnt duplicate comparing fields.
first sort the field only which fields you wan to delete the Duplicates.
example :-delete adjacent duplicate from ITAB comparing matnr werks.
Regards,
Prabhudas
05-18-2009 3:20 PM
HI,
Try this way..
DATA COUNT TYPE I.
ITAB1[] = ITAB[].
SORT ITAB BY MATNR.
LOOP AT ITAB.
COUNT = COUNT + 1.
AT END OF MATNR.
IF COUNT EQ 1.
DELETE ITAB1 WHERE MATNR EQ ITAB-MATNR.
ENDIF.
CLEAR COUNT.
ENDAT.
ENDLOOP.
05-18-2009 3:32 PM
Hi,
Try to sort your internal table by field.
and then delete duplicates values...
For Ex;
*Sort itab by field.
Delete Adjacent Duplicates from itab comparing field.*
Thanks
Rajesh
05-18-2009 3:25 PM
Hi,
Create one more field flag and then loop the table where flag eq space.
Inside the loop find out another entry exists.
If so, mention 'D' in flag for all the records with same values.
endloop.
After that, copy itab to itab1.
In itab delete records where flag eq 'D'.
In itab1 delete records where flag eq space.
05-18-2009 3:29 PM
Another way could be: -
LOOP AT ITAB
MOVE-CORRESPONDING ITAB TO ITAB_DUPS
ITAB_DUPS-COUNT = 1
MOVE-CORRESPONDING ITAB TO ITAB_UNIQUE
ITAB_UNIQUE-COUNT = 1
COLLECT ITAB_DUPS
COLLECT ITAB_UNIQUE
DELETE ITAB_DUPS WHERE COUNT EQ 1
DELETE ITAB_UNIQUE WHERE COUNT GT 1
ENDLOOP
05-18-2009 5:24 PM
DATA : FLAG TYPE I ,
COUNT TYPE I,
WA1 TYPE ITAB.
SORT ITAB.
FLAG = 0.
COUNT = 1.
LOOP AT ITAB.
IF SY-INDEX = 1.
WA1 = ITAB.
CONTINUE.
ENDIF.
IF WA1 NE ITAB.
FLAG = 1.
ENDIF.
IF WA1 EQ ITAB.
COUNT = COUNT + 1.
ENDIF.
IF COUNT EQ = 1 AND FLAG = 1.
APPEND WA1 TO ITAB1.
WA1 = ITAB.
FLAG = 0.
ENDIF.
IF COUNT GE 2 AND FLAG = 1.
DO COUNT TIMES.
APPEND WA1 TO ITAB2.
ENDDO.
COUNT = 1.
FLAG = 0.
WA1 = ITAB.
ENDIF.
ENDLOOP.
IF COUNT GE 2. " This for the last value.
DO COUNT TIMES.
APPEND WA1 TO ITAB2.
ENDDO.
ENDIF.
IF COUNT EQ 1. " for the last value
APPEND WA1 TO ITAB.
ENDIF.
....................................................................
After this ITAB1 will contain A B D
and ITAB2 will contain C C E E