In the Microsoft Internet Explorer (IE) application, the Web browser controls such print settings as page setup, paper size, and page orientation. These settings are not accessible to scripting function, which is problematic for BW teams because they limit end users' printing options. The author shows how to provide more printing controls to BW 3.x users with the code provided.
Web applications in the SAP BW 3.x Web Application Server (Web AS) environment run much the same way they do everywhere — via a Web browser. The technology within the browser governs the way that Web pages are displayed on screen and the way that they print. As a result, most limitations that BW users encounter displaying and printing their Web-based queries and reports result from the browser.
The browser of choice at most companies is Microsoft Internet Explorer (IE). Because Microsoft considers printing a security risk, settings such as page setup, paper size, and page orientation are not accessible to scripting functions on a Web page within IE. This presents a problem for BW teams.
Most teams would like to programmatically change the print settings in IE to accommodate a Web page’s layout, orientation, margins, and so forth. Web pages often require unique settings to print correctly. It would be nice for settings to change from Web page to Web page to prevent page clipping or other problems. Unfortunately, the only way to control these IE settings programmatically is to write a custom ActiveX1 control to interface with the Web browser. It requires advanced programming knowledge beyond the scope of this article. You have other options, however.
I will show you how to offer print setting controls to BW 3.x users and provide them with a print preview feature for Web queries. You can also allow them to format the on-screen page for these queries. In addition, I’ll explain how to enable user-friendly printing from within BW Web applications. I have put some of the code you will need to offer this functionality at this link.
Web Printing and Stylesheets
Formatting hardcopy sourced from the Web is generally done using HTML, Dynamic HTML, Cascading Stylesheets (CSSs), or in some cases XML. Basically, a Web page is formatted for printing via CSSs that are referenced within the Web application HTML template. CSSs are text documents with a specific formatting syntax.
There are two types of CSS syntax — CSS1 and CSS2. CSS2 is the latest version and is used most frequently today. Each block of syntax is called a style class and is defined by specific attributes.
CSS is used to format pages for both screen display and print. With CSS formatting, a developer can adjust various aspects of an HTML element such as its color, size, style, position, or visibility. Via the media attribute, an HTML page can reference separate CSSs, one for screen display and another for print.
A developer can add both a display and a print stylesheet from within the SAP BW Web Application Designer (Web AD). For display stylesheets, choose the General tab, click on the
icon, and then make your selection from the Choose Stylesheet screen (Figure 1). For hardcopy output, follow the path Menu>Insert>Print Stylesheet to access the Choose Print Stylesheet screen shown in (Figure 2).

Figure 1
BW Web Application Designer provides access to stylesheets for display…

Figure 2
….and for hardcopy output
Tags are embedded into the HTML template for the stylesheet choices, and examples of each are offered below. The first example (Figure 3) is for information that is displayed and the second (Figure 4) is for hardcopy output. Note the media attribute in Figure 4 specifies that this stylesheet is used when printing. By selecting a print stylesheet, developers can change the query format so that it prints differently than it appears on screen.
<link href= “/sap/bw/Mime/BEx/Stylesheet s/Sage_BWReports.css” type=”text/css” rel=”stylesheet “/>
|
Figure 3 |
HTML code referencing stylesheet for screen display |
|
<link href= “/sap/bw/Mime/BEx/Stylesheet s/BWReports_smallfont_print.css” type=”text/css” rel=”stylesheet “ media=”print”/> </HEAD>
|
Figure 4 |
HTML code referencing stylesheet for hardcopy output with media=”print” attribute |
|
Many useful CSS attributes are available such as a zoom control that can be applied to your display and hardcopy output. I suggest you explore the CSS attributes offered on the Microsoft Developer Network at https://msdn.microsoft.com/library/default.asp.
Tip!
SAP BW ships with stylesheets for displaying and printing Web applications. Select and modify the stylesheet to match your corporate design guide using the path Goto SE80>Mime repository>SAP>PublicBW>BEx>Stylesheets> Select a stylesheet>RMC>Export/Import. After making changes and importing your new stylesheet, you must refresh the Internet Communication Manager (ICM) cache before your changes will take effect via SMICM>Menu>Goto>HTTP Service Cache>Invalidate>Global in System.
Enhanced Web Printing
Although stylesheets provide an easy way to control formatting Web pages, sometimes a user just wants more print functions. If your implementation of SAP BW is version 3.0B SP09 or later, you can provide them print features such as page width and height controls and automated access to the IE print dialog screen.
The enhanced printing functionality is described in the ASAP implementation document “How To…Enhance Web Printing.” You can download it from service.sap.com/bw (Services & Implementation> How To…Guides> Guide List BW 3.x). You also will need to import the transports R901002.QB8 and K901002.QB8, which contain the HTML template includes and the Object-Oriented ABAP (ABAP OO) classes used for screen processing.
Use transactions SE38 and SE24 to confirm the presence of the HTML templates and ABAP OO classes presented in Figures 5 and 6. The Z_PRINT_HTML* templates are HTML includes and act as the framework for the print function user interface. Z_PRINT_SERVICE* ABAP OO classes control processing the HTML templates and the user interaction with the enhanced print functions.

