2009 Jan 07 12:55 AM
Hi All
I am having some contents in the internal table like this.
155555666
155555667
155555666abcd
155555667bcdf .
My requirement is to compare only first 9 characters of the entries and delete the duplicate entries.
Can any one suggest me how to do this.
Thanks in advance.
2009 Jan 07 5:41 AM
Hi Arun,
You can use the following code, as it will print the first occurence of the new value in itab of length 9 and delete the remaining.
delete adjacent duplicates from itab comparing a+0(9).
Here itab is the internal table and a is the field in that internal table.
i hope this solves your issue.
Regards,
Sachin Dargan.
Hi Arun,
You can use the following code, as it will print the first occurence of the new value in itab of length 9 and delete the remaining.
delete adjacent duplicates from itab comparing a+0(9).
Here itab is the internal table and a is the field in that internal table.
i hope this solves your issue.
Regards,
Sachin Dargan.
2009 Jan 07 1:06 AM
sort itab by fld1.
loop at itab into wa_itab.
if wa_itab-fld1+0(9) = w_var.
wa_itab2 = wa_itab.
append wa_itab2 to itab2.
else.
w_var = wa_itab-fld1+0(9).
endif.
endloop.
now itab2 has all the duplicate entries which you can delete.
P.S. - you might need to modify the code a bit as I didnt tested it.
2009 Jan 07 4:40 AM
Hello Arun
Here is another approach which you might like:
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_ITAB_DUPL_RECORDS
*&
*&---------------------------------------------------------------------*
*& Thread: Caomparing internal table entries
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1188520"></a>
*&---------------------------------------------------------------------*
REPORT zus_sdn_itab_dupl_records.
TYPES: BEGIN OF ty_s_itab.
TYPES: val(20) TYPE c.
TYPES: END OF ty_s_itab.
DATA: gt_itab TYPE STANDARD TABLE OF ty_s_itab
WITH DEFAULT KEY,
gs_rec TYPE ty_s_itab,
gd_idx TYPE i.
START-OF-SELECTION.
gs_rec-val = '155555666'. APPEND gs_rec TO gt_itab.
gs_rec-val = '155555667'. APPEND gs_rec TO gt_itab.
gs_rec-val = '155555666abcd'. APPEND gs_rec TO gt_itab.
gs_rec-val = '155555667efgh'. APPEND gs_rec TO gt_itab.
SORT gt_itab BY val.
LOOP AT gt_itab INTO gs_rec.
WRITE: / gs_rec-val.
ENDLOOP.
LOOP AT gt_itab INTO gs_rec.
gd_idx = syst-tabix + 1.
LOOP AT gt_itab TRANSPORTING NO FIELDS FROM gd_idx
WHERE ( val+0(9) = gs_rec-val+0(9) ).
DELETE gt_itab INDEX syst-tabix.
ENDLOOP.
ENDLOOP.
skip.
LOOP AT gt_itab INTO gs_rec.
WRITE: / gs_rec-val.
ENDLOOP.
END-OF-SELECTION.
Regards
Uwe
2009 Jan 07 5:41 AM
Hi Arun,
You can use the following code, as it will print the first occurence of the new value in itab of length 9 and delete the remaining.
delete adjacent duplicates from itab comparing a+0(9).
Here itab is the internal table and a is the field in that internal table.
i hope this solves your issue.
Regards,
Sachin Dargan.
2009 Jan 07 8:27 PM
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |