We can modify the table control at run time or we can provide additonal functionality to our ABAP Code like 'Inserting
blank lines' , 'sorting by column', 'deleting selected rows' ,'hiding certain columns' etc by setting the various fields of
the structure CXTAB_CONTROL in abap either in PBO or PAI.
ADDING BLANK LINES
To add blank lines to table control we do not need to change any of the fields of the structure CXTAB_CONTROL simply
adding blank lines to the internal table will do.
INSERT INITIAL LINE INTO itab.
SORTING BY COLUMN
We have to first determine which column of table control was selected for sorting.Then we have to determine the name
of the field from this information to use in SORT itab STABLE BY field command.
e.g.
DATA: col LIKE LINE OF tab_con-COLS "tab_con is name of table control,
"COLS field is an internal table of TYPE
"CXTAB_COLUMN
.This variable will
"be used to access column attributes of
"the
table control.
*We will read the column properties of selected column into col variable from
*collection of columns COLS.
*SELECTED is the field of structure CXTAB_COLUMN and indicates selection.
READ TABLE tab_con-COLS INTO col WITH KEY
selected = 'X' .
IF SY_SUBRC EQ 0.
*col-SCREEN-NAME(+offset) is used to determine the actual field name(like *PHONE) as*col-SCREEN-NAME will
return the screen name like ADDRESS-*PHONE.
*the value of offset depends upon the length of the name of the structure.
SORT itab STABLE BY col-SCREEN-NAME(+offset)
ENDIF.