2006 Dec 05 2:48 PM
Hello,
I have an internal table with 6 fields and if the first five fields are same then its called a dublicate and I shud collect these duplicates in an other table moving the original to the other internal table. So from the basic Internal table I need to form 2 tables one with originals and the other with duplicates..How do i do this?
Thanks
Viky
2006 Dec 05 2:52 PM
Hi
Say itab is your first table and
itab2 is table of the same type as itab
wa_itab and wa_itab are work areas of the type of your internal table.
Loop at itab into wa_itab.
clear cnt.
Loop at itab into wa_itab1 where field1 = wa_itab-field1
field2 = wa_itab-field2
field3 = wa_itab-field3
field4 = wa_itab-field4
field5 = wa_itab-field5
cnt = cnt + 1.
If cnt gt 1.
append wa_itab1 to itab2.
DELETE itab from wa_itab1.
endif.
Endloop.
Hello,
I have an internal table with 6 fields and if the first five fields are same then its called a dublicate and I shud collect these duplicates in an other table moving the original to the other internal table. So from the basic Internal table I need to form 2 tables one with originals and the other with duplicates..How do i do this?
Thanks
Viky
2006 Dec 05 2:52 PM
Hi
Say itab is your first table and
itab2 is table of the same type as itab
wa_itab and wa_itab are work areas of the type of your internal table.
Loop at itab into wa_itab.
clear cnt.
Loop at itab into wa_itab1 where field1 = wa_itab-field1
field2 = wa_itab-field2
field3 = wa_itab-field3
field4 = wa_itab-field4
field5 = wa_itab-field5
cnt = cnt + 1.
If cnt gt 1.
append wa_itab1 to itab2.
DELETE itab from wa_itab1.
endif.
Endloop.
2006 Dec 05 2:53 PM
take two internal tables and both should be a copy of the original table.
in one table delete adjacent duplicates comparing the necessary fields.
next loop at the original internal table . read the table in which duplicates are deleted. delete the third table if there are entries in second table.
cheers,
amit
2006 Dec 05 2:53 PM
loop at itab1.
if itab1-field1 = itab1-field2.
if itab1-field1 = itab1-field3.
if itab1-field1 = itab1-field4.
if itab1-field1 = itab1-field5.
move corresponding fields of itab1 to itab2.
append itab2.
else.
move corresponding fields of itab1 to itab3.
append itab3.
endif.
else.
move corresponding fields of itab1 to itab3.
append itab3.
endif.
else.
move corresponding fields of itab1 to itab3.
append itab3.
endif.
else.
move corresponding fields of itab1 to itab3.
append itab3.
endif.
clear: iatb1, itab2, itab3.
endloop.
Message was edited by:
Ramesh Babu Chirumamilla
2006 Dec 05 2:56 PM
suppose say fld1 , fld2 ,fld3 , fld4 fld5 , fld6 are ur fields
sort itab by fld1 fld2 fld3 fld4 fld5 fld6
loop at itab.
at new fld5.
read table itab index sy-tabix.
move-corresponding itab to itab1.
append itab1.
delete table itab index sy-tabix.
endat.
endat.
now
itab1 will contain the originals
itab will contain the duplicates
2006 Dec 05 3:05 PM
data: ind like sy-tabix.
itab_orig[] = itab[].
sort itab by fld1 fld2 fld3 fld4 fld5.
delete adjacent duplicates from itab comparing fld1 fld2 fld3 fld4 fld5.
loop at itab into wa.
ind = sy-tabix.
loop at itab from into wa_tab
where fld1 = fld1
and fld2 = fld2
and fld3 = fld3
and fld4 = fld4
and fld5 = fld5.
check sy-tabix gt ind.
append wa_tab to itab_dup.
delete itab from wa_tab.
endloop.
delete itab.
endloop.Now, i guess itab_orig should be holding the originals and itab_dup holding duplicate entries.
Please check.
Kind Regards
Eswar
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |