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

loop with Flag

Former Member
0 Likes
1,091

Hi,

I want to compare the a field with its previous value in a internal table

i am using the following logic

flag = 0.

loop at it where x_field = s_field.

if not of flag is intial.

if it_field2 = v_field2.

-


-


endif.

endif.

move it_field2 to v_field.

endloop.

i dont want to use flag in this case can any one help.

thanks.

5 REPLIES 5
Read only

naveen_inuganti2
Active Contributor
0 Likes
797

Hi,

data: tabix type sy-tabix.
loop at itab into wa1.
 read table itab into wa2 index tabix.
 if sy-subrc = 0.
  wa2-f1 is previous value of this field.
  compare wa1-f1 and wa2-f1. 
endif.  
  tabix = sy-tabix.
endloop.

Thanks,

Naveen Inuganti.

Read only

Former Member
0 Likes
797

Hi,

If you are not using the where clause in the LOOP then use AT-NEW inside the loop.

Regards,

Ankur Parab

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
797

Hello Gayatri,

Try like this:

DATA:
v_index TYPE i.

LOOP AT itab INTO wa1.
  v_index = sy-tabix - 1.

  IF v_index GT 0.
    READ TABLE itab INTO wa2 INDEX v_index.
    IF sy-subrc = 0.
*   Compare WA1 & WA2
    ENDIF.
  ENDIF.
ENDLOOP.

Hope this helps.

BR,

Suhas

Read only

Former Member
0 Likes
797

HI,

Clear v_field2
loop at it where x_field = s_field.
if it_field2 = v_field2.
  " The previous value is same with the present value
endif.
move it_field2 to v_field.
endloop.

Read only

Former Member
0 Likes
797

clear w_previousvalue.

loop at it where x_field = s_field.

if it-field1 = w_previousvalue AND

NOT w_previousvalue IS INITIAL.

  • do required processing

else.

  • do required processing.

endif.

w_previousvalue = it-field1.

endloop.