Situation:
Our outputs have some background colors for important fields to have better visibility. This works fine for the normal printout. But, when send a SmartForm Output as a FAX, output comes with a BLACK background wherever we have the background color. And this makes the output unreadable (BLACK font with BLACK background).
Possible ways to handle the problem:
- Don't send a FAX: This is not feasible, as some customers would like to have there forms as FAX
- Create a clone of the existing forms and remove the background color and call them whenever we have to send as FAX: This doesn't make sense because this will lead to more maintenance; change to the primary form leads the change to the clone form.
- Find out some way to remove the background color dynamically: This seems to be the best choice, but next question is how to do it.
Solution:
I had debugged the SmartForm function modules over and over to get the point where it sets the background color, borders etc to the output and what I found, there is only main internal table, with deep structure, which handles everything to generate the layout for the output.
I have started with creating a test Smartform. I created some tables lines with background colors. Than I made a coding node in the SmartForm and tried to change the internal table, which holds the entire layout related information, with help of field-symbols to remove the background color and BINGO - I got the background color removed.
With Background Color:
Without Background Color:
SmartForm:
Download the uploadable .XML Save this file as ZTEST_NP_DYN_BGCOL.XML. To Upload, go to tcode SMARTFORMS and upload this file from Utilities > Upload Form.
The Main logic which handles the dyanmic coloring is inside the Smartform under window DUMMY.
<?xml version="1.0" encoding="utf-8" ?>
- <sf:SMARTFORM xmlns:sf="urn:sap-com:SmartForms:2000:internal-structure" xmlns="urn:sap-com:sdixml-ifr:2000" sf:language="EN">
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<CAPTION>New Form</CAPTION>
<MASTERLANG>E</MASTERLANG>
<LANGVECTOR>*</LANGVECTOR>
<DEVCLASS>$TMP</DEVCLASS>
<FIRSTUSER>NPATEL</FIRSTUSER>
<FIRSTDATE>2007-08-07</FIRSTDATE>
<FIRSTTIME>16:40:57</FIRSTTIME>
<LASTUSER>NPATEL</LASTUSER>
<LASTDATE>2008-05-29</LASTDATE>
<LASTTIME>13:39:48</LASTTIME>
</HEADER>
<NAME>DOCUMENT_OUTPUT_INFO</NAME>
<TYPENAME>SSFCRESPD</TYPENAME>
</item>
<NAME>JOB_OUTPUT_INFO</NAME>
<TYPENAME>SSFCRESCL</TYPENAME>
</item>
<NAME>JOB_OUTPUT_OPTIONS</NAME>
<TYPENAME>SSFCRESOP</TYPENAME>
</item>
<NAME>ARCHIVE_INDEX</NAME>
<TYPENAME>TOA_DARA</TYPENAME>
</item>
<NAME>ARCHIVE_INDEX_TAB</NAME>
<TYPENAME>TSFDARA</TYPENAME>
</item>
<NAME>ARCHIVE_PARAMETERS</NAME>
<TYPENAME>ARC_PARAMS</TYPENAME>
</item>
<NAME>CONTROL_PARAMETERS</NAME>
<TYPENAME>SSFCTRLOP</TYPENAME>
</item>
<NAME>MAIL_APPL_OBJ</NAME>
<TYPENAME>SWOTOBJID</TYPENAME>
</item>
<NAME>MAIL_RECIPIENT</NAME>
<TYPENAME>SWOTOBJID</TYPENAME>
</item>
<TYPENAME>SWOTOBJID</TYPENAME>
</item>
<NAME>OUTPUT_OPTIONS</NAME>
<TYPENAME>SSFCOMPOP</TYPENAME>
</item>
<NAME>USER_SETTINGS</NAME>
<TYPENAME>TDBOOL</TYPENAME>
<DEFAULTVAL>'X'</DEFAULTVAL>
</item>
<NAME>FORMATTING_ERROR</NAME>
</item>
<NAME>INTERNAL_ERROR</NAME>
</item>
<NAME>USER_CANCELED</NAME>
</item>
</INTERFACE>
<item>types: begin of ty_tab,</item>
<item>abcde like sy-abcde,</item>
<item>end of ty_tab.</item>
<item>types: t_Tab type table of ty_tab.</item>
</GTYPES>
<TYPING>TYPE TABLE OF</TYPING>
<TYPENAME>TY_TAB</TYPENAME>
</item>
<TYPENAME>TY_TAB</TYPENAME>
</item>
</GDATA>
<item>* Fill the test internal table</item>
<item>perform fill_Table tables itab</item>
<item>using no_item</item>
<item>changing w_no_item.</item>
</GCODING>
<item>*&---------------------------------------------------------------------*</item>
<item>*& Form FILL_TABLE</item>
<item>*&---------------------------------------------------------------------*</item>
<item>*----------------------------------------------------------------------*</item>
<item>* -->I_TAB text</item>
<item>* -->I_NO text</item>
<item>* <--E_NO text</item>
<item>*----------------------------------------------------------------------*</item>
<item>FORM FILL_TABLE TABLES I_TAB TYPE T_TAB</item>
<item>USING I_NO TYPE I</item>
<item>CHANGING E_NO TYPE I.</item>
<item>E_NO = I_NO.</item>
<item>* if input is less than 5 than make it 5</item>
<item>IF E_NO < 5.</item>
<item>* fill the table</item>
<item>DO E_NO TIMES.</item>
<item>I_TAB-ABCDE = SY-ABCDE.</item>
<item>APPEND I_TAB.</item>
<item>CLEAR I_TAB.</item>
<item>ENDFORM. "fill_Table</item>
</FCODING>
<PAGEFORMAT>DINA4</PAGEFORMAT>
<STDSTYLE>SYSTEM</STDSTYLE>
<CAPTION>First Page</CAPTION>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<CAPTION>First Page</CAPTION>
</item>
</T_CAPTION>
<CAPTION>Background Picture</CAPTION>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<CAPTION>Background Picture</CAPTION>
</item>
</T_CAPTION>
</sf:GRAPHIC>
</sf:BACKGROUND>
</sf:PAGE>
</sf:OBJ>
<CAPTION>Dummy window</CAPTION>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<CAPTION>Dummy window</CAPTION>
</item>
</T_CAPTION>
<INAME>CHANGE_BG_COLOR</INAME>
</NAME>
<CAPTION>Change Background Color</CAPTION>
<item>* In line type TYPE1 under the MAIN_TABLE, we have two columns.</item>
<item>* Column 1 with RED background and border</item>
<item>* Column 2 with no background color and BLUE border</item>
<item>* This piece of code will remove the RED Background color when the total</item>
<item>* number of entry will greater than 5.</item>
<item>FIELD-SYMBOLS: <F_TAB> TYPE TSFTABDEF. " Table - Actual SF definitions</item>
<item>DATA: L_TABDEF TYPE SSFTABDEF, " Work Area for the Table</item>
<item>T_LTYPES TYPE TSFLTYPE, " Table - Line types</item>
<item>L_LTYPES TYPE SSFLTYPE, " Work Area for the table</item>
<item>T_COLINFO TYPE TSFCOLINFO, " Table - Columns</item>
<item>L_COLINFO TYPE SSFCOLINFO, " Work area for the table</item>
<item>T_BORDER TYPE TSFCTABA, " Tables - Borders</item>
<item>L_BORDER TYPE SSFCTABA. " Work Area for the border</item>
<item>* Assign the table definition to the table field symbol</item>
<item>* Assiging by '(Program)Tablename' will give as the actual table</item>
<item>* which contains the defination of the Smartform. We will change</item>
<item>* respective table background color.</item>
<item>ASSIGN ('(SAPLSTXBC)TABDEFS') TO <F_TAB>.</item>
<item>* Table definition table</item>
<item>LOOP AT <F_TAB> INTO L_TABDEF.</item>
<item>* Table line Types</item>
<item>* Line type TYPE1 from the table MAIN_TABLE</item>
<item>LOOP AT L_TABDEF-TLTYPE INTO L_LTYPES.</item>
<item>* Coloum information</item>
<item>* Column1 (cell) of the TYPE1</item>
<item>LOOP AT L_LTYPES-TCOLINFO INTO L_COLINFO.</item>
<item>* Background color and borders for that cell</item>
<item>LOOP AT L_COLINFO-BORDERS INTO L_BORDER.</item>
<item>* Clearing the color parameters for the cell</item>
<item>CLEAR: L_BORDER-INTENSITY, " Intensity</item>
<item>L_BORDER-FILLCOLOR-RED, " Red</item>
<item>L_BORDER-FILLCOLOR-USED, " Color Used</item>
<item>L_BORDER-CFILLCOLOR-COLOR, " Red color in Hexa</item>
<item>L_BORDER-CFILLCOLOR-XRED. " Color used in Hexa</item>
<item>MODIFY L_COLINFO-BORDERS FROM L_BORDER.</item>
<item>MODIFY L_LTYPES-TCOLINFO FROM L_COLINFO.</item>
<item>MODIFY L_TABDEF-TLTYPE FROM L_LTYPES.</item>
<item>MODIFY <F_TAB> FROM L_TABDEF.</item>
</CODE>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<INAME>CHANGE_BG_COLOR</INAME>
<CAPTION>Change Background Color</CAPTION>
</item>
</T_CAPTION>
</sf:CODE>
</sf:OBJ>
<INAME>%CONDITION3</INAME>
</NAME>
<CAPTION>New Alternative 3</CAPTION>
<ICON>@20/QSelect: Equal to@</ICON>
</item>
</COND>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<INAME>%CONDITION3</INAME>
<CAPTION>New Alternative 3</CAPTION>
</item>
</T_CAPTION>
</sf:CONDITION>
</sf:COND>
</sf:NODE>
</sf:item>
</sf:SUCC>
</sf:NODE>
</sf:PROC_CTRL>
</sf:WINDOW>
</sf:OBJ>
<INAME>%OUTATTRIB2</INAME>
</NAME>
<U_WHEIGHT>CM</U_WHEIGHT>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</LEFTATTR>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</TOPATTR>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</RIGHTATTR>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</BOTTOMATTR>
</BORDER>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<INAME>%OUTATTRIB2</INAME>
</item>
</T_CAPTION>
</sf:OUTATTR>
</sf:OUTATTR>
</sf:NODE>
</sf:item>
<CAPTION>Main Window</CAPTION>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<CAPTION>Main Window</CAPTION>
</item>
</T_CAPTION>
<INAME>MAIN_TABLE</INAME>
</NAME>
<CAPTION>New Table 1</CAPTION>
<TABHEADER>WA_ITAB</TABHEADER>
<OTABHEADER>A</OTABHEADER>
<OTABFOOTER>A</OTABFOOTER>
<U_FHEIGHT>CM</U_FHEIGHT>
<DEFAULTVAL>X</DEFAULTVAL>
</item>
</DYNLINES>
<INTENSITY>100</INTENSITY>
<LBOTTOM_U>MM</LBOTTOM_U>
</item>
</BORDERS>
</item>
<INTENSITY>000</INTENSITY>
<LBOTTOM_U>TW</LBOTTOM_U>
</item>
</BORDERS>
</item>
</CELLS>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<INAME>MAIN_TABLE</INAME>
<CAPTION>New Table 1</CAPTION>
</item>
</T_CAPTION>
</sf:SECTION>
</sf:OBJ>
<CAPTION>Header</CAPTION>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<CAPTION>Header</CAPTION>
</item>
</T_CAPTION>
</sf:EVENT>
</sf:OBJ>
</sf:NODE>
</sf:item>
<CAPTION>Main Area</CAPTION>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<CAPTION>Main Area</CAPTION>
</item>
</T_CAPTION>
</sf:EVENT>
</sf:OBJ>
<CAPTION>New Line 1</CAPTION>
<U_FHEIGHT>CM</U_FHEIGHT>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<CAPTION>New Line 1</CAPTION>
</item>
</T_CAPTION>
</sf:SECTION>
</sf:OBJ>
<INAME>%OUTATTRIB3</INAME>
</NAME>
<T_LINETYPE>TYPE1</T_LINETYPE>
<U_WHEIGHT>CM</U_WHEIGHT>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</LEFTATTR>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</TOPATTR>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</RIGHTATTR>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</BOTTOMATTR>
</BORDER>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<INAME>%OUTATTRIB3</INAME>
</item>
</T_CAPTION>
</sf:OUTATTR>
</sf:OUTATTR>
<CAPTION>New Column 1</CAPTION>
<U_FHEIGHT>CM</U_FHEIGHT>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<CAPTION>New Column 1</CAPTION>
</item>
</T_CAPTION>
</sf:SECTION>
</sf:OBJ>
<INAME>%OUTATTRIB4</INAME>
</NAME>
<U_WHEIGHT>CM</U_WHEIGHT>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</LEFTATTR>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</TOPATTR>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</RIGHTATTR>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</BOTTOMATTR>
</BORDER>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<INAME>%OUTATTRIB4</INAME>
</item>
</T_CAPTION>
</sf:OUTATTR>
</sf:OUTATTR>
<CAPTION>New Text</CAPTION>
<NOLANGUAGE>X</NOLANGUAGE>
<TDLINE>&wa_itab-abcde&</TDLINE>
</item>
</TEXT>
<STYLE_NAME>SYSTEM</STYLE_NAME>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<CAPTION>New Text</CAPTION>
</item>
</T_CAPTION>
</sf:TEXT>
</sf:OBJ>
</sf:NODE>
</sf:item>
</sf:SUCC>
</sf:NODE>
</sf:item>
<CAPTION>New Column 2</CAPTION>
<U_FHEIGHT>CM</U_FHEIGHT>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<CAPTION>New Column 2</CAPTION>
</item>
</T_CAPTION>
</sf:SECTION>
</sf:OBJ>
<INAME>%OUTATTRIB5</INAME>
</NAME>
<U_WHEIGHT>CM</U_WHEIGHT>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</LEFTATTR>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</TOPATTR>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</RIGHTATTR>
<THICKNESS>0.00</THICKNESS>
<THICKNESSU>PT</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</BOTTOMATTR>
</BORDER>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<INAME>%OUTATTRIB5</INAME>
</item>
</T_CAPTION>
</sf:OUTATTR>
</sf:OUTATTR>
<CAPTION>New Text 1</CAPTION>
<STYLE_NAME>SYSTEM</STYLE_NAME>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<CAPTION>New Text 1</CAPTION>
</item>
</T_CAPTION>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
</item>
</T_TEXT>
</sf:TEXT>
</sf:OBJ>
</sf:NODE>
</sf:item>
</sf:SUCC>
</sf:NODE>
</sf:item>
</sf:SUCC>
</sf:NODE>
</sf:item>
</sf:SUCC>
</sf:NODE>
</sf:item>
<CAPTION>Footer</CAPTION>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<CAPTION>Footer</CAPTION>
</item>
</T_CAPTION>
</sf:EVENT>
</sf:OBJ>
</sf:NODE>
</sf:item>
</sf:SUCC>
</sf:NODE>
</sf:item>
</sf:SUCC>
</sf:NODE>
</sf:PROC_CTRL>
</sf:WINDOW>
</sf:OBJ>
<INAME>%OUTATTRIB1</INAME>
</NAME>
<CAPTION>New Display Option</CAPTION>
<U_WHEIGHT>CM</U_WHEIGHT>
<THICKNESS>15.00</THICKNESS>
<THICKNESSU>TW</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</LEFTATTR>
<THICKNESS>15.00</THICKNESS>
<THICKNESSU>TW</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</TOPATTR>
<THICKNESS>15.00</THICKNESS>
<THICKNESSU>TW</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</RIGHTATTR>
<THICKNESS>15.00</THICKNESS>
<THICKNESSU>TW</THICKNESSU>
<DISTANCE>0.00</DISTANCE>
<DISTANCEU>CM</DISTANCEU>
</BOTTOMATTR>
</BORDER>
<FORMNAME>ZTEST_NP_DYN_BGCOL</FORMNAME>
<INAME>%OUTATTRIB1</INAME>
<CAPTION>New Display Option</CAPTION>
</item>
</T_CAPTION>
</sf:OUTATTR>
</sf:OUTATTR>
</sf:NODE>
</sf:item>
</sf:SUCC>
</sf:NODE>
</sf:item>
</sf:SUCC>
</sf:NODE>
</sf:PAGETREE>
</sf:item>
</sf:VARHEADER>
</sf:SMARTFORM>
Driver Program
This is the driver program for SmartForm:
*&---------------------------------------------------------------------* *& Report ZTEST_NP_SF_DYN *& *&---------------------------------------------------------------------* *& Test Program to test the dynamic background color in the *& Smartforms *&---------------------------------------------------------------------* REPORT ZTEST_NP_SF_DYN. DATA: W_FM_NAME TYPE RS38L_FNAM. * Selection Screen SELECTION-SCREEN: BEGIN OF BLOCK BLK1 WITH FRAME. SELECTION-SCREEN: BEGIN OF LINE, COMMENT 1(20) L_SF_NM, POSITION 35. PARAMETERS: P_SF_NM TYPE TDSFNAME DEFAULT 'ZTEST_NP_DYN_BGCOL'. SELECTION-SCREEN: END OF LINE. SELECTION-SCREEN: BEGIN OF LINE, COMMENT 1(20) L_ITEM, POSITION 35. PARAMETERS: P_ITEM TYPE I DEFAULT 5. SELECTION-SCREEN: END OF LINE. SELECTION-SCREEN: BEGIN OF LINE. PARAMETERS: P_BG_COL AS CHECKBOX. SELECTION-SCREEN: COMMENT 3(35) L_BG, END OF LINE. SELECTION-SCREEN: END OF BLOCK BLK1. * Initialization INITIALIZATION. L_SF_NM = 'Smartform Name'. L_ITEM = 'Number of Item'. L_BG = 'With Background Color'. * Start of Selection START-OF-SELECTION. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING FORMNAME = P_SF_NM IMPORTING FM_NAME = W_FM_NAME EXCEPTIONS NO_FORM = 1 NO_FUNCTION_MODULE = 2 OTHERS = 3. IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CALL FUNCTION W_FM_NAME EXPORTING NO_ITEM = P_ITEM I_DYN_BG = P_BG_COL EXCEPTIONS FORMATTING_ERROR = 1 INTERNAL_ERROR = 2 SEND_ERROR = 3 USER_CANCELED = 4 OTHERS = 5. IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. |
How to run this program:
Note: I have tried this on ECC 5.0.
source :https://www.sdn.sap.com/irj/sdn/wiki?path=/display/Snippets/Dynamic+Background+Colors+in+SmartForms