Sie sind auf Seite 1von 34

How to Find SAP SmartForms Function Module Name

If you create SAP Smart Forms documents for your outputs and use SmartForms as your Output Management solution, then you have already used the function modules for the SAP Smartforms you have created. For example, calling an SAP Smartform document within ABAP codes requires the SAP Smartform function module name. It is very useful using the ABAP function SSF_FUNCTION_MODULE_NAME to get the function module name for a SAP Smartform report. SSF_FUNCTION_MODULE_NAME returns the function module name for a Smart Form document. Instead of using SSF_FUNCTION_MODULE_NAME to learn its function name, we can use the menues in Smartforms transaction screen for getting the corresponding function module. For example, we can work on the SAP Standard Purchase Order Smartform document/SMB40/MMP0_A. Below is the attributes screen of the SAP Purchase Order standart Smartform.

Let's get the SAP SmartForms function module name using the SmartForms menues.

How to Debug SmartForms - Debugging SAP SmartForm in ABAP ?

Debugging SmartForms using Function Module If you want to debug Smartform document in non-modifiable client, then you can try debugging Smartforms Function Module using soft break point. First you need to find the function module name of the target SmartForm for debugging. If you do not know how to get the function module name of the SAP Smart Form, please read the Smart Form tutorial titled How to Find SAP SmartForms Function Module Name. Without knowing the function module name, we can not debug SmartForms in non-modifiable clients. After you find the function module name, we can now display the ABAP source codes of the SSF FM (Function Module) using the SAP Transaction SE37. Within the ABAP codes of Smartform FM you can put a soft break-point any where suitable for your debugging Smartforms purposes.

It is better to copy the node name or some parts of the ABAP code in the SAP Smartform and search the text within the SE37 displayed source code of the Smartforms function module (FM). You can place a soft break point in the source code using Ctrl+Shift+12 key combination or using the Stop icon .

Let's assume that you want to debug Smartforms codes within program lines named '%CODE10' as seen in the followin Smartform screenshot,

First click on the Search button , and not use the Ctrl+F since searc button has far more powerful functionalities than ordinary Ctrl+F search. Enter the text you are searching in the Find text area. You can search for the node name '%CODE10' as well as for a part of your SmartForm code. What is important here in this Search is be sure that you selected the option "In main program". Otherwise your search will take place only for a limited part of the Smartform function module codes.

When the place of the target code block is found, you can run the SAP Smart Form and start to debug Smartform document.

Debug Smart Form using Break-Point If you are in a modifiable client, or where you can alter the codes of your SAP SmartForms, then there is an other alternative method that you can debug Smart Forms. One way of debugging Smartform documents is placing break points within the Smart Form program lines like shown in below ABAP code : BREAK SAPUserName. * where SAPUserName is your ABAP Developer user * OR BREAK-POINT. * will stop program execution for all SmartForm callers

Smart Form Trace with SFTRACE or SMARTFORM_TRACE An other SAP tool that might help ABAP developers troubleshoot with Smart Forms and to debug SmartForm can be the Smart Form Trace. You can activate Smart Form Trace for tracing Smartform execution process using the SAP transactionSFTRACE or SMARTFORM_TRACE codes. For more help on Smart Form Trace and use to debug Smartforms, please refer to SAP Help documentation.

SAP Tutorial - Convert Spool Request to PDF File using RSTXPDFT4 ABAP Report

You want to export the contents of a spool request as a PDF file to a directory of your choice, and print the file as required. The PDF file contains the print data in the format in which it would be output by the printer. In order to generate PDF files instead of printing output from a printer, you can use the ABAP report RSTXPDFT4. First of all, you should generate a spool request for the document you want to create pdf file for. You can list the spool requests for your current transaction or other sessions' spool requests by using the filter in SAP transaction code SP01 screen. In the below SP01 SAP screen, you can see a short list of spool requests that are in que waiting instead of being printed. You can note down the spool number of the document which you want to export as pdf file.

Now, we can run the ABAP report RSTXPDFT4, using SAP transaction SE38 in an other SAP session. In SE38 screen, we can enter the ABAP RSTXPDFT4 program name in the input textbox and then run the report by using the F8 shortcut.

The first screen in the displayed RSTXPDFT4 report window is "Converting SAPscript (OTF) or ABAP List Spool Job to PDF" screen.

In this screen you will define the spool job which you want to convert it to PDF. Using the first SP01 screen where we have listed available spool requests, we can enter SAP spool request number into the "Spool Request" textbox. Also we can define the file folder or the directory where we want to download and save the the PDF file. You can enter a storage folder and the name for PDF file download into the "PDF file name" textbox. It is important that the "Download PDF File" checkbox is selected and marked. "Actual width" option is default selected and works fine for my example cases. In this screen next thing we will do is Executing the convertion by F8 shortcut.

