Entering content frame

Appendix: The Step Loop Technique Locate the document in its SAP Library structure

Table controls are processed using the step loop technique.

Step loops are the predecessors of table controls. They should no longer be used. Existing step loops can be changed to table controls in the Screen Painter. For the sake of completeness and to explain the technique of data transfer between tables on the screen and the ABAP program, step loops - and specifically the step loop technique - are explained here.

Like table controls, step loops are screen elements for displaying table-type data on a screen. From a programming standpoint, especially concerning the data transfer, table controls and step loops are almost identical. Table controls are ultimately an improvement of step loops, in terms of usability by the end user.

Defining Step Loops

A step loop is defined in the Structure linkScreen Painter. Screen elements, which unlike table controls can be spread over a number of lines, are combined into one group that repeats itself several times within the step loop. The attributes of the screen elements of the first group define the attributes of the whole step loop. The fields of a group only appear once in the field list of the corresponding screen. Therefore, you only have to create them once in ABAP programs. A screen can have more than one step loop. However, as screen elements, step loops do not have individual names.

In the Structure linkScreen Painter, you can define whether the size of a step loop is fixed or variable. The vertical size of variable step loops changes if the user changes the vertical size of the window. For every screen, you can define any number of fixed step loops but only one variable step loop. Every vertical size change triggers PAI if a variable step loop is defined on the screen. For fixed step loops the number of repetition groups is predefined.

Processing Step Loops

When processing step loops (step loop technique), loops are executed in the screen flow logic. The relevant commands in the flow logic are:

LOOP ...
  ...
ENDLOOP.

These statements must not be confused with the ABAP statements of the same names. Between LOOP and ENDLOOP, you can use the other flow logic keywords FIELD, MODULE, SELECT, VALUES, and CHAIN. At least one empty LOOP must exist for every step loop, both in the PBO and the PAI processing block. During the loops, the contents of the step loop are transported back and forth between identically-named fields of the ABAP program and the screen. Note that step loop fields defined with Dictionary reference must be defined in the ABAP program, as before, with TABLES as interface work areas.

The order the step loops are processed in the individual loops of the flow logic depends on the step loop order on the screen. The order on the screen depends primarily on the lines and secondarily on the rows.

The number of step loop rows displayed can change if the size of the table displayed is variable and the user changes the window height. In this case, you can transfer different numbers of lines to the ABAP program for individual PAI events.

The same as for table controls applies for the flow of data transport and the cursor position. The system fields sy-stepl and sy-loopc are also filled within the loops.

We differentiate between two loop techniques.

Loop Through the Lines of the Step Loop

The commands in the flow logic are:

LOOP.
  ...
ENDLOOP.

These statements create a loop pass through the step loop rows displayed on the screen and for PAI transfer the data of each group into the identically-named fields of the ABAP program, or for PBO from the ABAP program into the step loop fields. In the LOOP-ENDLOOP loop, you can call modules that process the transferred data and for PBO read from an internal table, or for PAI place in an internal table.

With this form of processing, the step loop display does not contain scroll bars. If you wish to be able to scroll, this must be specified in the ABAP program.

Parallel Loops Through Step Loops and an Internal Table

The commands in the flow logic are:

LOOP AT itab CURSOR c [INTO wa] [FROM n1] [TO n2].
  ...
ENDLOOP.

These statements create a parallel loop pass through the step loop rows displayed on the screen and an internal table itabof the ABAP program. The additions INTO, CURSOR, and FROMare possible at the time of PBO, but not at PAI.

With this form of processing, the step loop display contains scroll bars. The scroll function is automatically defined by the system. The step loop rows, between which you can scroll, is copied over from the internal table in the ABAP program. Scrolling triggers the PAI event.

The CURSOR addition is used to control, at the time of PBO, which internal table row should be the first to appear in the screen display. c is a data object of the ABAP program of type i. Conversely, for every PAI event, c is set to the value of the first table row displayed. This allows you to synchronize the internal table of the ABAP program with the step loop rows displayed. It is recommended that you place c into an auxiliary variable at the start of PBO and do not evaluate it in the loop, because scrolling changes the value of c.

Using the INTO addition, the fields of the internal table itab are written to the work area wa at the time of PBO and the content of wa is transported line-by-line to the identically-named fields of the step loop on the screen. Without the INTO addition, you must use an internal table with a header line. Then the content of the header line is transported line-by-line to the identically-named fields of the step loop on the screen at the time of PBO. A module for filling the step loop rows is therefore not necessary.

Conversely, at the time of PAI, the internal table rows are not automatically filled with the contents of the step loop rows. Instead, you must call a module that fills the table within the loop. However, you must still specify the addition AT itab at the time of PAI, because otherwise scrolling with the scroll bars does not work.

You can use the FROM and TOadditions to limit the display or work area of the internal table in the step loop. n1 and n2are data objects of the ABAP program with type i. If you do not specify these parameters, the system uses the start and/or end of the internal table as the display or processing limit. If c is outside the limits n1 and n2, the latter take precedence.

The additions CURSOR c and FROM n1 TO n2 of the LOOP AT statement, which specify the starting line and number of displayed rows of the internal table for step loops, are possible with Table Controls in the Flow Logic, but not necessary. With TABLE CONTROLS, the display is controlled by using the structure CXTAB_CONTROL in the ABAP program.

·        Instead of the CURSOR c, you should always use the component TOP_LINE for table controls. This component always contains the upper-most displayed row.

·        If you also specify n1 for table controls, the calculation formula for the component CURRENT_LINE is changed to sy-stepl + (TOP_LINE -1) + (n1 - 1).

