Tuesday, February 10, 2009

Dynamic Background Colors in Smartforms

We were having some specific background colors in our output generated by the SMartforms. This background colors are coming properly in the print-out. But, when we try to send them as FAX, we are getting the BLACK background whereever we have that background color.

I used Field-symbols to have an access of the table which stores the Smartforms definition. I replaced the background color with the White background.

Code Snippet for Dynamic Background Color
*&---------------------------------------------------------------------*
* This code will clear the specific background for specific conditions
*&---------------------------------------------------------------------*
* In line type TYPE1 under the MAIN_TABLE, we have two columns.
* Column 1 with RED background and border
* Column 2 with no background color and BLUE border
*
*
FIELD-SYMBOLS: TYPE tsftabdef. " Table - Actual SF definitions
*
DATA: l_tabdef TYPE ssftabdef, " Work Area for the Table
t_ltypes TYPE tsfltype, " Table - Line types
l_ltypes TYPE ssfltype, " Work Area for the table
t_colinfo TYPE tsfcolinfo, " Table - Columns
l_colinfo TYPE ssfcolinfo, " Work area for the table
t_border TYPE tsfctaba, " Tables - Borders
l_border TYPE ssfctaba. " Work Area for the border
*
*
* Assign the table definition to the table field symbol
* Assiging by '(Program)Tablename' will give as the actual table
* which contains the defination of the Smartform. We will change
* respective table background color.
*
ASSIGN ('(SAPLSTXBC)TABDEFS') TO .
*
* Table definition table
LOOP AT INTO l_tabdef.
*
* Table line Types
* Line type TYPE1 from the table MAIN_TABLE
LOOP AT l_tabdef-tltype INTO l_ltypes.
*
* Coloum information
* Column1 (cell) of the TYPE1
LOOP AT l_ltypes-tcolinfo INTO l_colinfo.
*
* Borders
* Background color and borders for that cell
LOOP AT l_colinfo-borders INTO l_border.
*
* Clearing the color parameters for the cell
CLEAR: l_border-intensity, " Intensity
l_border-fillcolor-red, " Red
l_border-fillcolor-used, " Color Used
l_border-cfillcolor-color, " Red color in Hexa
l_border-cfillcolor-xred. " Color used in Hexa
*
MODIFY l_colinfo-borders FROM l_border.
ENDLOOP.
*
MODIFY l_ltypes-tcolinfo FROM l_colinfo.
ENDLOOP.
*
MODIFY l_tabdef-tltype FROM l_ltypes.
ENDLOOP.
*
MODIFY FROM l_tabdef.
ENDLOOP.

You can follow this link to have step-by-step explianation alongwith the Screenshots and SMartform XML file:
Dynamic Background Colors in Smartforms

This is one of my published WIKIes on SDN.

No comments:

Post a Comment