After you have supplied the spool request number and the pdf file folder and the pdf file name, the RSTXPDFT4 will confirm the PDF conversion and will ask you if you want the PDF conversion to take place in the background. It is important that you select "NO" to this question. You have to continue to the converting SAP Smartforms or SAPScript output into PDF with the NO option. Selecting NO option will activate the file download and file save dialog screen and will enable SAP users or ABAP developers save the spool request as PDF file.

Online PDF conversion may take some time according to the size of the spool request you want to convert into PDF file format.

ABAP program RSTXPDF4 will end up with a file "Save as" dialog screen where you can once more define or change the storage folder and the file name of the converted PDF file of the spool request. Save the PDF conversion file on your computer.

Finally, a log report will display the final status of the PDF conversion using the RSTXPDF4 ABAP report. If the SAP system can convert PDF successfully, it will display a message like "Function CONVERT_OTFSPOOLJOB_2_PDF successful" You have now the converted pdf file in the download folder and open, display and print the pdf output from spool if you want.

SAP Smartforms - How to Call Smartform within Example ABAP Program

Here is an SAP Smartforms step by step example to open and call Smartform within ABAP code. Within ABAP programs an SAP Smartform can be called and opened by calling the ABAP functionSSF_FUNCTION_MODULE_NAME, we will see in the example ABAP code which is included with this Smartforms tutorial. First, create a SAP Smartform report using ABAP transaction code "smartforms" within ABAP Editor. Or you can use an existing simple SAP Smartforms report to call from the example ABAP program. In this SAP SmartForms tutorial, the example uses a SmartForm named "ZSMARTFORMS_SALES_DOCUMENTS". The SmartForm application "ZSMARTFORMS_SALES_DOCUMENTS" takes a table valued parameter to use as an internal table within SmartForms ABAP codes. This SmartForms parameter table is "it_vbak" which is declared in type table of VBAK SAP Sales and Distribution table. SAP VBAK table is contains Sales Document header data. As you will see in the below ABAP codes, the program select a range of VBAK Sales Document records into an internal table variable it_vbak. Later the variable table is passed to the SAP SmartForm as a TABLE argument. It is important that the table variable is correctly declared within the Smartform 's "Global Settings > Form Interface > Tables" section. As you will see in the below screenshot, it_vbak is declared as : IT_VBAK TYPE VBAK

Example ABAP Program to Call Smartform Here is the example ABAP code to call SAP SmarForms from a program or an ABAP report. Please note that we have ABAP codes which call ABAP function SSF_FUNCTION_MODULE_NAMEwith formname parameter is set to the target SAP Smartforms document. The SSF_FUNCTION_MODULE_NAME ABAP call returns the FM_NAME which is the compiled ABAP program identifier and is in type rs38l_fnam. The returned fm_name variable is then called using an ABAP Call Function method to open Smartform. While calling Smartform, the Table parameter is passed as an input argument. *&--------------------------------------------------------------* *& Report Z_CALL_SMARTFORM * *& Sample Function calls ZSMARTFORMS_SALES_DOCUMENTS smartform * *&--------------------------------------------------------------* REPORT Z_CALL_SMARTFORM. DATA : fm_name TYPE rs38l_fnam, it_vbak TYPE TABLE OF vbak. SELECT * FROM vbak into TABLE it_vbak WHERE vbeln GE '0100000004' AND vbeln LE '0100000010'.


SAP Smartforms Tutorial - Table Calculations using Count

SAP Resourc es

In this SAP Smartforms tutorial, I want to show how can SAP Smart Forms developers can use SAP Table Calculations using Count function. Tutorial Assume that you have a SAP Smartform sample report listing a list of SAP Smartform SAP documents created on your ABAP development system. In this Smartform tutorial, We will add Forums a new column and which will be an auto number field, numbering the table rows beginning from 1, 2, and goes on incrementing by 1. SAP Tools SAP Transacti on Codes Table

Define the following global variables in the Global Data tab in Global Definitions screen on your SAP Smartform. The first global variable GV_COUNTER is the numeric variable that will be used in the table calculations with count function. The second global variable GV_ORDERNO is the string variable to display as text value on the Sort Order column.