Figure 5
Use SE38, to check for Z_PRINT templates

Figure 6
Use SE24 to confirm Z_PRINT classes tranferred
You need to create a copy of the delivered Web template 0QUERY_TEMPLATE, which must be enhanced to deploy the print functions. To create a copy of the standard query template 0QUERY_TEMPLATE, use transaction SE38 and execute program RS_TEMPLATE_MAINTAIN, which will allow you to edit the template. These changes cannot be made within the Web AD.
Enter 0QUERY_TEMPLATE and execute. Then click on the Save As icon
, enter a new name, and save. Re-run program RS_TEMPLATE_MAINTAIN, and enter your new Z*0QUERY_TEMPLATE.
After entering the name of your new template, switch into the change mode by clicking on
to access the HTML code. You need to edit the HTML code a little to provide the enhanced print features.
At the top of the template, locate the following code:
Now add the new parameters shown in the shaded area:
<param name=”HELP_SERVICE” value=”ZPRINTING”> <param name=”HELP_SERVICE_CLASS value=”Z_HELP_PRINT_SERVICE”> DATA_PROVIDER: DataProvider
|
Within the body of the template, find the following lines:
In the second line of code noted above, remove the opening <! at the end of the section and remove —->. Next, replace Druckvorschau
with Print Preview
and finish by adding the following to the HREF attribute:
<SAP_BW_URL CMD=”PROCESS_HELP_WINDOW” HELP_SERVICE=”ZPRINTING” DATA_PROVIDER=”DP”>
Your edited HTML code should now read:
<!— Display Print Preview—->
<td class=”SAPBEXNavLine”><a href=”<SAP_BW_URL CMD=”PROCESS_HELP_WINDOW” HELP_SERVICE=”ZPRINTING” DATA_PROVIDER=”DP”>”><img src=”Mime/BEx/Icons/S_B_LAYT.gif” border=”0” alt=”Print Preview”></a></td>
Save your work and make Z*0QUERY_TEMPLATE the default Web template for queries via transaction SPRO (SAP Reference IMG > Business Information Warehouse > Reporting Relevant Settings > Web Based Settings >
Determine Settings for Web Templates).
After the customized template is designated the default, you can access the enhanced Web printing functions for other queries viewed on the Web. Open a query from the SAP BW BEx Query Designer, and view it on the Web by clicking on
. After entering any variables, you will notice a new print preview icon at the end of the toolbar (Figure 7).

Figure 7
With some HTML code editing, a new print preview icon appears on the toolbar.
Clicking on the new icon displays the Web Print Preview screen (Figure 8) for the query, which allows users to add header and footer text, and change other items.

Figure 8
Provide end users with a Print Preview screen to change the settings of their output
Landscape Printing
By adding page height and width controls to the Web Print Preview screen, end users gain a landscape printing option. In the Z_PRINT_HTML_TEMPLATE file you imported, manipulate programming code by inserting lines for page height and width controls using the ABAP Code Editor SE38 in the change mode.
Add two HTML input controls so that users can input the page height and width. Within the Z_PRINT_HTML_TEMPLATE file, find the @@BEGIN_HTML_FORM_3@@
coding, which is a form control that submits input controls back to the BW server. Scroll down to <td>Data Rows 
and add the following code just after the Data Rows
and Data Columns
area:
<!—-BEGIN OF INSERTION —>
<!—-the following is for Page Width and Page Height entry fields —>
<br>
<table cellspacing=0 cellpadding=5 style=”width: 17cm; border: 1px solid #909cae; FONT-STYLE:normal; FONT-FAMILY: arial, sans-serif; FONT-WEIGHT: normal; FONT-SIZE: x-small;”>
<tr>
<td colspan=3 class=”SAPBexTableCaption”>Page Layout
<tr>
<td colspan=3>
<table style=”FONT-STYLE:normal; FONT-FAMILY: arial, sans-serif; FONT-WEIGHT: normal; FONT-SIZE: x-small;”><tr>
<td>Page Width <input type=text name=p_page_width size=10 value=”<%= p_page_width %>”>
<td>Page Height <input type=text name=p_page_height size=10 value=”<%= p_page_height %>”>
</table>
</table>
<!—-END OF INSERTION—>
For the contents of the new fields to be processed by BW, code must be added to the METHOD PROCESS_URL_ PARAMETERS of class Z_PRINT_HELP_SERVICE. Access the Class Builder tool via transaction SE24, and enter class Z_PRINT_HELP_SERVICE. In the change mode, add:
p_page_width = i_r_parameter->get_upper_case( i_id = ‘P_PAGE_WIDTH’ ).
p_page_height = i_r_parameter->get_upper_case( i_id = ‘P_PAGE_HEIGHT’ ).
to the method PROCESS_URL_PARAMETERS. Save and activate.
After making these changes, execute a query on the Web and click the print preview icon
on the toolbar. There are now two input fields in the Print Preview screen for users to set the page width and page height of the data area (Figure 9). Note that the values are in centimeters.

