Você está na página 1de 8

Module Pool basics Go to start of metadata TABLE CONTROL

These are the screen elements used to display tabular data they can be called as screen tables (like STEP LOOP). To use table control we have to create it on the screen using SCREEN PAINTER (SE51) and declare a control variable of TYPE TABLEVIEW using CONTROLS statement in the ABAP program. We have to use LOOP... ENDLOOP statement in both PBO and PAI with or without AT int_table parameter. IF AT int_table parameter is not used than we have to place a MODULE call between the LOOP...ENDLOOP statement to fill the screen table rows from the ABAP program in PBO and program our own scrolling functions 1using OK_CODE field. Having a parallel loop(at screen table rows and int table rows) by using parameter AT int_table makes the ABAP code simple. A special structure of type CXTAB_CONTROL is used to set/get various attributes of table control at runtime like CURRENT_LINE ,TOP_LINE. a) ATTRIBUTES and CREATION Table control can be created in tow ways either by selecting the table control icon from the elements toolbar or by using table control wizard in SE51 and drawing a table control area on the screen.. If we use table control wizard it takes mimimum of coding and effort to create a workable table control.The wizard uses 7 dialogs .ABAP Code and screen flow logic statements are automatically generated for common functions like inserting new lines,selecting rows etc. In table control attributes we check/uncheck 1) horizontal/vertical separators. 2) with title ,if with title the name of the field. 3) with column headers 4) We have to select from single/multiple/none selection for rows and columns. 5) If Line selection column is to be used than the name of the Line Selection Column field is

specified. This field is of type C(1) and can be used to determine which record(s) were selected by the user in PAI. A field of this name and type is generally the part of the internal table which will be used to display the data if multiple row selection has been checked in the attribute box,for a single line row selection a declaration in ABAP program with the same name and type is sufficient. 6) The number of fixed columns can be specified.They can be changed dynamically in ABAP program using tab_con-FIXED_COLS attribute. Columns on Table Control The columns on table control are generally taken from the structure which is of same type as internal table used for displaying values in the ABAP program. b) CXTAB_CONTROL

When we create a control variable of type TABLEVIEW by using CONTROLS statement in ABAP to access table control from within ABAP, the control variable created is of deep structure type CXTAB_CONTROL.This structure itself consists of a structure (or line) of type CXTAB_COLUMN which represents the columns found on the table control and can be used to modify column properties. These structures are defined in type group CXTAB. By changing or reading various fields of these structures we can modify the behavior of table control at run time in general and its columns. e.g. To make a particular record as the top record in the table control we can use the field TOP_LINE of the structure CXTAB_CONTROL. tab_con-TOP_LINE = 5 " here tab_con is the name of the table control. Some of the useful fields of the structure CXTAB_CONTROL are: LINES This field or attribute is used to specify the total number of records the table control will be showing and according to SAP must be filled explicitly before any LOOP ... ENDLOOP statement .LINES field having a correct value ensures automatic and correct scrolling. It is of TYPE I. TOP_LINE

This field indicates the index of the record being shown in the top of the table control.It is of TYPE I.This field is used often for extended or self scrolling functions. CURRENT_LINE This field specifies the index of the current record being processed in the screen loop statement.It cannot be changed and its value is set by the system.It is of TYPE I.This field is used to determine the index and then used in PBO or PAI to read the internal table or to modify the internal table.e.g. READ TABLE itab INTO workarea INDEX tab_con-CURRENT_LINE. MODIFY TABLE itab FROM workarea INDEX tab_con-CURRENT_LINE.

FIXED_COLS This field is used to change the number of lead columns(fixed) in table control at runtime.It is of TYPE I. LEFT_COL This field is used to speify the first column that can be horizontallyy scrolled from the lead columns.It is of TYPE I. INVISIBLE This field can be used to hide or make visible the entire table control at run time.It is of TYPE C(1) and can have value of 'X' or ' '. COLS This field is used to modify various column attributes at run time and represents the collection of all the columns in the table control.It is of TYPE CXTAB_COLUMN which is an internal table without header line. CXTAB_COLUMN To access and modify the columns of the table control at run time w have to use the fields of the structure CXTAB_COLUMN which is a line of the structure CXTAB_CONTROL..This structure has 5 fields The fields of this structure are : SCREEN This filed is of TYPE SCREEN (screen table noramally used in ABAP) .It is used to modify and access various screen element attributes that created the column . e.g. SCREEN-NAME will return the screen element that created the

