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

Back to first record in loop

0 Likes
1,566

Hello Everybody,

I have a loop. i want to if the condition is met, back to first record and resume first line.

How can i do?

Hello Everybody,

I have a loop. i want to if the condition is met, back to first record and resume first line.

How can i do?

4 REPLIES 4
Read only

Sandra_Rossi
Active Contributor
1,496

Here is pseudo code. I'd probably not code like that, but I don't know your exact logic.

DO.
  repeat_loop = abap_false.
  LOOP AT itab ... WHERE ...
    IF ...
      repeat_loop = abap_true.
      EXIT. " leave LOOP AT to go back to first record and resume first line
    ENDIF.
  ENDLOOP.
  IF repeat_loop = abap_false.
    EXIT. " leave DO
  ENDIF.
ENDDO.

Read only

FredericGirod
Active Contributor
1,496

sandra.rossi and what about replace LOOP with a READ... INDEX ... ?

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,496

sandra.rossi I said that "I'd probably not code like that" because "I don't know your exact logic", so any proposal could be valid. I hope that my comment will help the OP to elaborate the question.

Read only

0 Likes
1,496

Ok, i will make an simple example;
the following loop is on row 10 of the table and if statement is okay. I mark to lv_az_ok. now i have to go back for the first line. (my process is similar but of course there is a more complex calculation)

select * from sflight into table @data(t_sflight).<br>loop at t_sflight into data(_sflight).
  IF _Sflight-carrid = 'AZ'.
    DATA(lv_az_ok)  = 'X'.
     "leave LOOP AT to go back to first record and resume first line</em>
  ENDIF.
endloop.

Also, the above code is a solution for me. However, i'am still curious about your choice. Maybe this could be the new syntax. And no suitable for me read table or index.