Application Development 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: 

delete duplicate column values for

Former Member
0 Kudos

Hi All,

My internal table contains the fields as no and text.The no is repeted but the text changes. so how to delete the no which is repeated again in the internal table.

for eg:

No Text

1 Text1

1 Text2

2 Text3

i need to replace the second column No as ' '.

Thanks

Yogesh.

1 ACCEPTED SOLUTION

suresh_datti
Active Contributor
0 Kudos

try this out..

types: begin of typ_itab,
        no(2),
        text(5),
       end of typ_itab.
data: itab type table of typ_itab,
      rec_tab like line of itab,
      w_old(2).
rec_tab-no = 1.
rec_tab-text = 'test1'.
append rec_tab to itab.
rec_tab-no = 1.
rec_tab-text = 'test2'.
append rec_tab to itab.
rec_tab-no = 1.
rec_tab-text = 'test3'.
append rec_tab to itab.
rec_tab-no = 1.
rec_tab-text = 'test4'.
append rec_tab to itab.
loop at itab into rec_tab.
  w_old = rec_tab-no.
  if sy-tabix gt 1.
    if rec_tab-no = w_old.
      clear rec_tab-no.
      modify itab from rec_tab index sy-tabix.
    endif.
  endif.
endloop.
loop at itab into rec_tab.
  write: / rec_tab-no,rec_tab-text.
endloop.

~Suresh

3 REPLIES 3

former_member784222
Active Participant
0 Kudos

Hi,

You need to have another internal table containing the 'no' field alone.

loop at main_tab.

read table ref_tab with key no = maintab-no. "test for existence

if sy-subrc = 0.

clear: maintab-text. if yes clear

else.

reftab-no = maintab-no. "if not append

append reftab.

endif.

modify maintab.

endloop.

Thanks and regards,

S. Chandra Mouli.

suresh_datti
Active Contributor
0 Kudos

try this out..

types: begin of typ_itab,
        no(2),
        text(5),
       end of typ_itab.
data: itab type table of typ_itab,
      rec_tab like line of itab,
      w_old(2).
rec_tab-no = 1.
rec_tab-text = 'test1'.
append rec_tab to itab.
rec_tab-no = 1.
rec_tab-text = 'test2'.
append rec_tab to itab.
rec_tab-no = 1.
rec_tab-text = 'test3'.
append rec_tab to itab.
rec_tab-no = 1.
rec_tab-text = 'test4'.
append rec_tab to itab.
loop at itab into rec_tab.
  w_old = rec_tab-no.
  if sy-tabix gt 1.
    if rec_tab-no = w_old.
      clear rec_tab-no.
      modify itab from rec_tab index sy-tabix.
    endif.
  endif.
endloop.
loop at itab into rec_tab.
  write: / rec_tab-no,rec_tab-text.
endloop.

~Suresh

Former Member
0 Kudos

Hi Yogeshwar,

DATA V_TABIX TYPE SY-TABIX.

DATA WA TYPE ITAB.

DATA V_FLAG.

SORT ITAB BY NO TEXT.

LOOP AT ITAB INTO WA.

V_TABIX = SY-TABIX.

AT NEW NO.

V_FLAG = 'X'.

CONTINUE.

ENDAT.

IF V_FLAG = 'X'.

CLEAR WA-NO.

MODIFY ITAB FROM WA INDEX V_TABIX.

ENDIF.

AT ENDOF NO.

CLEAR V_FLAG.

ENDAT.

ENDLOOP.

LOOP AT ITAB.

WRITE:/05 ITAB-NO , 25 ITAB-TEXT.

ENDLOOP.

Thanks,

Vinay