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: 
Read only

Caomparing internal table entries

0 Likes
765

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
745

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.

4 REPLIES 4
Read only

amit_khare
Active Contributor
0 Likes
745

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.

Read only

uwe_schieferstein
Active Contributor
0 Likes
745

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

Read only

Former Member
0 Likes
746

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.

Read only

0 Likes
745

thanks