Chapter 7. Smart Forms - Tips and Tricks
Chapter 7. Smart Forms - Tips and Tricks
Introduction
This chapter explores useful recipes related to Smart Forms. We will start
with a simple recipe that will allow you to change the text editor of the
Smart Form to Microsoft Word. Then we will see how page protection for a
number of text lines may be applied using folders in order to ensure that
certain lines are printed together on one page.
We will also see how to set an image as background of a form page for
only preview and also for print. The procedure for generating multiple form
outputs in a single spool request will be discussed in an upcoming recipe.
We will also see how the preview and the print dialog may be suppressed,
and the output directly converted to PDF. Finally we will see the recipe for
calculating subtotals using sorting criterion at the Smart Form level.
We assume that the reader has basic Smart Forms knowledge. In addition,
the familiarity with the structure of the form-calling program is needed.
How to do it...
Follow these steps:
1. Call transaction SE38 and enter RSCPSETEDITOR in the program field.
Then execute the program. The selection screen of the program is
shown as follows:
3. For switching off the Microsoft Word editor for Smart Forms,
uncheck the Smart Forms indicator and then click
the Activate button on the toolbar.
How it works...
Depending on the settings saved for Smart Form, the editor changes. If
the Smart Form checkbox was on, the text editor appears as Microsoft
Word. Otherwise, the normal Smart Form text editor appears.
See also
http://wiki.sdn.sap.com/wiki/pages/viewpage.action?
pageId=77987849
http://forums.sdn.sap.com/thread.jspa?threadID=1679160
Getting ready
We will first create a background image and upload the image on the SAP
Document Server using the transaction
SE78.
How to do it...
We will now set the graphic as the form background. Follow these steps:
1. Call the transaction SMARTFORMS. Double-click the relevant node in
the left-hand pane of the page for which the background image is
to be set.
2. In the right-hand pane, three tabs will appear for the page. The
third is Background Picture. On this tab, enter the name of the
uploaded graphic. Select the Color Bitmap Image (BCOL) radio
button. Within the Output Mode list, select Print Preview from the
lisbox.
4. Next, we define a text within the MAIN Main Window on the page.
How it works...
When the Smart Form is called (using a calling program), the background
graphic is displayed along with the line of text in the Print Preview mode.
However, when the form is printed, no background image appears (only the
line of text created appears). This setting is very useful when a pre-printed
paper having the appropriate background graphic is used for printing, and
should not be printed in the form output (since the paper already has the
graphic in it). The user, however, needs to see the background graphic
when the form preview is taken on th screen.
There's more...
If the background graphic appears blurred or the pixel artefacts are visible,
we may need to use a high-resolution graphic. One option may be that we
use a high quality (high-resolution graphic). Also, we may try to control this
using the resolution setting through the Resolution field in the Output
Attributes screen. Instead of keeping it blank, we may enter a value of
200.
The higher the resolution, the clearer will be the graphic (however, the size
of the graphic may decrease as the resolution increases).
We may also slightly change the image's output mode in order to make the
image work as a watermark when printed on paper. Instead of the Print
preview and no print option for the Output Mode, we can choose
the Print preview and print option.
This will print the image on both the Print option (and the Print
Preview option) and when printed on paper, it will make the image appear
as a watermark on top of which text and data will appear.
See also
http://wiki.sdn.sap.com/wiki/display/ABAP/Background+pictures+in+S
mart+Forms
How to do it...
For defining a folder with page protection, follow these steps:
1. Right-click on the MAIN window. Then, from the context menu that
appears, choose the optionCreate and then select Folder, as
shown in the following screenshot:
How it works...
When the form output is generated, irrespective of the number of lines
printed above our three-line text, a page protection is applied. If the space
on the page is not enough so that all three lines may be printed, a page
break is automatically triggered and the lines are printed on a fresh new
page. Otherwise, the same page is utilized. In no case will the three lines
be broken into two pages.
In this recipe, we will see how printed multiple forms may be included in a
single spool request. We will create a number of form pages comprising
employees data. Each page will contain one employee's salary information.
The recipe will focus on the important parts of the program related to Smart
Form processing. We assume that an internal table
EMPLOYEE_LIST
exists that
How to do it...
Follow these steps:
1. First, we call the function module SSF_FUNCTION_MODULE_NAME in order
to get the name of the Smart Form function module. The form
name is passed to the function module. Themyfunction variable is
based on the type RS38l_FNAM (not shown in the following
screenshot):
2. Then appropriate variables are defined for the Smart Form control
structure and output options based on dictionary structures.
employee_list
'X'.
How it works...
After executing the program, multiple pages of the forms are generated.
For each employee, a separate page appears along with the necessary
information.
In
SSF_OPEN
printing. The tdnewidassigned to 'X' creates a new spool request. Within the
loop, the no_open and no_close fields are set to 'X', which ensures the spool
request is not opened or closed within the loop. The function module of the
Smart Form is called in the loop and generates the necessary output of
each employee. When all employees are processed, the
SSF_CLOSE
function
There's more...
We can also avoid the usage of the
SSF_OPEN
modules. In this case, when we program that on the first employee, the
spool job is opened and when we program that on the last employee, the
spool job is closed.
See also
http://help.sap.com/saphelp_nw70/helpdata/en/64/bf2f12ed1711d4b6
55006094192fe3/frameset.htm
How to do it...
For generating PDF output without showing the Smart Form on the screen,
follow these steps:
1. First, we define two structures cont_parameters and myoutput based
on the dictionary structures ssfctrlop and ssfcrescl respectively.
2. Then, we assign 'X' to the setotf and no_dialog fields of the control
structure.
otfdata
of
How it works...
The control structure fields no_dialog and the getotf are assigned the
value 'X'. This ensures that the form output is suppressed but the form
generated is returned to the program in
otf
Form
myfunction)
returns to the
program the otf format in the otfdata field of the myoutput structure.
We then pass this otfdata to the function module CONVERT_OTF_2_PDF. The
function module converts the smart form otf to a PDF and stores it in the
internal table pdf_content passed to the function module for table
lines.
The
See also
http://help.sap.com/saphelp_nw70/helpdata/EN/27/67443cc0063415e
10000000a11405a/frameset.htm
Getting ready
For this recipe, we define a structure in the
database ZST9_EMPLOYEES comprising three
fieldsPERNR, ALLOWANCE, and AMOUNT. We define a table type also
based on this structure, as shown in the following screenshot:
Appropriate texts are created within the cells in order to print the employee
number, allowance, and amount values passed. A program is then created
and the Smart Form is called. A tabular output is generated.
In this recipe, we will see how sorting along with totaling may be so that the
total of each employee's allowance is printed at the end of each employee's
details.
How to do it...
For subtotaling and sorting, proceed as follows:
1. Double-click the defined table node in the left-hand pane. In the
right-hand pane, on the Datatab, within Sort Criteria, select
the Event on Sort End checkbox. Also, enter PERNR as the field
name.
8. The final state will look like the one shown in following screenshot:
How it works...
The settings we did in the Smart Form will output the subtotal of the
allowances of each employee as shown. At the end of each employee, the
total allowances are calculated and printed.
The entries made on the Calculation tab of the table totals all the amounts
of a particular PERNR field (the SORT criterion) and stores in
the SUBTOTAL variable. The output will then be generated at
theEVENT on SORT end. After that, we clear the old value of SUBTOTAL so
that the value of the next employee may be calculated.
See also
http://help.sap.com/saphelp_nw2004s/helpdata/en/8a/60da59394b11
d5b69b006094192fe3/frameset.htm