Variable Name Type Assignment Associated Type Default Value GV_COUNTER TYPE INTEGER 1 GV_ORDERNO TYPE CHAR3
After the global variables are defined, now ABAP developers can go to Smartform table screen Calculations tab as seen in the below screenshot. Choose the CNT Number Operation from the dropdown list. Possible operation types are ; AVG Mean Value, CNT Number and SUM Total operations. Target Field Name will be GV_COUNTER numeric global variable we have already defined. In the Time column, I'll choose A After Loop. After Loop option will assign the new value to the counter right after each table row is processed by Smartform. With GV_COUNTER default value equal to 1, the first data row will have counter value 1 in the table cell. Then After Loop option selection will increase the counter by 1. So the next table row will have 2 in the counter cell. The possible Time options are A After Loop, B Before Loop, R Before Sorting, T After Sorting. If when the GV_COUNTER default value is 1, we choose Before Loop option, then before printing the first data row the counter value will be increased by 1 so the table cell will display 2 for the first row.

Now Smartform developer can create Program Lines object and Text object within a table line cell in the Main Area of the table.

Place the following code in the Program Lines. CLEAR GV_ORDERNO. WRITE GV_COUNTER TO GV_ORDERNO. This code will convert the numeric GV_COUNTER variable to string value and writes to GV_ORDERNO global variable. In the Input Parameters windows add GV_ORDERNO and GV_COUNTER to the table. In the Output Parameters windows add GV_ORDERNO.

We will now print the GV_ORDERNO string variable in the table cell using Text object.

After all is completed, activate Smartform then execute Smartform with F8. The final output will be as follows :

I hope ABAP developers will like this SAP Smartforms tutorial which focus how to deal with table calculations.

SAP SmartForms Download as SmartForm PDF Format using WS_DOWNLOAD and cl_gui_frontend_services

In this ABAP tutorial, a Smartforms output is generated by the example ABAP report. Then an SAP Smartform to PDF convert is in sample ABAP codes. In the following steps Smartforms pdf file is downloaded to the SAP users' client computer. cl_gui_frontend_services class file_save_dialog method is used to identify the download path and the Smartforms PDF file name. CALL FUNCTION 'CONVERT_OTF' is used to convert Smartform OTF to PDF format. At last the Smartforms download is managed by call function WS_DOWNLOAD.

Set Text Elements of the ABAP Report The ABAP code is given at the end of this ABAP tutorial. But before you activate ABAP report, there are 2 text elements we should define and set values for. These two text elements are labels used on the SAP selection screen. First text element is the title of the selection frame. I chosed the text "Download Smartforms to Folder" as the title of the selection frame block. The second text element is the label of the file folder selection input textbox. These textbox with F4 help is requested open the file folder dialog and the SAP user can freely choose a folder where he or she wants to download the SmartForm in pdf format. Follow the menu selections : "SAP Menu > Goto > Text elements > Text symbols"

The Text symbols tab is the default active tab. Enter a text for the text symbol 001. This text for text-001 will be used as the label text of the frame on screen where the pdf converted SAP Smart Form document file path information is requested from the user.

Go to the Selection texts tab. You will see the PA_FILE entry without a text entered. This text will be seen on the GUI of the example ABAP report as the label of the input text area used for file folder path. This file folder is contains the full path set for the Smart Form document which is convert to pdf format.

Run the ABAP Report, Application Process Flow After the text symbols and selection texts are defined on the ABAP report Text elements screen, ABAP developers are now ready to run the ABAP program. Press F8 to execute and run the ABAP report prepared to run a Smart Forms report and convert the smartforms output to PDF format and on the next step download the pdf smartform document on client computer into the selected folder. When the ABAP application is started, the following screen is displayed. Click on the yellow text area and press F4 or click on the small icon next to the input text area to open the cl_gui_frontend_services screen File Save Dialog screen. The ABAP code to perform the opening of the cl_gui_frontend_services file save dialog screen is triggered from the AT SELECTION-SCREEN ON VALUE-REQUEST FOR event. In the ABAP Report source code, you can see that in value-request for event the PERFORM method calls the SelectFolder form routine.

When the cl_gui_frontend_services class successfully displays the below File Save Dialog screen, SAP users can choose the file folder and give a name for the pdf conversion of SmartForms report. If you look at the ABAP codes where "CALL METHOD cl_gui_frontend_services=>FILE_SAVE_DIALOG" file_save_dialog method of the cl_gui_frontend_services class is called, the default folder path, default pdf file name of the SAP SmartForms document and the file type are all set. But as I noted the user can change the download path, Smartforms pdf file name using the File Save Dialog screen.

For example, I decided to download the pdf converted SAP Smart Forms output on my computer's desktop with a file name download-smartform.pdf When you click on the Save button on the cl_gui_frontend_services file save dialog screen, the full path is displayed on the input textbox as shown below.

