How to use Code Inspector in quick steps?

AdHoc Inspection for ABAP Program in Quick Method

We will see how we can do a quick code inspection on a single program or an
object set. This is also termed as an Ad Hoc Inspection, since the inspection results are not
saved and are not available for future.


1. Call the SAP transaction SCII. Alternatively, you may go to transaction SCI and on
the main screen, leave the Inspection field blank and press the Create button below
the Inspection Input field. The screen appears as follows:




2. Select the Single radio-button option. From the list box, select the Program option
and then enter the name of the program in the field provided. We enter the name
of a previously created program ZST9_TEST_FOR_ALL_ENTRIES_2.



3. From the area in the lower part of the screen, we will select the option Temporary
Definition. Then we select from the available checks that we want to be carried out.
Selecting or deselecting a particular category will include or exclude all checks within
the category in the inspection. For resetting to default values at any time, select the
menu path by going to Utilities | Set Initial. Alternatively, use the toolbar button
or press F7.



4. Finally, press F8 to carry out the inspection.


The code of the program mentioned is scanned and checked based on the selected checks.
The results are then displayed. The results comprise of tree structure (hierarchy) within nodes
corresponding to the checkbox selected. There are three columns shown for messages within
the different categories and then the checkboxes pertaining to the category in question.
These are Errors, Warnings, and Information messages. You may open the various
categories to see the detail of the messages found in each category. For example,
we have two information messages found under Use of Indexes in SELECT statement.





You may double-click on a particular message to reach the actual line of the code in the
program that generated the message in question.

While selecting the checks to be run from a particular category, a check may have further
attributes. This is denoted by the icon before it. You may click on the icon to view a list of
the attributes and choose the ones relevant for your requirement. If you find an icon, it means
that there is at least one value that must be set for the attributes contained within the check.
Otherwise, selecting the check will produce an error and the inspection will not run.



For running another inspection from the results screen, use the toolbar button .

For viewing the results in a compact display format, use the toolbar button .  


You have also the option of checking objects using object sets or the object contained within a
request. However, the transaction has a limitation that you may not check over 50 objects and
that the inspection may not be saved for reuse. In this case, the inspection is not stored and
does not have a name (that is, it is anonymous). The next recipe will cover the ones that will
overcome these limitations.


How to Sort or Sub-Total a table field in SMARTFORMS?

Sorting and Sub-totaling to table fields.

We will see how we can sort a given table within the Smart Form and calculate
totals based on a particular field as the sort criterion. In this recipe, we will use an example of
employees and their allowances and amounts.

We define a structure in the database ZST9_EMPLOYEES comprising three
fields PERNR, ALLOWANCE, and AMOUNT. We define a table type also based on this
structure, as shown in the following screenshot:




A table EMPLOYEE_TABLE (based on the defined dictionary table type) is included in the
TABLES tab of the Smart Form interface, and a corresponding work area WA_EMPLOYEE
in the global definition.

A table is then created on the Smart Form layout. The loop of the table is shown as follows:



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.



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.


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 Data tab, within Sort Criteria, select the Event on Sort End checkbox. Also, enter
PERNR as the field name.




2. This will add a PERNR Event on Sort End node.





3. We define a subtotal variable in the global definition. This is a temporary storage
variable for totals of each employee's allowances.



4. On the Calculations tab of the table, we enter the values shown in the
following screenshot:





5. Right-click the PERNR Event on Sort End node to create a table line. Use the same
line type used for the rows of the table (containing three cells).

6. For the second and third cell, we define texts outputting SUBTOTAL and VARIABLE
and SUBTOTAL respectively.

7. Also, a line of code is added after the text that clears the SUBTOTAL variable.





8. The final state will look like the one shown in following screenshot:




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 the EVENT on SORT end. After that, we clear the old value of SUBTOTAL so that
the value of the next employee may be calculated.

How to convert SmartForms into PDF document?

Converting Smart Forms to PDF output

we will see how the form output may be suppressed and returned as internal
table to our calling program and then how a PDF is generated within the program. We will
set values to some fields in the control structure of the Smart Form and use it with the
CONVERT_OTF_2_PDF function module.

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.



3. The dynamic call of the Smart Form function module is then carried out.



4. Appropriate variables are then defined. The most important is the internal
table pdf_content used for storing the converted PDF output of the form.
The filesize and doc_archive tables are necessary for calling the function
module CONVERT_OTF_2_PDF.



