2006 Aug 15 1:04 PM
Hi All,
How to copy the duplicates from sorted internal table values into other internal table.
Thanks,
Venkat
2006 Aug 15 1:06 PM
loop at itab.
clear flag.
at new matnr.
flag = 'X'.
endat.
if flag ne 'X'.
move-corresponding itab to itab1.
append itab1.
endif.
endloop.where matnr is the duplicate entry in itab.
Message was edited by: Chandrasekhar Jagarlamudi
2006 Aug 15 1:06 PM
Hi,
I think there is no direct command. You will have to build ur own logic.
>> First take a copy of the original internal table
>> Then SORT the table and do a adjacent duplicate
>> Now you have 2 tables one with original data and second with unique data.
>> Compare the two tables using a loop.
itab_1[] = itab[].
SORT ITAB bY F1 F2.
DELETE ADJACENT DUPLICATES FROM ITAB.
Loop at itab_1.
READ TABLE ITAB with key ITAB = itab_1.
IF sy-subrc eq 0.
CONTINUE.
ELSE.
DELETE.
ENDIF.
endloop.
Cheers
VJ
Message was edited by: Vijayendra Rao
2006 Aug 15 1:15 PM
2006 Aug 15 3:10 PM
Hello Vijayendra,
READ TABLE ITAB with key ITAB = itab_1.
This stmt is not working.
Thanks,
Venkat
2006 Aug 15 3:18 PM
change it to
READ TABLE ITAB with key ITAB-fld1 = itab_1-fld1
ITAB-fld2 = itab_1-fld2. ~Suresh
2006 Aug 15 3:19 PM
You can write the fields with key statement..eg
READ TABLE ITAB with KEY itab-f1 = itab_1-f1
itab-f2 = itab_1-f2....
etc
Regards
anurag
2006 Aug 15 1:15 PM
I dont think it can done via a single command..need to use the below logic.
sort itab.
loop at itab.
istab = itab.
at end of field.
move-corresponding istab to itab1.
append itab1.
endat.
endloop.
Regards
Anurag
2006 Aug 15 1:54 PM
Hi,
try this code:
sort itab.
loop at itab.
at new fld1.
..
endat.
itabdup-fld1 = itab-fld1.
append itabdup.
clear itabdup.
end loop.
delete adjacent duplicates from itab comparing fld1.
reward if helpful,
keerthi.
2006 Aug 15 3:52 PM
Please see the following example. this program pulls out records only when they have a duplicate entry in the table. In this case, the record with GHI will be outputed.
report zrich_0001.
data: begin of itab occurs 0,
f1 type c,
f2 type c,
f3 type c,
end of itab.
data: begin of itabx occurs 0,
f1 type c,
f2 type c,
f3 type c,
end of itabx.
data: begin of itabo occurs 0,
f1 type c,
f2 type c,
f3 type c,
end of itabo.
data: counter type i.
itab = 'ABC'. append itab.
itab = 'DEF'. append itab.
itab = 'GHI'. append itab.
itab = '123'. append itab.
itab = '456'. append itab.
itab = '789'. append itab.
itab = 'GHI'. append itab.
itabx[] = itab[].
sort itabx ascending.
sort itab ascending.
delete adjacent duplicates from itab.
loop at itab.
clear counter.
loop at itabx where f1 = itab-f1
and f2 = itab-f2
and f3 = itab-f3.
counter = counter + 1.
endloop.
if counter > 1.
move itab to itabo.
append itabo.
endif.
endloop.
* Output the record that had a duplicate entry
loop at itabo.
write:/ itabo.
endloop.
Regards,
Rich Heilman