LOOP [AT itab CURSOR top_line [INTO wa] [FROM n1] [TO n2]].
...
ENDLOOP.
1. LOOP.
2. LOOP AT itab CURSOR top_line [INTO wa] [FROM n1] [TO n2].
Definition of a loop in the screen flow logic. The loop sequentially processes the listed groups of the corresponding step loop by executing a loop pass for each group. The statement block between LOOP and ENDLOOP can contain the keywords FIELD, MODULE, and CHAIN (as well as the obsolete SELECT and VALUES) of the flow logic. Nesting of loops is not possible. Loops can either be executed with or without reference to an internal table.
If step loops are defined in a screen, a loop must be defined for each step loop both in the the PBO processing block as well as in the PAI processing block. The assignment of loops to step loops is derived from the alignment of the step loops on the screen - the lines are valuated with primary priority, and the columns with secondary priority.
System Fields
Within a loop pass, the system field sy-stepl contains
the line number of the displayed group, counted from the uppermost, visible line. The system field sy-loopc contains the number of group lines displayed on a screen.
LOOP.
...
ENDLOOP.
If the AT itab addition is not specified, the contents of the screen fields belonging to the current group of the step loop are transported during a loop pass from (at event PBO) or to (at event PAI) data objects with the same name in the ABAP program.
For step loop fields that are defined with reference to the ABAP Dictionary, the data objects with the same name in the ABAP program must be declared using TABLES, as is the case with normal dynpro fields. Otherwise, no data transport will take place.
In the layout of the dynpro screen, there are two dynpro fields wa-col1 and wa-col2 that are grouped together to a group of a step loop. The screen flow logic contains the following statements:
PROCESS BEFORE OUTPUT.
...
LOOP.
MODULE tab_out.
ENDLOOP.
...
PROCESS AFTER INPUT.
...
LOOP.
MODULE tab_in.
ENDLOOP.
...
Loops are run on the step loop and, in the loops for PBO and PAI, the dialog modules tab_out and tab_in are called. The following program section shows how the respective ABAP program fills the step loop fields in the PBO module tab_out from an internal table itab. It also shows how, in the PAI module tab_in, it modifies the internal table in accordance with the user specifications in the step loop.
DATA: BEGIN OF wa,
col1 TYPE i,
col2 TYPE i,
END OF wa,
itab LIKE STANDARD TABLE OF wa.
...
MODULE tab_out OUTPUT.
IF itab IS INITIAL.
DO 40 TIMES.
wa-col1 = sy-index.
wa-col2 = sy-index ** 2.
APPEND wa TO itab.
ENDDO.
ENDIF.
READ TABLE itab INTO wa INDEX sy-stepl.
ENDMODULE.
...
MODULE tab_in INPUT.
MODIFY itab FROM wa INDEX sy-stepl.
ENDMODULE.
LOOP AT itab CURSOR top_line [INTO wa] [FROM n1] [TO n2].
...
ENDLOOP.
If the addition AT itab is specified, an internal table itab of the corresponding ABAP program is sequentially processed parallel to the processing of the step loop. For each group of the step loop, a line in the internal table is processed. The internal table itab must be an index table.
A scroll bar will continue to be generated for the display of the corresponding step loop. This bar allows you to scroll between the lines of the internal table itab and to display the corresponding lines in the step loop. Each scrolling action triggers the event PAI. So that scrolling functions correctly, the addition AT itab must be specified both in the PBO as well as in the PAI processing block.
The additions CURSOR, INTO, TO, and FROM can only be specified in the PBO, not in the PAI processing block.
In the layout of a dynpro screen, there are two screen fields wa-col1 and wa-col2 belonging to a group of a step loop. The screen (dynpro) flow logic contains the following statements:
PROCESS BEFORE OUTPUT.
...
MODULE tab_init.
LOOP AT itab CURSOR top_line INTO wa.
ENDLOOP.
...
PROCESS AFTER INPUT.
...
MODULE get_first_line.
LOOP AT itab.
MODULE tab_in.
ENDLOOP.
...
Parallel loops are executed through the step loop and the internal itab table. At PBO, no dialog module is called in the loop. Instead, the module tab_init is called beforehand to edit the internal table itab. At PAI, the module tab_in is called in the loop to modify the internal table in accordance with the user specifications in the step loop. Beforehand, the module get_first_line is called in order to store the index of the first displayed table line in the help variable line. This is necessary since the content of top_line will be changed when the user scrolls further. The following program section shows the dialog modules of the corresponding ABAP program.
DATA: BEGIN OF wa,
col1 TYPE i,
col2 TYPE i,
END OF wa,
itab LIKE TABLE OF wa.
DATA: top_line TYPE i,
line TYPE i,
idx TYPE i.
...
MODULE tab_init OUTPUT.
IF itab IS INITIAL.
DO 40 TIMES.
wa-col1 = sy-index.
wa-col2 = sy-index ** 2.
APPEND wa TO itab.
ENDDO.
ENDIF.
ENDMODULE.
...
MODULE get_first_line INPUT.
line = top_line.
ENDMODULE.
MODULE tab_in INPUT.
idx = sy-stepl + line - 1.
MODIFY itab FROM wa INDEX idx.
ENDMODULE.