Table Controls
Table Controls
The following example processes a table control with LOOP with parallel loop using an internal table. By using function codes you can sort columns and delete rows from the internal table. The ready for input status of the table control fields is controlled using a function 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. 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. The layout of screen 100 is:
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, columns 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 AT itab INTO demo_conn WITH CONTROL flights. ENDLOOP. PROCESS AFTER INPUT. MODULE cancel AT EXIT-COMMAND. LOOP AT itab. MODULE read_table_control. ENDLOOP. MODULE user_command_0100. A loop is executed at PBO and PAI using the table control FLIGHTS and is also executed using the internal table ITAB of the ABAP program. During the PBO loop, no module is called to fill the table control from 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 control structure FLIGHTS is filled explicitly with the current number of rows of the internal table before the PBO loop to 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, 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. 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 larger than two are set to not ready for input status in a loop using the table FLIGHTCOLS. By choosing the function code TOGGLE, you can change the ready for input status of the columns. The function codes SORT_UP and SORT_DOWN allow you to sort selected columns of the internal table ITAB ascending or descending. The static settings of the table control allow you to select only a single column. The selected column is derived from the internal table FLIGHT-COLS. The name of the sort criteria in the SORT statement is determined dynamically from the component COLSSCREEN-NAME. The prefix DEMO_CONN- must be removed using an offset specification. After sort the selection is undone, and the component SELECTED in table FLIGHT-COLS is assigned a blank character. You can delete selected rows from the internal table ITAB using the function code DELETE. First the system checks 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 read again from the internal table in the PBO loop, the rows on the screen are deleted.
ZTBLDTOP
*&---------------------------------------------------------------------* *& Include ZTBLDEMO *& Report ZTBLDEMO * *
*&---------------------------------------------------------------------*
REPORT
ZTBLDEMO
MESSAGE-ID AT
ZTBLDEMO
*&---------------------------------------------------------------------* *& Report *& ZUSRDATA * *
*&---------------------------------------------------------------------*
INCLUDE ZTBLDTOP.
* * *
*&---------------------------------------------------------------------* * text
*----------------------------------------------------------------------* MODULE STATUS_0100 OUTPUT. SET PF-STATUS 'FOR100'. SET TITLEBAR '100'. ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------* * text
*----------------------------------------------------------------------* MODULE DISPLAY_USERDATA OUTPUT. READ TABLE ITAB_PHONELIST INDEX TCTRL_PHONELIST-CURRENT_LINE. IF SY-SUBRC EQ 0. RECORD-NAME = ITAB_PHONELIST-NAME. RECORD-PHONE = ITAB_PHONELIST-PHONE. RECORD-EMAIL = ITAB_PHONELIST-EMAIL. ELSE.
*&---------------------------------------------------------------------* * text
*----------------------------------------------------------------------* MODULE USER_COMMAND_0100 INPUT. SAVE_CODE = OK_CODE. CLEAR OK_CODE. CASE SAVE_CODE. WHEN 'BACK'. CALL FUNCTION 'COPO_POPUP_TO_GOON' EXPORTING TEXTLINE1 = 'Any modifications will be lost!' TEXTLINE2 = 'Are you sure?' TITEL IMPORTING answer = confirmation. = 'Exit The Program'
if confirmation = 'G'. LEAVE PROGRAM. ENDIF. WHEN 'DELE'. CALL FUNCTION 'COPO_POPUP_TO_GOON' EXPORTING TEXTLINE1 = 'Selected rows will be deleted!' TEXTLINE2 = 'Are you sure?'
= 'Delete rows'
= confirmation.
IF CONFIRMATION = 'G'. REFRESH ITAB_PHONELIST. CLEAR ITAB_PHONELIST. ENDIF. WHEN 'SAVE'. REFRESH ITAB_PHONELIST. CLEAR ITAB_PHONELIST. WHEN 'APND'. REFRESH ITAB_PHONELIST. CLEAR ITAB_PHONELIST. WHEN 'READ'. IF NOT FILENAME IS INITIAL. CALL FUNCTION 'COPO_POPUP_TO_GOON' EXPORTING TEXTLINE1 = 'Any modifications will be lost!' TEXTLINE2 = 'Are you sure?' TITEL IMPORTING answer ENDIF. if confirmation = 'G' or FILENAME IS INITIAL. CALL FUNCTION 'UPLOAD' EXPORTING FILENAME = = confirmation. = 'Read Another File'
'c:\temp\fonelist.txt' IMPORTING ACT_FILENAME TABLES DATA_TAB ENDIF. ENDCASE. ENDMODULE. " USER_COMMAND_0100 INPUT = ITAB_PHONELIST. = FILENAME
*&---------------------------------------------------------------------* * text
*----------------------------------------------------------------------* MODULE EXTRACT_USERDATA INPUT. CASE SAVE_CODE. WHEN 'DELE'. IF SELECTION IS INITIAL AND confirmation = 'G'. PERFORM TRANSFER. ENDIF. WHEN 'SAVE'. PERFORM TRANSFER. WHEN 'APND'. PERFORM TRANSFER. ENDCASE. ENDMODULE. " EXTRACT_USERDATA INPUT
*&---------------------------------------------------------------------* * text
*----------------------------------------------------------------------* FORM TRANSFER. CLEAR ITAB_PHONELIST. ITAB_PHONELIST-NAME = RECORD-NAME. ITAB_PHONELIST-PHONE = RECORD-PHONE. ITAB_PHONELIST-EMAIL = RECORD-EMAIL. APPEND ITAB_PHONELIST. ENDFORM. " TRANSFER
*&---------------------------------------------------------------------* * text
*----------------------------------------------------------------------* MODULE USER_COMMAND_0100_AFTER_LOOP INPUT. CASE SAVE_CODE. WHEN 'SAVE'. CALL FUNCTION 'DOWNLOAD' EXPORTING FILENAME TABLES DATA_TAB WHEN 'APND'. CLEAR ITAB_PHONELIST. " a blank row being created. = ITAB_PHONELIST. = FILENAME
APPEND ITAB_PHONELIST. " a blank row being added. ENDCASE. ENDMODULE. " USER_COMMAND_0100_AFTER_LOOP INPUT
Field List
GUI Status
Objects
Table Attributes
Table Columns
Structure CXTAB_CONTROL
The deep structure CXTAB_CONTROL contains the general attributes of the table control on the highest level. The component CXTAB_CONTROL is a table of the structure CXTAB_COLUMN and contains the attributes of a column. The component CXTAB_CONTROL-COLS-SCREEN is a flat structure of the same type as system table screen and contains the attributes of the individual screen elements.
Up to component CURRENT_LINE, all attributes of the structure CXTAB_CONTROL in the ABAP program can be set to change the table control display on the screen.
Components of CXTAB_CONTROL
The structure CXTAB_CONTROL has the following components: Component FIXED_COLS Type (Length) INT4 Meaning In the Screen Painter:
Number of lead columns. Transferred Fixed columns from Screen Painter. Can be changed in the ABAP program. Controls the scroll bar of the table control. At LOOP without internal table, LINES has the initial value zero and must be set in the program so that the scroll bar can be used. At LOOP AT itab the system sets this component to the number of rows of the internal table, whenever the table control is processed for the first time. The initialization event of a table control is not determined uniquely. If the corresponding internal table is not fully created at this event, then the LINES variable receives an incorrect value. If LINES in the LOOP loop is smaller as the number of rows of the internal table, then the table control contains blank rows at the end. Therefore you should always set the LINES component explicitly in the ABAP program, including at LOOP AT itab. In this way you have full control over the dimensions of the vertical scroll bar and so can control the number of rows that are ready for input. Initialization should usually occur at PBO directly before theLOOP statement for the table control. Top row at next PBO. Set at PAI by position of the vertical slider box. Can be changed in the ABAP program. Current line in the loop. Set automatically in the LOOP loop to the value sy-stepl+(TOP_LINE-1). No changes allowed in the ABAP program. First displayed horizontal scrollable column after the lead column. Set at PAI by position of the horizontal slider box. LEFT_COL contains the absolute number of the column independent of any column shift by
LINES
INT4
TOP_LINE
INT4
CURRENT_LINE
INT4
LEFT_COL
INT4
the user. Can be changed in the ABAP program. LINE_SEL_MODE INT4 Row selection mode: 0, 1, 2 for none, Row selection one or multiple rows can be selected. Transferred from Screen Painter. Can be changed in the ABAP program. Column selection mode: 0, 1, 2 for none, one or multiple rows can be selected. Transferred from Screen Painter. Can be changed in the ABAP program. Flag (X or blank) for selection column. Transferred from Screen Painter. Can be changed in the ABAP program. Column selection
COL_SEL_MODE
INT4
LINE_SELECTOR
CHAR(1)
Selection column
H_GRID
CHAR(1)
Flag (X or blank) for horizontal Separators separators. Transferred from Screen Painter. Can be changed in the ABAP program. Flag (X or blank) for vertical Separators separators. Transferred from Screen Painter. Can be changed in the ABAP program.
V_GRID
CHAR(1)
COLS INVISIBLE
CXTAB_COLUMN Control table for single columns (see below). CHAR(1) Flag (X or blank) for visibility of entire table control.
Components of CXTAB_COLUMN
Each column of the table control corresponds to a row of the table CXTAB_COLUMN. The internal table CXTAB_COLUMN has no header line and the following columns: Component SCREEN INDEX Type (Length) SCREEN INT4 Meaning Structure for the attributes of screen elements of the column (see below). Current position of the column in the table control. Transfered with initial value from Screen Painter. At PAI the current column configuration of the table control is withdrawn. Can be changed in the ABAP program. Flag (X or blank) whether column is selected or not. At PAI the current status of the table control is withdrawn. Can be changed in the ABAP program. Visible length of the column. Transferred from Screen Painter. Can be changed in the ABAP program. Flag (X or blank) whether column is visible. Transferred from Screen Painter. Can be changed in the ABAP
SELECTED
CHAR(1)
VISLENGTH INVISIBLE
INT4 CHAR(1)
Components of SCREEN
The component SCREEN-NAME is the name of the screen element that creates the column. The initial values of the remaining components correspond to the attributes of the screen elements in the Screen Painter. The attributes are transferred from here with initial values. They can be changed directly in the ABAP program. Note that directly set values can be overwritten by modifying these attributes using MODIFY SCREEN within the loop LOOP AT SCREEN. Furthermore, note that the attributes of the structure screen are not set with blank characters and X, but are set with 0 and 1 as in the normal processing of screen.