Now as you can see the SAP Smart Forms download path and the file name is selected.

SAP users are ready to press the F8 button or the

SAP execute icon to start the ABAP program.

After the successfull execution of the sample ABAP program, a Smart Forms output is converted into pdf file format and the resultant pdf file is saved on the target download folder with the desired file name as shown below.

The PDF output of the Smartforms document download-smartform.pdf is created on my computer desktop folder. You can see the Smartform pdf output on the screenshot.

BAP Code of the SAP Application which Convert Smart Forms to PDF Format and Downloads to Client Here is the ABAP code that I use to convert Smartform to PDF file format. Please pay attention to selection-screen block and selection-screen on value request for ABAP code blocks. cl_gui_frontend_services class is used to call method file_save_dialog to display the file save dialog screen GUI to the SAP users. REPORT ZDOWNLOADSM . DATA : gt_vbak TYPE TABLE OF vbak. DATA : form_name TYPE rs38l_fnam, gs_control_params TYPE ssfctrlop, gs_output_options TYPE ssfcompop. DATA : t_otfdata TYPE ssfcrescl, t_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE, " SAPscript: Text Lines t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE, " OTF Structure w_bin_filesize(10) TYPE c. DATA : gv_initialDirectory TYPE STRING, gv_filename TYPE STRING, gv_path TYPE STRING, gv_fullpath TYPE STRING. CONSTANTS : c_defaultpath(100) TYPE C VALUE 'C:\'. SELECTION-SCREEN BEGIN OF BLOCK BLOCK-1 WITH FRAME TITLE TEXT-001. PARAMETERS : pa_file LIKE RLGRAP-FileName DEFAULT c_defaultpath. SELECTION-SCREEN END OF BLOCK BLOCK-1. AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_file. PERFORM u_SelectFolder USING pa_file.

START-OF-SELECTION. PERFORM uf_GetReportData. PERFORM uf_GetSmartFormModuleName. PERFORM uf_RunSmartForm. PERFORM uf_ConvertToOTF. PERFORM uf_DownloadToClient. END-OF-SELECTION. form U_SELECTFOLDER using p_pa_file.

DATA : lv_subrc LIKE sy-subrc, lt_it_tab TYPE filetable. IF pa_file IS INITIAL. gv_initialDirectory = 'C:\'. ELSE. gv_initialDirectory = pa_file. ENDIF. " Display File Open Dialog control/screen CALL METHOD cl_gui_frontend_services=>FILE_SAVE_DIALOG EXPORTING WINDOW_TITLE = 'Save SmartForm as ...' DEFAULT_EXTENSION = '.pdf' DEFAULT_FILE_NAME = 'smartform.pdf' FILE_FILTER = '.pdf' INITIAL_DIRECTORY = gv_initialDirectory CHANGING FILENAME = gv_filename PATH = gv_path FULLPATH = gv_fullpath. IF sy-subrc = 0. " Write path on input area p_pa_file = gv_fullpath. ENDIF. endform. " U_SELECTFOLDER form UF_DOWNLOADTOCLIENT . DATA : lv_filename(128) TYPE C. lv_filename = gv_fullpath. CALL FUNCTION 'WS_DOWNLOAD' EXPORTING BIN_FILESIZE = w_bin_filesize FILENAME = lv_filename FILETYPE = 'BIN' TABLES data_tab = t_pdf_tab EXCEPTIONS FILE_OPEN_ERROR = 1 FILE_WRITE_ERROR = 2 INVALID_FILESIZE = 3 INVALID_TYPE = 4 NO_BATCH = 5

UNKNOWN_ERROR = 6 INVALID_TABLE_WIDTH = 7 GUI_REFUSE_FILETRANSFER = 8 CUSTOMER_ERROR = 9 NO_AUTHORITY = 10 OTHERS = 11. endform. " UF_DOWNLOADTOCLIENT form UF_GETREPORTDATA . SELECT * FROM vbak INTO TABLE gt_vbak WHERE vbeln EQ '0100000004'. endform. " UF_GETREPORTDATA form UF_GETSMARTFORMMODULENAME . CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = 'ZSMARTFORMS_SALES_DOCUMENTS' IMPORTING fm_name = form_name EXCEPTIONS no_form = 1 no_function_module = 2 OTHERS = 3. endform. " UF_GETSMARTFORMMODULENAME form UF_RUNSMARTFORM . gs_output_options-tdnoprev = 'X'. gs_control_params-no_dialog = 'X'. gs_control_params-getotf = 'X'. CALL FUNCTION form_name EXPORTING control_parameters = gs_control_params output_options = gs_output_options user_settings = 'X' IMPORTING job_output_info = t_otfdata TABLES it_vbak = gt_vbak EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3

