Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  SAP GUI User Dialogs →  General Dynpros →  Statements in the Dynpro 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.
  TRY.
      demo_conn = itab[ flights-current_line ].
    CATCH cx_sy_itab_line_not_found.
      RETURN.
  ENDTRY.
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 += 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 += 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 dictionary. The first two columns are lead columns. The corresponding fields are output fields. A title bar, columns headers, and a selection column are created. The selection column is assigned to the component MARK, of the type CHAR, length 1, from the structure DEMO_CONN. One column and one or more rows can be selected.

The flow logic of dynpro 100 is given one loop executed at PBO time and another loop executed at PAI time 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 matches the current row of the table control are overwritten by the content of the work area demo_conn. User input is passed from the input fields of the control 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, user input is processed in the module user_command_0100. The GUI status SCREEN_100 enables the corresponding function codes. Both row-by-row and page-by-page scrolling is possible and it is also possible to jump to the first or last page. Scrolling is enabled by setting the component top_line of the control structure flights. As an increment, page-by-page scrolling uses the helper variable filled in the PAI loop using sy-loopc.