02-15-2007 2:03 AM
hi,
SORT itab ASCENDING BY xxx.
DELETE ADJACENT DUPLICATES FROM itab COMPARING xx.
1)can i do in a loop as i need to throw in error file for those repeated record.
2)the itab without header record is ok rite? our standard is not to use occurs but to define another working area. our standard is loop itab into wa
thanks
02-15-2007 3:03 AM
Hi,
You can solve your prob using below code:
DATA: ind(1), p_val like itab-field1.
SORT itab ASCENDING field1.
LOOP AT itab INTO wa_itab.
CLEAR: p_val, ind.
ON CHANGE OF field1.
p_val = itab-field1.
ind = 'X'.
ENDON.
IF itab-field1 = p_val AND NOT ind IS INITIAL.
DELETE itab INDEX sy-tabix.
ENDIF.
ENDLOOP.
Thanks.
02-15-2007 2:06 AM
Hi,
1) You can do it in a loop..
2) You can use for without header line internal table also..
Thanks,
Naren
02-15-2007 2:12 AM
Hi,
DO you want to use the DELETE adjacent inside a loop?
That does not make sense.
If you want to move the duplicate records to a error file, then you have to sort the internal table, loop it and compare the first and next record. IF the key fields are not same move it to another internal table and delete the entry.
If you want to delete all the matching key fields from th internale table in one single shot then, sort the internal table and use delete adjacent duplicates.
Regards
Subramanian
02-15-2007 3:03 AM
Hi,
You can solve your prob using below code:
DATA: ind(1), p_val like itab-field1.
SORT itab ASCENDING field1.
LOOP AT itab INTO wa_itab.
CLEAR: p_val, ind.
ON CHANGE OF field1.
p_val = itab-field1.
ind = 'X'.
ENDON.
IF itab-field1 = p_val AND NOT ind IS INITIAL.
DELETE itab INDEX sy-tabix.
ENDIF.
ENDLOOP.
Thanks.
02-15-2007 3:18 AM
e_l,
1) Once you SORT your table by key fields and used Delete adjacent means
there won't be no duplicate records.
2) you can use it.
Thanks
02-15-2007 3:27 AM
02-15-2007 3:27 AM
Hi,
Using of Delete adjacent duplicates in a Loop is not of use when you want to store the duplicate entries in an internal table.
Instead Loop at the internal table where itab-xxx = <value>.
<error_table> = itab-xxx.
delete itab index sy-index.
Endloop.
Regards,
Sowmya.