user_canceled = 4 OTHERS = 5. endform. " UF_RUNSMARTFORM form UF_CONVERTTOOTF . t_otf[] = t_otfdata-otfdata[]. CALL FUNCTION 'CONVERT_OTF' EXPORTING FORMAT = 'PDF' MAX_LINEWIDTH = 132 IMPORTING BIN_FILESIZE = w_bin_filesize TABLES otf = t_otf lines = t_pdf_tab EXCEPTIONS ERR_MAX_LINEWIDTH = 1 ERR_FORMAT = 2 ERR_CONV_NOT_POSSIBLE = 3 ERR_BAD_OTF = 4. endform. " UF_CONVERTTOOTF Let me explain the above ABAP code in brief. There are exactly 5 PERFORM calls to functions within the ABAP program. These Perform calls are : PERFORM uf_GetReportData. PERFORM uf_GetSmartFormModuleName. PERFORM uf_RunSmartForm. PERFORM uf_ConvertToOTF. PERFORM uf_DownloadToClient. PERFORM uf_GetReportData. In this function SAP database tables are queried for the raw data of the SAP Smart Forms report. The result set of the ABAP SELECT query is stored in an ABAP internal table. PERFORM uf_GetSmartFormModuleName. This function contains a very basic Function Call to get the function name of the SAP Smart Forms report. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' is the main ABAP code of this code block. ssf_function_module_name is always called in ABAP codes to get the function module name of the SAP Smart Forms report using the name of the Smartforms report. PERFORM uf_RunSmartForm. In this function the Smart Forms report is executed using CALL FUNCTION form_name function call. Before the SAP Smartform document is generated, Smartforms output options and control parameter are

set to value so that there will be no dialog screen, no print preview screen and the output will be generated in otf format. PERFORM uf_ConvertToOTF. The important ABAP code in this function is the CALL FUNCTION 'CONVERT_OTF' function call. The OTF data is converted to PDF format in this stage of the ABAP report. The code to convert Smartforms OTF output to PDF takes place here with call function Convert_OTF. PERFORM uf_DownloadToClient. ABAP code CALL FUNCTION 'WS_DOWNLOAD' enables the pdf output of the SAP Smartforms document to be downloaded to the client computer with given file folder, file name, etc parameters. The ABAP function WS_DOWNLOAD is marked as obsolete but still works successfully in order to download Smartforms pdf file on users' computers.

SAP Smartforms Tutorial - Table Calculations using Sum Total

SAP Resour ces SAP Tutorial SAP Forums

Within this SAP Smartforms tutorial, I will share ABAP codes with SAP Smartforms developers showing how to use Table Calculations using Sum - Total function in Smartform document. Before going details with the Smartform table calculations, I want to note that the samples are created and executed on SAP Netweaver 7.01 ABAP Trial version. Please check the SAP Netweaver 7.01 ABAP trial version installation guide for details.

As the data source of the sample Smartform document, I will use the ZCARS ABAP table. The SAP Smartforms output will list the rows in ZCARS ABAP table. SAP So I create a new SAP Smartforms report using ABAP transaction code smartforms with Smart Tools Form name ZSSF_CARS_LIST. SAP Transac tion Codes Table In the Initialization phase of the Smart Form output, copy and paste following ABAP code which reads all rows from ZCARS ABAP table into internal table GT_ZCARS. The ABAP internal table data will be displayed in the Smartform table control later in this Smartforms tutorial. Go to Form > Global Settings > Global Definitions screen. Click on Initialization tab. REFRESH GT_ZCARS. SELECT * INTO TABLE GT_ZCARS FROM ZCARS. Please note that in the output parameters list we should place the GT_ZCARS global variable. I prefer to use GT_ZCARS also in the input parameters list. Here is the screenshot how Smartform developers can manage initialization section of this example output.

Of course, we have not yet defined the global variable GT_ZCARS. If you try to activate Samrtform, it will fail because of the undefined internal table. Let's define global variables that are required in this example SAP Smartforms tutorial. Go to Form > Global Settings > Global Definitions screen. Click on Global Data tab. Create the following global variables in the Global Data table as follows.


ABAP developers will realize that I used a custom type GTY_N10 in the Global Data declarations type. We have to define this data type in the SAP Smartform document before we can use it. Go to Form > Global Settings > Global Definitions screen. Click on Types tab. Type the followin ABAP code for type declaration. TYPES : BEGIN OF gty_N10, N10(10) TYPE N, END OF gty_N10.

