Looping Directly Through a Screen Table 

Use the simple form of the LOOP statement

LOOP.
...<actions>...
ENDLOOP.

to loop through the currently displayed rows of a screen table. If you are using a table control, include the additional WITH CONTROL parameter:

LOOP WITH CONTROL <table control>.
...<actions>...
ENDLOOP.

This simple LOOP is the most general form of the LOOP statement. If you use this LOOP, you can declare the screen table fields as any type (internal table, database table, structure or individual fields). The simple LOOP copies the screen table fields back and forth to the relevant ABAP fields. If you want to manipulate the screen values in a different structure, you must explicitly move them to where you want them.

Each pass through the loop places the next table row in the ABAP fields, and executes the LOOP <actions> (usually ABAP module calls) for it. In a PBO event, the LOOP statement causes loop fields in the program to be copied row by row to the screen. In a PAI event, the fields are copied row by row to the relevant program fields.

In an ABAP module, use the system variable SY-STEPL to find out the index of the screen table row that is currently being processed. The system sets this variable each time through the loop. SY-STEPL always has values from 1 to the number of rows currently displayed. This is useful when you are transferring field values back and forth between a screen table and an internal table. You can declare a table-offset variable in your program (often called BASE, and usually initialized with SY-LOOPC) and use it with SY-STEPL to get the internal table row that corresponds to the current screen table row.

(In the example below, the screen fields are declared as an internal table. The program reads or modifies the internal table to get table fields passed back and forth to the screen.)

***SCREEN FLOW LOGIC***
PROCESS BEFORE OUTPUT.
LOOP.
    MODULE READ_INTTAB.
  ENDLOOP.

PROCESS AFTER INPUT.
LOOP.
    MODULE MODIFY_INTTAB.
  ENDLOOP.

 

***ABAP MODULES***
MODULE READ_INTTAB.
  IND = BASE + SY-STEPL - 1.
  READ TABLE INTAB INDEX IND.
ENDMODULE.

MODULE MODIFY_INTTAB.
  IND = BASE + SY-STEPL - 1.
  MODIFY INTTAB INDEX IND.
ENDMODULE.

Remember that the system variable SY-STEPL is only meaningful within LOOP...ENDLOOP processing. Outside the loop, it has no valid value.