column ( e.g if the screen elemrnt ADDRESS-PHONE created the column PHONE than the SCREEN-NAME will return the value ADDRESS-PHONE and not PHONE ,so we have to use offset method to retrieve the correct field name i.e SCREENNAME(+7) will give us the value PHONE ,This method can be used for example in dynamic sorting of the column fields when the name of the column selected is required and not its screen element name e.g SORT itab STABLE BY SCREEN-NAME(+7) . INDEX This field represents the position of the column in the table control.It is of TYPE I. INVISIBLE This field is used to make a particular column invisible or visible.It is of TYPE C(1) and can have a vale of 'X' or ' '. VISLENGTH This field represents the visible length of the column.It is of TYPE I. SELECTED This field represents whether the column is selected or not.It is of TYPE C(1) and can have a value of 'X' or ' '. c) MODIFICATION 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-SCREENNAME 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. DELETING SELECTED ROWS Deletion of selected rows is simple. To delete selected rows first we will determine the rows which have been selected through selection column. FOR SINGLE ROW SELECTION IF mark EQ 'X'. "mark is the name of selection column field

DELETE itab FROM workarea. ENDIF. FOR MULTIPLE ROW SELECTION *To deetermine the rows selected we will use the selection column field to loop *through the internal table. LOOP AT itab WHERE mark EQ 'X'. "mark is the name of selection column field DELETE itab " and is part of the internal table .

ENDLOOP. HIDING A COLUMN To hide a column we will use the INVISIBLE field of the structure CXTABA_CONTROL and set its value to 'X'. e.g. To hide column number 3. DATA col LIKE LINE OF tab-con-COLS . READ TABLE tab_con-COLS INTO col WHERE index = 3. "tab_con is the name " of table control. col-INVISIBLE = 3. MODIFY tab-con-COLS FROM col INDEX 3. DISABLING INPUT To disable/enable fields of a column we will use the field SCREEN-INPUT of the structure CXTAB_COLUMN and set its value to 0 or 1. e.g. To disable input at column 3 of the table control . DATA col LIKE LINE OF tab_con-COLS. READ TABLE tab_con-COLS INTO col INDEX 3. col-SCREEN-INPUT = 0. MODIFY tab_con-COLS FROM col INDEX 3. d) ABAP DECLARATION : CONTROLS: tab_con TYPE TABLEVIEW USING SCREEN nnnn Here tab_con is the same name we used in screen for the table control.This ABAP statement will declare a control variable that will be used to access the table control , and set it's various attributes like number of fixed columns(tab_con-FIXED_COLS) ,total number of records it will display(tab_conLINES).It is of type CXTAB_CONTROL and is a deep Structure (structure containing structures). REFRESH CONTROL tab_con FROM SCREEN nnnn This ABAP statement will initialize the table control on the screen nnnn to its initial values. e) PBO PROCESSING: In PBO we have to use the screen LOOP ...ENDLOOP statement , with or without

intenal table. LOOP WITH CONTROL tab_con. MODULE fill_tab_con. ENDLOOP. Here a module should be called between the loop endloop statement to transfer data from the ABAP program to the screen table through a structure. This module should use the CURRENT_LINE attribute of the table control variable to get the current screen table record index to read the data from the internal table into a work area.e.g. READ TABLE int_table INDEX tab_con-CURRENT_LINE The record read will be placed in the header line of the internal table and will be available to the similarly named screen fields or if these are different it can be written explicitly. e.g. screen_field_name = int_table-field_name LOOP AT int_table INTO workarea WITH CONTROL tab_con CURSOR i FROM n1 TO n2. ENDLOOP.

Here the module call is not required to fill the screen table.The CURSOR parameter is a integer of type I indicating which absolute internal table line should be the first to display on the table control .FROM n1 TO n2 can be used to restrict the starting line and ending line number of the internal table , they are of type SY-TABIX. In both cases before the LOOP statement a module should be called which is generally for setting of status ,in which we should fill the LINES attribute (tab_con-LINES ) of the control with the total number of internal table records,doing this ensures correct and automatic scrolling. The ABAP statement DESCRIBE TABLE int_table LINES lines can be used to get the total lines in an int table. f) PAI PROCESSING: We have to use LOOP ... ENDLOOP in PAI so that data can transfer fro table control to ABAP program. If we want to write changes to the data we should call a module between the LOOP ... ENDLOOP. The MODULE call to process user commands (SY-UCOM) should be called after the ENDLOOP statement.e.g. PROCESS AFTER INPUT MODULE mod AT EXIT-COMMAND. LOOP AT itab_table or LOOP "depending on whether we are using AT int_table MODULE modify_int_table. ENDLOOP. MODULE user_command.

In the MODULE call modify_int_table we can use MODIFY int_table FROM workarea INDEX tab_con-CURRENT_LINE or we can use int_table-field_name = screen_field_name.

Você também pode gostar