Example

Example

REPORT demo_dynpro_step_loop.

TYPES: BEGIN OF t_itab,
         col1 TYPE i,
         col2 TYPE i,
       END OF t_itab.

DATA: itab TYPE STANDARD TABLE OF t_itab,
      wa   LIKE LINE OF itab,
      fill TYPE i.

DATA: idx   TYPE i,
      line  TYPE i,
      step  TYPE i,
      limit TYPE i,
      c     TYPE i,
      n1    TYPE i VALUE 5,
      n2    TYPE i VALUE 25.

DATA:  ok_code TYPE sy-ucomm,
       save_ok TYPE sy-ucomm.

START-OF-SELECTION.

  DO 40 TIMES.
    wa-col1 = sy-index.
    wa-col2 = sy-index ** 2.
    APPEND wa TO itab.
  ENDDO.

  DESCRIBE TABLE itab LINES fill.

  CALL SCREEN 100.

MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS_100' EXCLUDING 'PREVIOUS'.
ENDMODULE.

MODULE status_0200 OUTPUT.
  SET PF-STATUS 'STATUS_200' EXCLUDING 'NEXT'.
ENDMODULE.

MODULE transp_itab_out OUTPUT.
  idx = sy-stepl + line.
  READ TABLE itab INTO wa INDEX idx.
ENDMODULE.

MODULE transp_itab_in INPUT.
  step = sy-loopc.
  idx = sy-stepl + line.
  MODIFY itab FROM wa INDEX idx.
ENDMODULE.

MODULE user_command_0100 INPUT.
  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'NEXT_LINE'.
      line = line + 1.
      limit = fill - step.
      IF line > limit.
        line = limit.
      ENDIF.
    WHEN 'PREV_LINE'.
      line = line - 1.
      IF line < 0.
        line = 0.
      ENDIF.
    WHEN 'NEXT_PAGE'.
      line = line + step.
      limit = fill - step.
      IF line > limit.
        line = limit.
      ENDIF.
    WHEN 'PREV_PAGE'.
      line = line - step.
      IF line < 0.
        line = 0.
      ENDIF.
    WHEN 'LAST_PAGE'.
      line =  fill - step.
    WHEN 'FIRST_PAGE'.
      line = 0.
    WHEN 'NEXT'.
      c = line + 1.
      LEAVE TO SCREEN 200.
  ENDCASE.
ENDMODULE.

MODULE get_first_line INPUT.
  line = c - 1.
ENDMODULE.

MODULE user_command_0200 INPUT.
  save_ok = ok_code.
  CASE save_ok.
    WHEN 'PREVIOUS'.
      LEAVE TO SCREEN 100.
  ENDCASE.
ENDMODULE.

MODULE cancel INPUT.
  LEAVE PROGRAM.
ENDMODULE.

The layout of screen 100 is:

This graphic is explained in the accompanying text

A variable step loop with 10 initial repetition groups is defined. The fields of the repetition groups are the components col1and col2 of the structure wa of the ABAP program.

The flow logic of screen 100 is:

PROCESS BEFORE OUTPUT.
  MODULE status_0100.
  LOOP.
    MODULE transp_itab_out.
  ENDLOOP.

PROCESS AFTER INPUT.
  MODULE cancel AT EXIT-COMMAND.
  LOOP.
    MODULE transp_itab_in.
  ENDLOOP.
  MODULE user_command_0100.

In the status STATUS 100, the function codes FIRST_PAGE, PREV_PAGE, PREV_LINE, NEXT_LINE, NEXT_PAGE, LAST_PAGE, and NEXT have been assigned to pushbuttons on the application toolbar for screen 100.

The layout of screen 200 is the same as that of screen 100, except that step loop is not variable, but fixed.

The flow logic of screen 200 is:

PROCESS BEFORE OUTPUT.
  MODULE status_0200.
  LOOP AT itab INTO wa CURSOR c FROM n1 TO n2.
  ENDLOOP.

PROCESS AFTER INPUT.
  MODULE cancel AT EXIT-COMMAND.
  MODULE get_first_line.
  LOOP AT itab.
    MODULE transp_itab_in.
  ENDLOOP.
  MODULE user_command_0200.

In the status STATUS 200, the function code PREVIOUS is assigned to a pushbutton of the application toolbar for screen 200.

If you execute the program, the system displays a step loop on screen 100, whose line number has been adjusted to fit the height of the screen but has no vertical scroll bars. On screen 200, the system displays a step loop with a fixed line number of 10 and a vertical scroll bar.

At the time of PBO, both step loops are filled from the internal table itab. For screen 100 the loop is only through the step loop and for screen 200 it is parallel through the step loop and the internal table. The step loop on screen 200 is restricted to the lines 5 to 25 of the internal table. While for screen 100 a PBO module is called to fill the work area WA, this is not necessary for screen 200.

At the time of PAI, a module is called in both screens within the loops. In this module, the system transfers possible user entries in the step loop rows to the corresponding rows of the internal table.

For screen 100, the scrolling function of the step loop is programmed in the PAI module USER_COMMAND_100. For this, the number of rows of the step loop on the screen is buffered in the auxiliary variable step, because sy-loopc is only filled within the loop. You do not need to program a scrolling function for screen 200, because it is automatically provided by the system in the form of the scroll bar.

The synchronization between the internal table and the step loop on screen 200 is dealt with by the variable c, which is used in the CURSORaddition to the LOOP statement. It is set before the call of screen 200 in correspondence with the display of the table on screen 100. At the time of PAI of screen 200, c is read to redefine first table row after any scrolling with the scroll bar.

 

Leaving content frame