Table Controls in ABAP Programs 

To handle table controls in ABAP programs, you must declare a control in the declaration part of the program for each table control using the following statement:

CONTROLS <ctrl> TYPE TABLEVIEW USING SCREEN <scr>.

where <ctrl> is the name of the table control on a screen in the ABAP program. The control allows the ABAP program to read the attributes of the table control and to influence the control. The statement also declares a deep structure of name <ctl>. The data type of the structure corresponds to the type CXTAB_CONTROL defined in the type group CXTAB in the ABAP Dictionary.

At runtime the components of the structure contain the attributes of the table control. Several of the initial values are determined in the Screen Painter. The initial value for the control <ctl> is taken from the screen which is determined using the addition USING.

If you write the statement

REFRESH CONTROL <ctrl> FROM SCREEN <scr>.

you can initialize a table control at any time with the initial value of a screen <scr>. Values that are not taken from the settings in the Screen Painter, are set to the current status of the table control at PAI.

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.

This graphic is explained in the accompanying text

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

Type (length)

Meaning

In the Screen Painter:

FIXED_COLS

I

Number of lead columns. Transferred from Screen Painter. Can be changed in the ABAP program.

Fixed columns

LINES

I

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 the LOOP statement for the table control.

 

TOP_LINE

I

Top row at next PBO. Set at PAI by position of the vertical slider box. Can be changed in the ABAP program.

 

CURRENT_LINE

I

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.

 

LEFT_COL

I

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 the user. Can be changed in the ABAP program.

 

LINE_SEL_MODE

I

Row 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.

Row selection

COL_SEL_MODE

I

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.

Column selection

LINE_SELECTOR

C(1)

Flag (X or blank) for selection column. Transferred from Screen Painter. Can be changed in the ABAP program.

Selection column

H_GRID

C(1)

Flag (X or blank) for horizontal separators. Transferred from Screen Painter. Can be changed in the ABAP program.

Separators

V_GRID

C(1)

Flag (X or blank) for vertical separators. Transferred from Screen Painter. Can be changed in the ABAP program.

Separators

COLS

CXTAB_COLUMN

Control table for single columns (see below).

 

INVISIBLE

C(1)

Flag (X or blank) for visibility of entire table control.

 

Internal table CXTAB_COLUMN is a component of the structure CXTAB_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

Type (length)

Meaning

SCREEN

SCREEN

Structure for the attributes of screen elements of the column (see below).

INDEX

I

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.

SELECTED

C(1)

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.

VISLENGTH

I

Visible length of the column. Transferred from Screen Painter. Can be changed in the ABAP program.

INVISIBLE

C(1)

Flag (X or blank) whether column is visible. Transferred from Screen Painter. Can be changed in the ABAP program.

The structure SCREEN is a column of the table CXTAB_COLUMN.

Components of SCREEN

The structure SCREEN contains the same components as system table

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 system table

SCREEN .

Scrolling in Table Controls

Scrolling with scroll bars is automatically implemented with table controls, and managed by the system. However, the component <ctl>-LINES must be set to the required row number before editing the table control. This is the case for table controls with or without parallel loops using an internal table. The component LINES is set implicitly for table controls with parallel loops using an internal table, although the correct value is not guaranteed (see table above). It is therefore recommended that in both instances you set the component LINES explicitly to the number of rows in the internal table of the ABAP program. You can determine this number from the statement DESCRIBE TABLE (see the following example).

The event PAI with an empty function code is triggered when scrolling using scroll bars. When the loops at PAI and PBO are executed, the system sets the component TOP_LINE of the structure CXTAB_CONTROL before PBO, so that the correct row is edited at the loop pass.

You can easily implement program-controlled vertical scrolling (line by line, page by page, or goto page) by using the component of the structure CXTAB_CONTROL. Essentially the component TOP_LINE must be provided with a value. For page by page scrolling, the number of rows to be scrolled during the loop pass can be taken from the system field SY-LOOPC. SY-LOOPC contains the number of rows currently display, whereas the component LINES of structure CXTAB_CONTROL contains the number of all rows in the table control.

Cursor Position on Table Controls

At PBO you can set the cursor on a specific field of a specific row of a table control.

SET CURSOR FIELD <f> LINE <lin> [OFFSET <off>].

Using the optional addition OFFSET, you can enter the offset of the cursor in the field as described under

Setting the Cursor Position .

At PAI you can read the current cursor position.

GET CURSOR FIELD <f> LINE <lin> ...

In addition to the information given under

Finding Out the Cursor Position , field <lin> contains information on which row of the table control the cursor is currently on. You can also use

GET CURSOR LINE <lin>.

if you only want to determine the row of the table control. SY´-SUBRC allows you to check if the cursor is placed in a row of a table control.

 

 

Leaving content frame