Skip to content

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

Table Control with Scrolling

This example demonstrates program driven scrolling in table controls.

Other versions: 7.31 | 7.40 | 7.54

Source Code

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
       ##too_many_itab_fields.

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.
  demo_conn = itab[ 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.

Description

The table control flights is defined and can be resized. The fields of the table control are copied from the DEMO_CONN structure in the ABAP Dictionary. The first two columns are lead columns. The corresponding fields are output fields. A title list, column headers, and a selection column are available. The selection column is assigned component MARK, of type CHAR, length 1, from the structure DEMO_CONN. One column and multiple rows can be selected.

In the flow logic of screen 100, one loop is executed in the PBO and another in the PAI using the table control flights. In the PBO loop, a module is called to fill the table control from table itab of the ABAP program. In the PAI loop, a module is called to modify table itab.

Before the PBO loop, the current number of rows in the internal table itab in the component lines of the control structure flights is stored in the status_0100 module. This means the system can set up the scroll bar properly.

In the PBO loop, in the fill_table_control module, work area demo_conn is filled with values from the internal table; the row index corresponds to the actual table control row.

In the PAI loop, in the read_table_control module, the current number of loops sy-loopc in the table control is stored in an auxiliary variable. This number depends on the screen size. The row of the internal table with the row index that corresponds to the current table control row is overwritten by the contents of the work area demo_conn. In this way, user entries in the input fields of the control are copied to the internal table. A flag is set in the column MARK of the internal table indicating whether the table control row is selected or not.

After the PAI loop, the user entries are processed in module user_command_0100. The GUI status SCREEN_100 enables the corresponding function codes. It is possible to scroll vertically and horizontally, and to jump to the first or last page. Scrolling is enabled by setting component top_line of the control structure flights. For horizontal scrolling, the auxiliary variable filled in the PAI loop using sy-loopc is used as the increment.