Now we are ready to create SAP Smartforms Table control. Right click on Main window and chooseCreate > Table from context menu. The data of the table is from ABAP internal table we have defined in Global Data tab and populated in Initialization tab. Let's assing the data source GT_ZCARS to SAP Smartforms table as seen in the below screenshot. Go to the Data tab of the Table control, mark Internal Table checkbox. With data loop in internal table GT_ZCARS into GS_ZCARS structure or work area.

You will notice in the above screenshot that I added the CATEGORY field as sort criteria and mark theEvent on Sort Begin and Event on Sort End checkboxes. These checkmarks will cause Smartform to create events and additional event lines just before and after the Main Area of the Smartform table.

Let's now create line types for table rows. I define two line types; one for displaying item rows and the second is for displaying category sum and overall total line.

And here is the details of table line types when you click Table Painter buton.

Now we can configure Table Calculations tab to display sum of numeric values listed on table using SUM Total operation.

The first line in Table Calculations is for auto numbering rows in the table display. ABAP developers can find the details about CNT Number Calculation example in SAP Smartforms Table in this target Smartform tutorial. The second and third lines in Table Calculations manage the category subtotals and report total respectively.

Operation Field

Target Field Name



For Field

Name CNT Number SUM Total SUM Total B Before Loop GV_CATEGORYSUBTOTAL- A After GV_N N10 Loop A After GV_N GV_TOTAL-N10 Loop GV_COUNTER

Name S Sort CATEGORY Criterion S Sort CATEGORY Criterion

The above Table Calculations configuration will work as follows : After each row displayed in the table, the global variable GV_N is summed into GV_CategorySubTotal-N10 variable value. The GV_CategorySubTotal-N10 value will be reset to its original value with Category field sort criterion. This means GV_CategorySubTotal-N10 will sum GV_N values from each row within same category. When the category changes, and a new category items begin listing on the table GV_CategorySubTotal-N10 will be set to 0, the initial value. So to display Category Subtotals, we will display GV_CategorySubTotal-N10 just before it is reset to initial value in the Category Event on Sort End line.

Just before printing the GV_CATEGORYSUBTOTAL-N10 value on the Smartform Text control within the event line cell, I remove preceeding zeros from the global variable. * Remove preceeding zeros SHIFT GV_CATEGORYSUBTOTAL-N10 LEFT DELETING LEADING '0'. For the GV_TOTAL value which will display overall sum of the table row field, the third table calculation line will help Smartform developers. Note that this SUM calculation is same as previous calculation with exception this does not have a reset criteria. This means the sum operation will work for all table rows. The GV_N field variable calculated during table row display will be summed into target field GV_TOTAL-N10 till the end of all table rows. The GV_TOTALN10 total value can be easily displayed in SAP Smartforms table using the Table Footer section as follows.

After you activate SAP Smartform and run Smartform output, a similar report shown below will be displayed.

SAP Smartforms Table Parameter in Form Routine

Smartform developers use Form Routines just like ABAP functions to reuse common ABAP codes for specific purposes. A form routine can be called within SAP Smartform code blocks and help ABAP developer with a clear readable code. Although it is easy to pass parameters to a Smartform Form Routine, passing internal tables sometimes causes compile errors. I'ld like to share a tip with ABAP and Smartform developers how they can pass internal tables to a Smartform Form Routine for calculations in this tutorial. As a sample case, I'll try to pass pricing condition details in a KOMV internal table to my sample Smartform Form Routine. In Smartform Global Data, I have defined TKOMV as table variable using TYPE TABLE OF type assignment with KOMV associated type. TKOMV TYPE TABLE OF KOMV

In the Initialization code block, I've called RV_PRICE_PRINT_REFRESH and PRICING_GET_CONDITIONS functions to get pricing conditions and store them in global variable tkomv table. CALL FUNCTION 'PRICING_GET_CONDITIONS' EXPORTING comm_head_i = komk TABLES tkomv = tkomv. Now copy and paste following form routine codes in current SAP Smartform Form Routines tab as a new form routine. FORM CALCITEMDISCOUNT USING lwa_vbap TYPE vbap tkomv TYPE TABLE OF komv CHANGING lv_discount TYPE kawrt. *** ABAP CODE here reading tkomv table parameter for discount calculation ENDFORM. In an ABAP code block, use the following form call for above Smartform form routine as follows PERFORM calcitemdiscount USING gwa_vbap tkomv CHANGING lv_discount. Unfortunately when I compile or activate Smartform document, the following error message is displayed preventing the Smartform to activate successfully. @8O@ DISCOUNT Different number of parameters in FORM and PERFORM (routine: CALCITEMDISCOUNT, number of formal parameters: 5, number of actual Solution requires a simple trick. First of all ABAP developers will realize that in Form Routine definition the ABAP code is not parsed correctly although the Check tool in Form Routine tab did not throw an exception. First, go to Types tab in Smartform Global Definitions (under Global Settings node) and define a new type as table type of target structure.

