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: 

Compare rows of same internal table

Former Member
0 Kudos
2,241

Hi folks,

I have to compare the fields value of f2, f3 in between rows of same internal table. how can I achieve this...Please help me out...

thanks in advance

1 ACCEPTED SOLUTION

former_member194669
Active Contributor
194

Try something this way



itab_t[] = itab[].

loop at itab.
  v_tabix = sy-tabix.
  read table itab_t index v_tabix.
  if itab_t-f2 = itab_t-f3.
     " do your validation.
  endif.
endloop.

5 REPLIES 5

former_member194669
Active Contributor
195

Try something this way



itab_t[] = itab[].

loop at itab.
  v_tabix = sy-tabix.
  read table itab_t index v_tabix.
  if itab_t-f2 = itab_t-f3.
     " do your validation.
  endif.
endloop.

Former Member
0 Kudos
194

Hi Kartikey,

What exactly is your requirement? Can you be little more specific.

Regards,

Bharati

0 Kudos
194

hi,

i need to see that whether the value of f2 field is repeated in any other row or not

Edited by: KARTIKEY SINGH on Dec 22, 2008 8:25 PM

0 Kudos
194

Try this way.

Suppose your inernal table has f1,f2,f3...f10 fields.

You want to check whether field f2 is repeated in any of the rows in the table.

t_data1[] = t_data[].

LOOP AT t_data INTO w_data.

LOOP AT t_data1 INTO w_data1 WHERE f2 = w_data-f2.

v_count = v_count + 1.

ENDLOOP.

IF v_count >= 1.

" Your validation

CLEAR: v_count.

ENDIF.

ENDLOOP.

If you dont want to put loop inside loop, try to have the field f2 as first field of the internal table and sort itab by f2. Then loop the table and use At end f2 logic..It will work..

Edited by: Shanthi Kumar Juluru on Dec 22, 2008 11:01 PM

0 Kudos
194

Just some changes to Shanthi Kumar Juluru's post

LOOP AT t_data INTO w_data.

LOOP AT t_data INTO w_data1 WHERE f2 = w_data-f2.

if w_data1-f2 = w_data-f2.

v_count = v_count + 1.

endif.

ENDLOOP.

IF v_count > 1.

" f2 column has repeated value

CLEAR: v_count.

exit.

ENDIF.

ENDLOOP.