Figure 9
Users can set page width and height for land- scape printing and more
Automating the Print Dialog
Let your end users know that the new controls for page header, footer, page width, and page height are available in addition to those settings available within the IE print dialog box. Earlier I noted that there is no way to control the print settings programmatically from the Web page except via a custom ActiveX Control. Therefore, the user will have to remove any headers and footers, and select the page layout within the IE print dialog box. To make this function more seamless, you can add code to automate the display of the print dialog box.
The print templates and print helper classes need to be edited to call the JavaScript function window.print(), which automates the execution of the print dialog screen. The end result will be a third button on the Print Preview screen that when clicked on, processes any changes made to the settings and executes the IE print dialog screen.
To enable this functionality, modify the HTML include Z_PRINT_HTML_TEMPLATE via SE38 and add the following code:
…
…
<input type=submit value=’Enter’ name=”FormCmd”>
<!—- BEGIN OF INSERTION —>
<input type=submit value=’Print’ name=”FormCmd”>
<!—- END OF INSERTION —>
…
Next you will need to add some code to the METHOD PROCESS_URL_PARAMETERS of CLASS Z_PRINT_HELP_SERVICE using SE24. I have posted all the additional code you require at this link. Insert these lines after the ENDDIF for IF l_value EQ 'ENTER' and before the ELSE. To simplify the step, copy the entire IF l_value EQ 'ENTER' … ENDIF statement and paste. Note 'ENTER' will change to 'PRINT' in the newly added code.
Next, modify METHOD PROCESS_CMD of CLASS Z_PRINT_HELP_SERVICE via SE24 by adding the code indicated in Figure 10 and commenting out the appropriate lines in the figure.
CALL METHOD me->create_html_from_template EXPORTING i_snippet_name = 'HTML_HEAD' CHANGING c_html_stream = l_html. *{ INSERT D30K904417 2 data: l_value type string. l_value = i_r_parameter->get_upper_case ( i_id = 'FORMCMD' ). if l_value = 'PRINT'. CALL METHOD me->create_html_from_template EXPORTING i_snippet_name = 'HTML_BODY_START_2' CHANGING c_html_stream = l_html. else. CALL METHOD me->create_html_from_template EXPORTING i_snippet_name = 'HTML_BODY_START' CHANGING c_html_stream = l_html. endif. *} INSERT *{ DELETE D30K904417 1 * CALL METHOD me->create_html_from_template * EXPORTING * i_snippet_name = 'HTML_BODY_START' * CHANGING * c_html_stream = l_html. *} DELETE CALL METHOD me->create_html_form
|
Figure 10 |
Using SE24, modify METHOD PROCESS_CMD of CLASS Z_PRINT_HELP_SERVICE |
|
The final change to automate the IE print dialog box is to modify include Z_PRINT_HTML_TEMPLATE using SE38, and add the following snippet at the end of the include:
@@BEGIN_HTML_BODY_START_2@@
<BODY onload=”window.print()”>
@@END_HTML_BODY_START_2@@
@@BEGIN_HTML_BODY_END_2@@
</body>
@@END_HTML_BODY_END_2@@
After making these changes you will notice a new Print button—in addition to the Enter and Reset buttons—on the Print Preview display.

The new button allows end users to automatically access the IE print dialog box. After making any necessary changes in the Print Preview screen and the document is ready to print, users uncheck the Preview Mode box, click the new Print button, which releases the final page for printing and executes the IE print dialog (Figure 11).

Figure 11
Clicking the new Print button in the Print Preview screen releases the page for printing and executes the IE print dialog
David Fox
David Fox is a platinum solution consultant within the enterprise management business intelligence solution area at SAP. He specializes in the design, implementation, and support of SAP BW both stand-alone and integrated with SAP Strategic Enterprise Management, SAP Customer Relationship Management, SAP Enterprise Portal, SAP R/3, and mySAP Retail. He has more than four years of experience implementing SAP BW. In addition to implementation support, David provides SAP BW implementation strategy consultation to plan and identify related risks, resources, costs, and scope.
If you have comments about this article or publication, or would like to submit an article idea, please contact the editor.