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: 

Removing duplicate entries from Itab

Former Member
0 Kudos

Hi All,

I need to remove duplicate entries from an itab, please give me the code for the same..

Thanks in Advance,

Sudeep..

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

SORT ITAB BY FIELD1 FIELD2.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING FIELD1 FIELD2.

data : begin of itab occurs 0,

num1 type i,

num2 type i,

end of itab.

data wa like itab.

data: v_cnt type i,

v_num type i.

itab-num1 = 1.

itab-num2 = 1.

append itab.

clear itab.

itab-num1 = 1.

itab-num2 = 3.

append itab.

clear itab.

itab-num1 = 2.

itab-num2 = 4.

append itab.

clear itab.

itab-num1 = 4.

itab-num2 = 4.

append itab.

clear itab.

itab-num1 = 3.

itab-num2 = 1.

append itab.

clear itab.

itab-num1 = 3.

itab-num2 = 2.

append itab.

clear itab.

sort itab by num1.

loop at itab.

if v_num <> itab-num1.

v_num = itab-num1.

if v_cnt = 1.

delete itab where num1 = wa-num1.

clear v_cnt.

v_cnt = v_cnt + 1.

else.

clear v_cnt.

endif.

v_cnt = v_cnt + 1.

else.

v_cnt = v_cnt + 1.

endif.

move itab to wa.

endloop.

if v_cnt = 1.

delete itab where num1 = wa-num1.

endif.

loop at itab.

write:/5 itab-num1,

20 itab-num2.

endloop.

10 REPLIES 10

Former Member
0 Kudos

SORT itab.

DELETE ADJACENT DUPLICATES FROM ITAB.

Regards,

Atish

Former Member
0 Kudos

DELETE - duplicates

Syntax

... ADJACENT DUPLICATES FROM itab

[COMPARING { comp1 comp2 ...}|{ALL FIELDS}]... .

Addition:

... COMPARING {comp1 comp2 ...}|{ALL FIELDS}

Effect

With these additions, the statement DELETE deletes all lines in certain groups of lines, except for the first line of the group. These are groups of lines that follow one another and have the same content in certain components. If the addition COMPARING is not specified, the groups are determined by the content of the key fields.

Lines are considered to be doubled if the content of neighboring lines is the same in the components examined. In the case of several double lines following one another, all the lines - except for the first - are deleted.

Addition

... COMPARING {comp1 comp2 ...}|{ALL FIELDS}

Effect

If the addition COMPARING is specified, the groups are determined either by the content of the specified components comp1 comp2 ... or the content of all components ALL FIELDS. The specification of individual components comp is made as described in the section Specification of Components. Access to class attributes is possible through the object component selector only as of Release 6.10.

Example

Deleting all multiple-occurring lines in the internal table connection_tab. The result of this exanple corresponds to the one in the example for the position specification for INSERT.

DATA: BEGIN OF connection,

cityfrom TYPE spfli-cityfrom,

cityto TYPE spfli-cityto,

distid TYPE spfli-distid,

distance TYPE spfli-distance,

END OF connection.

DATA connection_tab LIKE SORTED TABLE OF connection

WITH NON-UNIQUE KEY cityfrom cityto

distid distance.

SELECT cityfrom cityto distid distance

FROM spfli

INTO TABLE connection_tab.

DELETE ADJACENT DUPLICATES FROM connection_tab.

former_member404244
Active Contributor
0 Kudos

Hi,

SORT ITAB BY FIELD1 FIELD2.

DELETE DUPLICATE ENTRIES FROM TABLE ITAB COMPARING FIELD1 FIELD2.

also u can write

DELETE DUPLICATE ENTRIES FROM TABLE ITAB COMPARING ALL FEILDS.

Reward if helpful.

Regards,

Nagaraj

former_member386202
Active Contributor
0 Kudos

Hi,

Use delete duplicate adjacent statement.

EX.

DELETE ADJACENT DUPLICATES FROM it_final COMPARING pernr endda begda.

Reagrds,

Prashant

Former Member
0 Kudos

Hi ,

First sort the particular internal table and then delete the duplicates record.

eg sort itab.

delete adjacent duplicates from itab comparing all fields.

regards,

Santosh Thorat

former_member208856
Active Contributor
0 Kudos

hi,

write statement as below :

delete ADJACENT DUPLICATES FROM it_curr COMPARING fcurr.

Regards,

Sandeep Kaushik

Former Member
0 Kudos

HI,

use statement delete adjacent duplicates from itab.

regards

siva

Former Member
0 Kudos

Hi,

see this example.

DATA: BEGIN OF connection,

cityfrom TYPE spfli-cityfrom,

cityto TYPE spfli-cityto,

distid TYPE spfli-distid,

distance TYPE spfli-distance,

END OF connection.

DATA connection_tab LIKE SORTED TABLE OF connection

WITH NON-UNIQUE KEY cityfrom cityto

distid distance.

SELECT cityfrom cityto distid distance

FROM spfli

INTO TABLE connection_tab.

DELETE ADJACENT DUPLICATES FROM connection_tab.

rgds,

bharat.

Former Member
0 Kudos

Hi

SORT ITAB BY FIELD1 FIELD2.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING FIELD1 FIELD2.

data : begin of itab occurs 0,

num1 type i,

num2 type i,

end of itab.

data wa like itab.

data: v_cnt type i,

v_num type i.

itab-num1 = 1.

itab-num2 = 1.

append itab.

clear itab.

itab-num1 = 1.

itab-num2 = 3.

append itab.

clear itab.

itab-num1 = 2.

itab-num2 = 4.

append itab.

clear itab.

itab-num1 = 4.

itab-num2 = 4.

append itab.

clear itab.

itab-num1 = 3.

itab-num2 = 1.

append itab.

clear itab.

itab-num1 = 3.

itab-num2 = 2.

append itab.

clear itab.

sort itab by num1.

loop at itab.

if v_num <> itab-num1.

v_num = itab-num1.

if v_cnt = 1.

delete itab where num1 = wa-num1.

clear v_cnt.

v_cnt = v_cnt + 1.

else.

clear v_cnt.

endif.

v_cnt = v_cnt + 1.

else.

v_cnt = v_cnt + 1.

endif.

move itab to wa.

endloop.

if v_cnt = 1.

delete itab where num1 = wa-num1.

endif.

loop at itab.

write:/5 itab-num1,

20 itab-num2.

endloop.

Former Member
0 Kudos

Thanks 4 All