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

Remove duplicate entries from Internal Table

Former Member
0 Likes
1,914

Hi,

There is an internal table with following records

SNO TAXAMOUNT MWSKZ

1450044 2 D5

1450044 8 SS

1450044 2 SW

1450044 8 SS

Now i want to remove the dupliactes entries from his internal table without sorting . How to do that??

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,481

Hi,

this code may help.

DATA : BEGIN OF ls_table ,

SNO(7),

TAXAMOUNT(1),

MWSKZ(2),

END OF ls_table .

DATA : lt_table like ls_table OCCURS 0 WITH HEADER LINE .

DATA : lv_tabix like sy-tabix.

lt_table-SNO = '1450044' .

lt_table-TAXAMOUNT = '2' .

lt_table-MWSKZ = 'D5' .

APPEND lt_table.

lt_table-SNO = '1450044' .

lt_table-TAXAMOUNT = '8' .

lt_table-MWSKZ = 'SS' .

APPEND lt_table.

lt_table-SNO = '1450044' .

lt_table-TAXAMOUNT = '2' .

lt_table-MWSKZ = 'SW' .

APPEND lt_table.

lt_table-SNO = '1450044' .

lt_table-TAXAMOUNT = '8' .

lt_table-MWSKZ = 'SS' .

APPEND lt_table.

LOOP AT lt_table.

lv_tabix = sy-tabix.

READ TABLE lt_table WITH KEY SNO = lt_table-SNO

TAXAMOUNT = lt_table-TAXAMOUNT

MWSKZ = lt_table-MWSKZ .

if sy-subrc eq 0.

if lv_tabix ne sy-tabix.

DELETE lt_table.

endif.

endif.

ENDLOOP.

13 REPLIES 13
Read only

Sm1tje
Active Contributor
0 Likes
1,481

If you really want it without sorting, then create a copy of original internal table and cross check both internal tables.

Read only

Former Member
0 Likes
1,481

and how to cross check both internal table? Kindly code it.

Read only

Former Member
0 Likes
1,481

Hi,

You can write

delete adjacent duplicates from internal table name comparing SNO TAXAMOUNT MWSKZ.

this would delete the duplicates.

Thanks,

Guru.

**Reward if helpful

Read only

0 Likes
1,481

No ur code does not remove duplicates. I already tried it

Read only

kiran_k8
Active Contributor
0 Likes
1,481

Anurodh,

Deleting adjacent duplicates without sorting will get you wrong result.It is a must to sort the internal table before using delete adjacent duplicates.

SORT itab ASCENDING BY kunrg.

DELETE ADJACENT DUPLICATES FROM itab COMPARING kunrg.

K.Kiran.

Read only

anversha_s
Active Contributor
0 Likes
1,481

hi,

Suppose your internal table name is ITAB1.

do like this.

itab2[] = itab1[].

sort itab2.

delete adjacent duplicates from itab2 comparing SNO TAXAMOUNT MWSKZ.

Regards,

Anversha

Read only

Former Member
0 Likes
1,481

hi without sorting you can delete entries in this way:

loop at itab into wa1.

count = 0.

loop at itab into wa2.

if wa2 = wa1 .

count = count + 1.

if count > 1.

delete itab from wa1.

endif.

endif.

endloop.

endloop.

reward if useful.

Read only

0 Likes
1,481

Your code gives dump error.

Read only

0 Likes
1,481

hi use this delete statement in previous code

delete table itab from wa1.

reward if useful.

Read only

Former Member
0 Likes
1,481

hi

say tne internal table u used is itab.

now do this:

itab1[] = itab[].

sort itab1 by SNO TAXAMOUNT .

delete adjacent duplicates from itab1 comparing SNO TAXAMOUNT .

loop at itab.

read table itab1 with key SNO = itab-SNO

TAXAMOUNT = itab1-TAXAMOUNT .

if sy-subrc = 0.

<process accordingly>

else.

< processaccordingly>

endif.

endloop.

Read only

Former Member
0 Likes
1,482

Hi,

this code may help.

DATA : BEGIN OF ls_table ,

SNO(7),

TAXAMOUNT(1),

MWSKZ(2),

END OF ls_table .

DATA : lt_table like ls_table OCCURS 0 WITH HEADER LINE .

DATA : lv_tabix like sy-tabix.

lt_table-SNO = '1450044' .

lt_table-TAXAMOUNT = '2' .

lt_table-MWSKZ = 'D5' .

APPEND lt_table.

lt_table-SNO = '1450044' .

lt_table-TAXAMOUNT = '8' .

lt_table-MWSKZ = 'SS' .

APPEND lt_table.

lt_table-SNO = '1450044' .

lt_table-TAXAMOUNT = '2' .

lt_table-MWSKZ = 'SW' .

APPEND lt_table.

lt_table-SNO = '1450044' .

lt_table-TAXAMOUNT = '8' .

lt_table-MWSKZ = 'SS' .

APPEND lt_table.

LOOP AT lt_table.

lv_tabix = sy-tabix.

READ TABLE lt_table WITH KEY SNO = lt_table-SNO

TAXAMOUNT = lt_table-TAXAMOUNT

MWSKZ = lt_table-MWSKZ .

if sy-subrc eq 0.

if lv_tabix ne sy-tabix.

DELETE lt_table.

endif.

endif.

ENDLOOP.

Read only

Former Member
0 Likes
1,481

hi,

write a simple code.

DELETE ADJACENT DUPLICATES FROM ITAB.

Read only

Former Member
0 Likes
1,481

Hi ,

try this code,

itab1[] = itab[].

loop at itab1 into wa_itab1

l_tabix = sy-tabix.

delete itab where ( compare ur fields with wa_itab1 fields ) and index <> l_tabix.

endloop.

reward points if usful.

regards,

muralidhar.