2008 Mar 12 8:16 AM
Hello freinds,
I have one internal table.Now I have to check wheter that internal table has any reapeting entry or not.
then please tell me how to check.
2008 Mar 12 8:19 AM
hi,
sort that internal table by all fields ... if you want to delete those then use delete adjacent duplcates to delete those
sort itab <fields>.
delete adjacent duplicates from itab comparing <fields>.
2008 Mar 12 8:20 AM
Hi,
Use COLLECT statement to get unique records in the internal table.
-->You use the COLLECT statement to generate unique or compressed datasets. The contents of the work area of the internal table are recorded as a new entry at the end of the table or are added to an existing entry. The latter occurs when the internal table already contains an entry with the same key field values as those currently in the work area. The numeric fields that do not belong to the key are added to the corresponding fields of the existing entry.
When the COLLECT statement is used, all the fields that are not part of the key must be numeric.
Regards,
vineela.
2008 Mar 12 8:20 AM
let itab1 be ur internal table...then code like this....
data itab2 like itab[].
sort itab1.
itab2 = itab1[].
delete adjacent duplicates from itab2.
if itab1[] = itab2.
No duplicate entries exist
else.
*Duplicate entries exist
endif.
Reward if useful...
Thanks Arjun
2008 Mar 12 8:23 AM
Hi,
chk out this thread..
DELETE ADJACENT DUPLICATE ENTRIES FROM <itab> http://COMPARING. .
Deletes adjacent duplicate entries, either by comparing the key fields or the comparison fields specified explicitly in the COMPARING addition.
Regards,
Arunsri
2008 Mar 12 8:23 AM
Hi,
say ur internal table is itab.
create another internal table jtab same as itab.
then do like this.
jtab[] = itab[].
DELETE ADJACENT DUPLICATES FROM jtab COMPARING ALL FIELDS.
if itab[] = jtab[].
no duplicates
else.
duplicates are there
endif.
rgds,
bharat.
2008 Mar 12 8:48 AM
thanx Bharat,
This is really Helpful answer.
But My problem is that I have to find out the duplicate entries and transport to another internal table.
then please tell me how to do it.
2008 Mar 12 9:00 AM
sort itab by field1 field2.
loop at itab.
v_counter = v_counter + 1.
itab1 = itab.
if v_counter > 1.
if itab1-field1 = itab-field1 and
itab1-field2 = itab-field2. <-- depends on upto how many
no. of fields UR looking for duplicates
itab3 = itab.
append itab3.
clear: itab3 , v_counter.
endif.
endif.
endloop.
itab3 will contain all the duplicate entries ...
2008 Mar 12 8:23 AM
describe table itab lines x. "take the no of records in itab
sort itab by use here all the fields in the internal table.
use command delete adjacent duplicates on itab.
describe table itab lines y.
if x=y.
message 'no duplicate records found'.
else.
message 'duplicate records found'.
endif.
2008 Mar 12 8:26 AM
hi ,
tables:pa0008.
data: begin of it_pa00008 occurs 0,
pernr like pa0008-pernr,
begda like pa0008-bagda,
endda like pa0008-endda,
ansal like pa0008-ansal,
end of it_pa0008 .
select-options:s_pernr for pa0008-pernr.
select pernr
begda
endda
ansal
from pa0008
into table it_pa0008
where pernr in s_pernr.
sort it_pa0008 by pernr begda descending.
*here you put a break point to see the duplicates *
delete adjacent duplicates from table it_pa0008 comparing pernr.
regards,
venkat.
Edited by: venkat appikonda on Mar 12, 2008 9:27 AM
2008 Mar 12 8:47 AM
Hi Venkat,
This is really Helpful answer.
But My problem is that I have to find out the duplicate entries and transport to another internal table.
then please tell me how to do it.
2008 Mar 12 8:52 AM
Try this.
data : wa_store like line of itab.
sort itab by <ur key fieds>.
loop at itab.
if sy-tabix = 1.
wa_store = itab.
else.
if wa_store = itab.
<append wa_store to new intenal table.>
endif.
wa_store = itab.
endif.
clear itab.
endloop.
Edited by: Kamini Rawat on Mar 12, 2008 9:55 AM
2008 Mar 12 9:04 AM
sort itab.
itab[] = itab_new[].
delete itab adjascent duplicate coparing <,,>
If itab[] <> itabnew[].
loop at itab_new.
read itab.
if sy-subec <> 0.
move reord from itab to itab_store.
endif.
endloop.
2008 Mar 12 9:06 AM
hi
1. if you don't want duplicate entries,
sort itab <fields>.
delete adjacent duplicates from itab comparing <fields>.
2. if you want to findout
sort itab <fields>.
loop at itab into wa1.
if wa1 = wa2.
duplicate entries are there
endif.
wa2 = wa1.
endloop.
reward if useful
2008 Mar 12 9:11 AM
2008 Mar 12 9:52 AM
Hi,
For moving ur duplicate entries to another table, u need to take three internal tables.
here is the sample code:
itab1 is the original internal table with all the entries and a blank fiels as flag appended at last.
Make a copy of it.
itab2 = itab1.
Delete duplicate adjacent from itab2 comparing all fields.
*now,
LOOP at itab2 into wa_itab2.
counter = 0.
LOOP at itab1 into wa_itab1.
if wa_itab2 = wa_itab1.
counter = counter +1.
if counter GT 1.
wa_itab3 = wa_itab1.
Append wa_itab3 to itab3.
wa_itab1-flag = 'X'.
modify itab1 from wa_itab1 transporting flag.
endif.
endif.
endloop.
endloop.
This will create an internal table itab3 with all duplicate entries . Also duplicate entries will be marked by flag in itab1.
hope it will solve your problem.
Reward points if helpful.
Thanks,
Parul.