Make your own free website on Tripod.com

SAP PM & ABAP Code Niraj Visnoi

Table Control modification in SAP ABAP at run time

Home
What is SAP ?
SAP LSMW Explained with example
SAP PM T-Codes
PM BRD/COR Maintenance
Add Your URL
User Exits & Enhancements
Best Of SAP Links
BDC Code
My Resume
SAP SmartForms Step by Step
SAP ABAP ALV Grid Explained with Example
Useful Tips
Contact Information Guest Book and Consultants List
ABAP Code
ABAP System Fields
SAPScript
SAPScript Graphics
SAPScript Print Program
ABAP ListViewer
Dialog Programming
SAP Tables
SAP ALE and IDOC
Recommended SAP ABAP Coding guidelines
SAP General ABAP
Submit Your Code
SAP Books For consultants
Free Website Submission and ROR Sitemap generator
Free Domain Search
Free HoroScope

Table Control modification at run time.

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.
 
 
 

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.
 
NOTE: Similarly other operations can be performed by changing the value of various fields of structure CXTAB_CONTROL.
 

Enter supporting content here

http://sap.niraj.tripod.com

Search http://sap.niraj.tripod.com Search www

 http://sap.niraj.tripod.com      Niraj Visnoi *INDIA * niraj_visnoi@consultant.com      
 CELL No. 91 9911413767       Copyright 2006 all rights reserved