Application Development 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: 

Internal Table

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

8 REPLIES 8

Sm1tje
Active Contributor
0 Kudos

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

Former Member
0 Kudos

.

Edited by: Yogesh Chavan on May 18, 2009 4:20 PM

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

0 Kudos

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

jayanthi_jayaraman
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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