11-13-2007 5:13 AM
Hi All,
I need to remove duplicate entries from an itab, please give me the code for the same..
Thanks in Advance,
Sudeep..
11-13-2007 5:17 AM
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.
11-13-2007 5:14 AM
11-13-2007 5:15 AM
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.
11-13-2007 5:15 AM
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
11-13-2007 5:15 AM
Hi,
Use delete duplicate adjacent statement.
EX.
DELETE ADJACENT DUPLICATES FROM it_final COMPARING pernr endda begda.
Reagrds,
Prashant
11-13-2007 5:16 AM
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
11-13-2007 5:16 AM
hi,
write statement as below :
delete ADJACENT DUPLICATES FROM it_curr COMPARING fcurr.
Regards,
Sandeep Kaushik
11-13-2007 5:17 AM
HI,
use statement delete adjacent duplicates from itab.
regards
siva
11-13-2007 5:17 AM
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.
11-13-2007 5:17 AM
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.
11-13-2007 5:20 AM