TYPES tkomv2 TYPE TABLE OF komv. Now we can replace the table parameter in form routine definition with this new table type definition as follows. Only change the parameter definition, leave remaining ABAP code unchanged.

FORM CALCITEMDISCOUNT USING lwa_vbap TYPE vbap tkomv TYPE tkomv2 CHANGING lv_discount TYPE kawrt. *** ABAP CODE here reading tkomv table parameter for discount calculation ENDFORM. After above change is completed, you will be able to activate Smartform successfully and make PERFORM form routine calls within other ABAP code blocks in the Smartform document.

SAP Smartforms Table for Sales Order and Invoice Outputs

Smartforms table is used to display a list of data table rows on SAP Smartforms output documents. These data rows are generally Sales Order items for a Sales Order Confirmation output. Or item lines for a SAP Sales Invoice document. In this Smart Forms tutorial we'll display invoice data from SAP Sales Invoice table VBRK and VBRP, and sales order data from SAP Sales Order table VBAK and VBAP Just as seen in below SAP Smartform structure, a Smartform table has Header section, Main Area section and Footer section. In general, header section is used to display table column headers. Main area is used for listing table item lines. The footer is generally used for subtotals.

SAP Sales Order Confirmation Order Items Table In a Sales Order Confirmation Smartform output, there is a table parameter named ZTVBDPA which imports Sales Order items. The ZTVBDPA view has the structure VBDPA - Document Item View for Inquiries,Quotation,Order In the Smartform, in Main window section, Smartform developers can add a Table and display order items using this Smartforms table. Create the following field symbol definition in Global Definitions > Field Symbols tab. <FS> TYPE VBDPA

Then goto Main window where you want to display sales order details as a table. Right click on the window node, select Create > Table menu options.

Goto Data tab. In the first line, write the internal table ZTVBDPA which stores table data. Then choose A ASSIGNING from dropdown list since we will be using a field symbol variable <FS> for this SAP Smartforms tutorial.

This definition is equal to following ABAP report example in function. DATA ZTVBDPA TYPE TABLE OF VBDPA. FIELD-SYMBOLS <FS> TYPE VBDPA. LOOP AT ZTVBDPA ASSIGNING <FS>. * ABAP Code ENDLOOP. Then using Table Painter and Details buton on Table tab, row types can be defined which will be used within Smartforms table. Then to display POSNR position number of a sales order item, <FS>-POSNR can be used. In oder to show the order item material number, <FS>-MATNR can be used.

SAP Sales Invoice Items Table For a Sales Invoice SAP Smartform output, all invoice data is transferred from Smartform print program to the SAP Smartforms using import variable named IS_BIL_INVOICE IS_BIL_INVOICE is defined using the LBBIL_INVOICE (Billing Data: Transfer Structure to Smart Forms) structure type. IT_GEN component of the LBBIL_INVOICE stores Billing Item: General Data details which is used as base table to display invoice items on a SAP Smartforms document. Here is how invoice items table Data tab can be configured to list Sales invoice items.

Smartform developers can create GS_IT_GEN structure in Global Definitions > Global Data tab as follows. GS_IT_GEN TYPE LBBIL_IT_GEN

The table data definition creates ABAP code similar to shown below. DATA : GS_IT_GEN TYPE LBBIL_IT_GEN, IS_BIL_INVOICE TYPE LBBIL_INVOICE.


SAP Smartforms Table Tips ABAP developers can use Smartform Folder control to keep together a group of lines. For example, for a sales order item or for an invoice item you want to display 3 lines of data. But it is important to keep together these three lines on the same page. This is not easy if Smartforms Folder control is not used. Insert a Folder structure into the Table Main Area, move the item lines into the Folder control.

Then the trick is to mark the checkbox Page Protection as seen in the below screenshot.

Move Minus Sign from Right to Left of Negative Number in SAP Smartform

In ABAP when displaying or printing negative numeric value the minus sign is on the right of the value instead of left of the number. So ABAP developers or Smartform developers are required to format negative numbers and move minus sign from right to left of the number before printing it. This ABAP tutorial includes a following methods : number format option for SAP Smartform to shift the negative sign from right to the left of the number ABAP codes to move minus sign from right to the left of the negative number ABAP function module CLOI_PUT_SIGN_IN_FRONT to set negative sign to the left side of the number value

