Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  User Dialogs →  Screens →  Statements in the Screen Flow Logic →  Table Controls 

LOOP - WITH CONTROL

Other versions: 7.31 | 7.40 | 7.54

Syntax


LOOP [AT itab [INTO wa] [CURSOR top_line] [FROM n1] [TO n2]] 
     WITH CONTROL contrl.
  ...
ENDLOOP.

Variants

1. LOOP WITH CONTROL contrl.

2. LOOP AT itab CURSOR cur [INTO wa]
       [CURSOR top_line] [FROM n1] [TO n2]
       WITH CONTROL contrl.

Effect

Definition of a loop in the dynpro flow logic, which is linked to a <DS:ABEN.TABLE_CONTROL_GLOSRY>table control contrl. The loop sequentially processes the presented rows of table control contrl by executing one loop pass per table control row. For contrl, you must directly specify the name of a table control of the dynpro. If the table control does not exist, the loop is ignored. The statement block between LOOP and ENDLOOP can contain the keywords FIELD, MODULE, CHAIN and ENDCHAIN of the flow logic. You cannot nest loops. You can execute loops either with or without reference to an internal table.

If table controls are defined in a dynpro, you must define one loop for each table control both in the PBO processing block and in the PAI processing block.

System Fields

Within the loop pass, the system field sy-stepl contains the number of the current table control row, started at the top visible row. The system field sy-loopc contains the total number of table control rows displayed on the screen.


Note

To link the loop to a table control, use the addition WITH CONTROL. The statement LOOP without this addition processes stand-alone step loops and is obsolete.

Variant 1

LOOP WITH CONTROL contrl.
  ...

ENDLOOP.

Effect

If the addition AT itab is not specified, during a loop pass the contents of the screen fields of the current row of table control contrl are transported from (at event PBO) or to (at event PAI) the data objects with the same names of the ABAP program. During PBO processing, the transport is done at the end of, during PAI processing at the beginning of the loop pass. The addition WITH CONTROL must be specified both at PBO and PAI.


Notes

  • For screen fields of the table control that are defined with a reference to the ABAP Dictionary, the data objects with the same names of the ABAP program must be declared exactly like normal screen fields with TABLES, otherwise there will be no data transport.
  • In the loop, you can call dialog modules to process the relevant data objects of the ABAP program. For example, you can read data from an internal table at PBO and write it back to this internal table at PAI, after processing it on the screen.

Variant 2

LOOP AT itab CURSOR cur [INTO wa]
     [CURSOR top_line] [FROM n1] [TO n2]

     WITH CONTROL contrl.
  ...
ENDLOOP.

Effect

If you specify addition AT itab, during loop processing of the table control the internal table itab of the corresponding ABAP program is processed sequentially in parallel. For each row of the table control, one row of the internal table is processed. The internal table itab must be an index table. You can specify the additions INTO, CURSOR, FROM, TO and WITH CONTROL only at PBO, but not at PAI. At PAI, the internal table is used for reference to the table control.

Use addition INTO to specify a work area wa, to which at PBO at the end of each loop pass the current row of the internal table is assigned. If you do not specify the addition wa, an internal table with header row must be used, which will then be used implicitly instead of wa. The content of wa or of the header row is transported after the assinment to the fields with the same names in the current row of the table control. The work area wa must be a global data object of the ABAP program matching the row type of the internal table. At the event PAI, only the work area wa or the header row of the internal table is filled with the content of the table control rows at the beginning of each loop pass. The content of the internal table is not automatically changed.

The syntax of additions CURSOR, FROM and TO is identical to the processing of step loops. When looping on table controls, you are allowed to use additions, but they are not really necessary, because the table controls are designed to be controlled by the structure of type CXTAB_CONTROL created via CONTROLS in the ABAP program. Here, top_line of component TOP_LINE corresponds to this structure while the number of rows to be displayed can be controlled using component LINES instead of n1 and n2. If n1 is still specified for table controls, the content of component CURRENT_LINE is calculated as follows, differing from the method shown at CONTROLS: sy-stepl+ (TOP_LINE - 1) + (n1 - 1).


Notes

  • For screen fields of the table control defined with a reference to flat structures in the ABAP Dictionary, the data objects with the same names of the ABAP program must be declared identically to normal screen fields using TABLES, otherwise there will be no data transport.
  • Between LOOP and ENDLOOP, at PBO no dialog module must be called to read the data from the internal table. At PAI, however, this is necessary provided you want to evaluate the transported data. For example, you can modify the internal table according to the user entries.

Example

If on the screen of a dynpro a table control FLIGHT_TAB is defined, the relevant flow logic may look like this. The loop is executed with reference to the internal table spfli_tab. At PBO, the loop calls a dialog module prepare_tab to fill the internal table. In the loop, at PBO no dialog module is called, because the table control in this case is filled automotically. At PAI, in the loop a dialog module modify_tab is called to store the changes the user entered in the table control in the internal table. You can find the relevant programming section of the ABAP program in the example for CONTROLS.

PROCESS BEFORE OUTPUT.
  MODULE prepare_tab.
  LOOP AT spfli_tab INTO spfli WITH CONTROL flight_tab.
  ENDLOOP.
PROCESS AFTER INPUT.
  LOOP AT spfli_tab.
    MODULE modify_tab.
  ENDLOOP.

Continue

ENDLOOP