ABAP Keyword Documentation → ABAP - Reference → User Dialogs → Dynpros → Statements in the Screen Flow Logic → Table Controls → Table Control - Examples
Table Control with Modifications
This example demonstrates sorting by columns and how rows are deleted in table controls.
Other versions: 7.31 | 7.40 | 7.54
Source Code
REPORT demo_dynpro_tabcont_loop_at.
CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.
DATA: cols LIKE LINE OF flights-cols,
lines TYPE i.
DATA: ok_code TYPE sy-ucomm,
save_ok TYPE sy-ucomm.
DATA: itab TYPE TABLE OF demo_conn.
TABLES demo_conn.
SELECT *
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE @itab
##TOO_MANY_ITAB_FIELDS.
LOOP AT flights-cols INTO cols WHERE index GT 2.
cols-screen-input = '0'.
MODIFY flights-cols FROM cols INDEX sy-tabix.
ENDLOOP.
CALL SCREEN 100.
MODULE status_0100 OUTPUT.
SET PF-STATUS 'SCREEN_100'.
DESCRIBE TABLE itab LINES lines.
flights-lines = lines.
ENDMODULE.
MODULE cancel INPUT.
LEAVE PROGRAM.
ENDMODULE.
MODULE read_table_control INPUT.
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 'TOGGLE'.
LOOP AT flights-cols INTO cols WHERE index GT 2.
IF cols-screen-input = '0'.
cols-screen-input = '1'.
ELSEIF cols-screen-input = '1'.
cols-screen-input = '0'.
ENDIF.
MODIFY flights-cols FROM cols INDEX sy-tabix.
ENDLOOP.
WHEN 'SORT_UP'.
READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
IF sy-subrc = 0.
SORT itab STABLE BY (cols-screen-name+10) ASCENDING.
cols-selected = ' '.
MODIFY flights-cols FROM cols INDEX sy-tabix.
ENDIF.
WHEN 'SORT_DOWN'.
READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
IF sy-subrc = 0.
SORT itab STABLE BY (cols-screen-name+10) DESCENDING.
cols-selected = ' '.
MODIFY flights-cols FROM cols INDEX sy-tabix.
ENDIF.
WHEN 'DELETE'.
READ TABLE flights-cols INTO cols WITH KEY screen-input = '1'.
IF sy-subrc = 0.
LOOP AT itab INTO demo_conn WHERE mark = 'X'.
DELETE itab.
ENDLOOP.
ENDIF.
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.
In the flow logic of dynpro 100, one loop is executed at PBO time and another loop is executed at PAI
time using the table control flights
and the internal table itab
of the ABAP program at the same time. In the PBO loop, no module is called to fill the table control
from the table itab
of the ABAP program. However, during the PAI loop, a module is called to modify table itab
.
At PBO, the component lines
of the control structure flights
is filled explicitly with the current number of rows in internal table itab
to configure the scroll bar of the table control before the PBO loop.
In the PAI loop, the rows of the internal table with row indexes that match the current table control
rows 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, the user input is processed in the module user_command_0100
. The GUI status SCREEN_100 enables the corresponding function codes.
When the program is called not all of the fields in the table control are ready for input. The static
specifications of the table control in the Screen Painter are modified before CALL
SCREEN in the program. The system uses the table cols
in control structure
flights
. All columns with a column position greater than two are set to not
ready for input using a loop across the table flights-cols
. By selecting the function code TOGGLE, the input readiness of these fields can be switched on and off.
Using the function codes "SORT_UP" and "SORT_DOWN",
it is possible to sort the columns of the internal table itab
in either ascending
or descending order. The static settings of the table control allow only a single column to be selected.
The selected column is removed from the internal table flights-cols
. The
name of the sort criterion in the SORT
statement is determined dynamically
from the component cols-screen-name
. The prefix demo_conn
must be removed by specifying an offset. After the sort, the selection is canceled and the component selected
in the table flights-cols
is assigned a blank character.
Using the function code "DELETE", it is possible to delete selected rows
from the internal table itab
. First the system checks in flights-cols
whether the fields of the table control are ready for input. Then all selected rows are deleted in a
loop using the internal table itab
. Since the table control is filled completely
from the internal table itab
during the PBO loop, the rows are also deleted on the screen.