As best practice to print negative values with minus sign leading the value instead of trailing is to format negative numeric values according to your requirements. And the solution is as simple as using the (<C) formatting option in the Text control where you print the numeric value.

Here is ABAP code block which can help you convert a numeric value into string, condense string value to remove leading spaces and then move minus sign to left from right of negative number value. Please note that the following ABAP code reads numeric value into a local variable. Then checks if it is a negative number or not. If it has a negative numeric value then multiplies with -1 in order to take the absolute value of the numeric data. After making the number positive, the ABAP code saves it into a character variable which is used to display numeric value on Text object on SAP Smartform document. We've now get rid of the minus sign of the number value. Using SHIFT ... LEFT DELETE LEADING ' ' statement the leading space characters are cleared. If the original number value is negative, as last step of the ABAP script, the minus sign "-" is added in front of the character value by using CONCATENATE command. This is how ABAP developers can move minus sign from right of the negative number to left side by using ABAP code and display value on a Text object on SAP Smartform document. *DATA GV_CONDVALUE_TXT TYPE CHAR20. " in Global Data definition DATA lv_kwert TYPE kwert. lv_kwert = gs_it_kond-kwert. IF gs_it_kond-kwert < 0. lv_kwert = -1 * lv_kwert . ENDIF. WRITE lv_kwert TO gv_condvalue_txt. SHIFT gv_condvalue_txt LEFT DELETING LEADING ' '. IF gs_it_kond-kwert < 0.

CONCATENATE '-' gv_condvalue_txt INTO gv_condvalue_txt. ENDIF.

You can create a form method in order to simplify this ABAP code block for using every numeric value you print on your SAP Smartforms output documents. Using ABAP function module CLOI_PUT_SIGN_IN_FRONT is an other option to bring the minus sign to front of the negative number value. In order to use the CLOI_PUT_SIGN_IN_FRONT function module, ABAP developers should store the numeric value in a character like CLIKE data type. Here is an example where you can use the codes in your ABAP programs. DATA gv_negativenumericvalue TYPE kwert VALUE -100. DATA gv_negativenumericvalue_txt TYPE char40. WRITE gv_negativenumericvalue TO gv_negativenumericvalue_txt. CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' CHANGING value = gv_negativenumericvalue_txt. WRITE :/ 'negative number : ', gv_negativenumericvalue. WRITE :/ 'FM format number: ', gv_negativenumericvalue_txt. The output of the above ABAP sample report is as seen in below screenshot

Importance of the function module SSF_FUNCTION_MODULE_NAME

A function module is generated whenever a Smart Form is activated. This Smart Form could be called from the driver program by calling this function module as shown below: REPORT Zcall_smartform. CALL FUNCTION '/1BCDWB/SF00000359' * EXPORTING * ARCHIVE_INDEX = * ARCHIVE_INDEX_TAB = * ARCHIVE_PARAMETERS = * CONTROL_PARAMETERS = * MAIL_APPL_OBJ = * MAIL_RECIPIENT = * MAIL_SENDER = * OUTPUT_OPTIONS = * USER_SETTINGS = 'X' * IMPORTING * DOCUMENT_OUTPUT_INFO =

* JOB_OUTPUT_INFO = * JOB_OUTPUT_OPTIONS = * 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. But this is not an efficient way of calling Smart Form for the following reason: Whenever a Smart Form is generated, a function module is generated and the naming convention for that Smart Form is done internally by using Number range object or something similar. In the above case, the function module name is/1BCDWB/SF00000359. The function module for the next new and activated Smart Form would be /1BCDWB/SF00000360. So when this Smart Form is transported from the development to Quality or Production system, a new function module name is generated according to the number series available in that system. If the above program is transported to either quality or production system, the program might go for a dump as the function module is not available in that system. To handle this situation, we use the function module SSF_FUNCTION_MODULE_NAME to get the name of the function module for a Smart Form dynamically. If the form is not active, the function module SSF_FUNCTION_MODULE_NAME raises the exception NO_FORM. Look at the modified program below: REPORT zcall_smartform. DATA: fname TYPE rs38l_fnam. call function 'SSF_FUNCTION_MODULE_NAME' exporting formname = 'ZSMARTFORMS_TRAINING2' * VARIANT = ' ' * DIRECT_CALL = ' ' importing fm_name = fname * 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. * Now replace the function module name '/1BCDWB/SF00000359' * with the variable FNAME CALL FUNCTION FNAME * EXPORTING