5. The function module CONVERT_OTF_2_PDF is then called. The OTF parameter
passes the value of the field otfdata of the myoutput structure.



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 format. The call to the Smart Form function module (stored in the variable 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 PDF file may then be
saved on the desktop using the method CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD,
or e-mailed to another user.

How to incorporate and print several SMARTFORMS in one SPOOL request?

Printing several forms in one spool request


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 contain the employee numbers of all personnel to be processed.


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. The myfunction 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.



3. The function module SSF_OPEN is then called.




4. A loop is run on the internal table employee_list for all employees. For each
employee, the form get_employee_data is called, which fetches the necessary
information of the employee in question and fills the internal table employee_data.
The no_open and no_close fields of the control parameters structure are assigned
the value 'X'. In addition, the tdnewid field of the output options structure is
assigned 'X'.


5. The function module of the Smart Form is then called and necessary data of the
employee provided along with control parameters and output option structures.





6. Finally, the SSF_CLOSE function module is called.

After executing the program, multiple pages of the forms are generated. For each employee,
a separate page appears along with the necessary information.



The call of the function module SSF_OPEN opens the spool job for form printing.
The tdnewid assigned 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 module is called and the spool request is closed.


We can also avoid the usage of the SSF_OPEN and SSF_CLOSE function 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.

How to use folder options for page protection?


Steps for Page Protection in SMARTFORMS


We will see how we can create a folder comprising a number of lines
(block of text ) so that they are all printed on the same page. If the space within a page is
not enough for printing all the lines, the entire text block is printed on the subsequent page,
that is, page protected.

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 option Create and then select Folder, as shown in the following screenshot:



2. Next, enter a suitable folder name. In the right-hand pane, on the Output Options tab
of the created folder, check the Page Protection indicator.



3. Then add a text under the given folder.


4. Add three lines to the text.




5. Save and activate your Smart Form.


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.


How to set image as a background in the SMARTFORMS?

Setting background pictures in FORMS and in the print preview


We will first create a background image and upload the image on the SAP Document Server
using the transaction SE78. The name of the image we upload is ZST9_BACKGROUND and is
in color (the supported formats are .tiff and .bmp).




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 listbox.



3. The main window is placed on top of the background graphic.




4. Next, we define a text within the MAIN Main Window on the page.



5. A suitable line TEST TEXT FOR BACKGROUND is created within the created text,
as shown in the following screenshot:



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 the screen.




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.



How to improve the performance in SELECT Queries?

Improve the performance by adding hints in SELECT clause


If there are many indexes that contain common fields (or for any other reason), the database
optimizer cannot decide the right index to be used for a particular query.


Hints can be provided using the %_HINTS parameter. We will see the syntax for specifying
HINTS within your SELECT clause in order for a particular index to be used by the database
optimizer. We will see how the hints may be specified when the underlying database is
MS SQL Server.

We will have a small program that runs a SELECT statement on the table
ZST9_VBAK. We will use the index (Z12) that we created in the previous Creating Secondary
Indexes in Database Tables recipe.


For creating the program containing the SELECT clause with the HINT parameter, proceed
as follows:
1. A parameter P_AUFNR is declared for taking as input an order number.
2. Next, a data variable myvbeln is defined.
3. A SELECT statement is then written. The addition %_HINTS followed by the database
name, the table, and table index name is made to the SELECT clause.




It is a very simple addition. There is a special syntax used for specifying the name of the
database index to be used for the particular SELECT statement. The name of the index we
used can be taken from the index name as defined in the ABAP Dictionary. The table name
and the index name are specified within TABLE <tablename> ABINDEX(<suffix>). The syntax
should be proper because other than the database name check, the syntax checker does not
check the index name. Therefore, if a wrong index is used, the corresponding query will not
give a syntax error but the desired results will not be achieved.






In our case, we use MSSQLNT as the database name. However, you may use other database
names such as ADABAS, AS400, DB2, DB6, INFORMIX, MSSQLNT, and ORACLE (depending on
what is applicable to your underlying database). The code pertaining to the HINT parameter of
one database may differ from that of another.
For example, if we have an ORACLE database, the same Z12 index may be specified in the
SELECT statement in the following manner:




Note the database name added along with the changed format for index specification.