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: 

Internal table

Former Member
0 Kudos
231

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.

15 REPLIES 15

Former Member
0 Kudos
210

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>. 

Former Member
0 Kudos
210

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.

Former Member
0 Kudos
210

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

Former Member
0 Kudos
210

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

Former Member
0 Kudos
210

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.

0 Kudos
210

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.

0 Kudos
210

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 ...

Former Member
0 Kudos
210

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.

Former Member
0 Kudos
210

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

0 Kudos
210

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.

Former Member
0 Kudos
210

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

Former Member
0 Kudos
210

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.

Former Member
0 Kudos
210

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

Former Member
0 Kudos
210

hi Amar,

Refer to the below thread ... hope it might help..

Regards,

Santosh

Former Member
0 Kudos
210

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.