Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use LOOP AT itab INTO <fieldsymbol>

As I rarely loop into a field symbol, I often forget to use ASSIGNING instead of INTO which will promptly cause an abend. Is there a valid use of INTO with <fieldsymbol> or is this something that the syntax checker really ought to catch?

like image 462
tomdemuyt Avatar asked Dec 13 '25 22:12

tomdemuyt


1 Answers

LOOP...INTO is perfectly valid but it will work differently. LOOP...INTO transports the values to the structure provided but ASSIGNING assigns the field symbol to the actual table rows.

The only difference is if you are going to change the table contents. See the following:

* Changes all entries in the CARRID column of lt_flights to 50.
LOOP AT lt_flights ASSIGNING <flight>.
  <flight>-carrid = 50.
ENDLOOP.

* Does not change the entries in lt_flights (MODIFY...FROM would be required).
ASSIGN <flight> TO ls_flight.
LOOP AT lt_flights INTO <flight>.
  <flight>-carrid = 50.
ENDLOOP.

LOOP...INTO with a field symbol would be useless unless you had some kind of dynamic programming requirement.

like image 156
Eric Avatar answered Dec 16 '25 08:12

Eric