Entering content frameTable Controls: Examples with Scrolling Locate the document in its SAP Library structure

The following example processes a table control with LOOP without parallel loop using an internal table. In addition to the scroll bar, the user can also carry out program-controlled scrolling with function codes.

Example

REPORT demo_dynpro_tabcont_loop.

CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.

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

DATA: itab TYPE TABLE OF demo_conn,
      fill TYPE i.

      TABLES demo_conn.

DATA: lines TYPE i,
      limit TYPE i.

SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.

CALL SCREEN 100.

MODULE status_0100 OUTPUT.
  SET PF-STATUS 'SCREEN_100'.
  DESCRIBE TABLE itab LINES fill.
  flights-lines = fill.
ENDMODULE.

MODULE fill_table_control OUTPUT.
  READ TABLE itab INTO demo_conn INDEX flights-current_line.
ENDMODULE.

MODULE cancel INPUT.
  LEAVE PROGRAM.
ENDMODULE.

MODULE read_table_control INPUT.
  lines = sy-loopc.
  MODIFY itab FROM demo_conn INDEX flights-current_line.
ENDMODULE.

MODULE user_command_0100 INPUT.
  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'NEXT_LINE'.
      flights-top_line = flights-top_line + 1.
      limit = fill - lines + 1.
      IF flights-top_line > limit.
        flights-top_line = limit.
      ENDIF.
    WHEN 'PREV_LINE'.
      flights-top_line = flights-top_line - 1.
      IF flights-top_line < 0.
        flights-top_line = 0.
      ENDIF.
    WHEN 'NEXT_PAGE'.
      flights-top_line = flights-top_line + lines.
      limit = fill - lines + 1.
      IF flights-top_line > limit.
        flights-top_line = limit.
      ENDIF.
    WHEN 'PREV_PAGE'.
      flights-top_line = flights-top_line - lines.
      IF flights-top_line < 0.
        flights-top_line = 0.
      ENDIF.
    WHEN 'LAST_PAGE'.
      flights-top_line =  fill - lines + 1.
    WHEN 'FIRST_PAGE'.
      flights-top_line = 0.
  ENDCASE.
ENDMODULE.

The layout of screen 100 is:

This graphic is explained in the accompanying text

A resizable table control called FLIGHTS is defined. The fields of the table control are transferred from the structure DEMO_CONN in the ABAP Dictionary. The first two columns are lead columns. The corresponding fields are output fields. A title bar, column headers, and a selection column are created. The component MARK of type character with length 1 from structure DEMO_CONN is assigned to the selection column. You can select one column and several lines.

It has the following flow logic:

PROCESS BEFORE OUTPUT.
  MODULE status_0100.
  LOOP WITH CONTROL flights.
    MODULE fill_table_control.
ENDLOOP.

PROCESS AFTER INPUT.
  MODULE cancel AT EXIT-COMMAND.
  LOOP WITH CONTROL flights.
    MODULE read_table_control.
ENDLOOP.
  MODULE user_command_0100.

The system executes a loop at PBO and PAI using the table control FLIGHTS. During the PBO loop, a module is called to fill the table control from table ITAB of the ABAP program. During the PAI loop, a module is called to modify table ITAB.

Before the PBO loop, in the module STATUS_0100 the current number of lines of the internal table ITAB is placed in component LINES of control structure FLIGHTS. This helps the system to correctly install the scroll bar of the table control.

During the PBO loop, in the module FILL_TABLE_CONTROL the work area DEMO_CONN is filled with values from the internal table, where the row index corresponds to the current row of the table control.

During the PAI loop, in the module READ_TABLE_CONTROL the current number of the loop SY-LOOPC in the table control is placed an auxiliary variable. The number is dependent on the size of the screen. The rows of the internal table, whose row index corresponds to the current row of the table control, are overwritten with the contents of the work area DEMO_CONN. User input is transferred from the input fields of the control to the internal table. In particular, the internal table also contains a flag in the column MARK to indicate whether the row of the table control is selected or not.

After the PAI loop, user input is processed in the module USER_COMMAND. The GUI status SCREEN_100 provides the appropriate function codes. You can scroll line by line or page by page, or Goto the first or last page. You can implement scrolling by setting the component TOP_LINE of control structure FLIGHTS. For page-by-page scrolling the auxiliary variable that is filled in the PAI loop by SY-LOOPC is used as the step size.

 

 

Leaving content frame