Oct 8, 2011

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 function SSF_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

sap-smartforms-global-settings-form-interface-tables-variable-declaration


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_NAME with 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'.


CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZSMARTFORMS_SALES_DOCUMENTS'
IMPORTING
FM_NAME = fm_name
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3.

CALL FUNCTION fm_name
TABLES
it_vbak = it_vbak
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5.

I hope, SAP Smartforms developers will find this sample ABAP code useful as beginning to SAP Smartforms.


No comments: