Call Smart form present in different server into SAP ECC and display the same in ECC
Note: All the screenshots, code, data and documentations are made dummy for elaboration of this functionality.
Prepared by:
Kanishak Gupta
Target readers:
SAP Technical Consultants
Disclaimer: The screen shots shown in the document are taken in ECC 6.0 and GTS. The screens may differ in different versions of SAP.
Declaration:
I hereby declare that this document is based on my work experience and to the best of my knowledge this document does not contain any material that infringes the copyrights of any other individual or organization.
Introduction:
This document contains several steps to call the smart form present in other SAP server say SAP GTS and display it in SAP ECC. This process will be explained with the help of an example shown in the document.
Scenario:
There is an Invoice report in SAP ECC which displays the various invoices in ALV. On clicking the line item in ALV, the program should be able to get the smart from present in SAP GTS for the billing document in the line item of ALV. This is done to validate and display some special invoices like pro-forma invoices, replicated in SAP GTS, in SAP ECC system.
Steps to follow:
First let’s create a RFC function module in SAP GTS or server where the smart form is present.
Important Note: Different systems might use different function modules to display the smart form data. So our primary aim is to debug the system where the smart form is present and find out the steps by which the system displays that particular smart form.
The following example is only for fetching the invoice related smart form from SAP GTS for the billing document.
Create a RFC Function module with the import parameter as G_REF_NO type /SAPSLL/REFNO (field which stores the billing document number in SAP GTS).
The FM also contains two parameters as TABLES.W_JOB_OUTPUT_INFO as OTF output data and I_BAPIRET2 to store the error messages if there are any.
An invoice report is created in ECC which displays the billing documents (VBRK-VBELN) in ALV format.Once the line item in ALV is double clicked; program picks the billing document present in the line item and then finds the respective GTS server connected to ECC with the help of Function module “/SAPSLL/CD_ALE_RECEIVER_GET_R3”. Then the program calls the RFC created above which provides us the smart form data as OTF data. The OTF data is displayed as a smart form in ECC through FM “SSFDISPLAY_OTF”.
Important terms used:-
OTF – The Output Text Format (OTF) is the established SAP output format for printing forms. It consists of a number of simple, device-independent commands, thus allowing output to be directed to different output devices such as line printers and laser printers, or as an on-screen print preview. OTF is an explicit output format, which means that once SAP Smart Forms has generated an OTF output, no modifications can be made.
GTS – SAP Global Trade Services automates global trade processes and enables us to manage large numbers of business partners, and high volumes of documents while also helping us to comply with changing legal regulations. It facilitates global trade by providing us with the tools we require to respond to governments modernizing their systems and to customs authorities communicating electronically with businesses. SAP GTS also helps you to avoid costly delays in your import and export processes and allows you to respond quickly to global business opportunities while mitigating financial risks.
RFC – Remote Function Call (RFC) is the standard SAP interface for communication between SAP systems or with non SAP systems. RFC calls a function to be executed in a remote system.
Attached code for reference:-
a) Wrapper RFC function module
FUNCTION zgotc_comminvoice_formdata.
*”———————————————————————-
*”*”Local Interface:
*” IMPORTING
*” VALUE (G_REF_NO) TYPE /SAPSLL/REFNO
*” TABLES
*” I_JOB_OUTPUT_INFO TYPE TSFOTF
*” I_BAPIRET2 STRUCTURE BAPIRET2
*”———————————————————————-
* Get the Reference number in internal format
PERFORM sub_convert_ref_no CHANGING g_ref_no.
* Fetch the GUID’s and then the OTF data
PERFORM sub_fetch_guids USING g_ref_no CHANGING i_job_output_info []
i_bapiret2 [].
ENDFUNCTION.
*———————————————————————-*
***INCLUDE LZGOTC_COMMINVOICE_FORMDATASUB.
*———————————————————————-*
*&———————————————————————*
*& Form SUB_CONVERT_REF_NO
*&———————————————————————*
* Get the reference number in internal format
*———————————————————————-*
* <–FP_G_REF_NO Reference number
*———————————————————————-*
FORM sub_convert_ref_no CHANGING fp_g_ref_no TYPE /SAPSLL/REFNO.
* FM to convert the reference number into internal form
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
EXPORTING
input = fp_g_ref_no
IMPORTING
output = fp_g_ref_no.
ENDFORM. ” SUB_CONVERT_REF_NO
*&———————————————————————*
*& Form SUB_FETCH_GUIDS
*&———————————————————————*
* Fetch GUID’s and then OTF data
*———————————————————————-*
* –>FP_G_REF_NO Reference number
* <–FP_I_BAPIRET2 Return parameter
*———————————————————————-*
FORM sub_fetch_guids USING fp_g_ref_no type /SAPSLL/REFNO
CHANGING fp_i_job_output_info TYPE tsfotf
fp_i_bapiret2 TYPE ty_t_bapiret2.
*Local data declarations
DATA : l_guid_pobj TYPE /sapsll/pobj_guid_16,“Primary Key of Preceding Object
l_guid_trigg TYPE os_guid, “Globally Unique Identifier
l_guid_trigger TYPE char40, “GUID trigger
l_appl_log_handle TYPE balloghndl, “Application Log: Log
li_mes TYPE /sapsll/msg_if_t, “Message Interface
lw_bapiret2 TYPE bapiret2, “Return parameter
l_devtype TYPE rspopty “Spool: Device type name
*Get the primary GUID for the reference number from ECC
SELECT SINGLE
guid_pobj
FROM /sapsll/corref
INTO l_guid_pobj
WHERE refno EQ fp_g_ref_no.
IF sy–subrc EQ 0.
* Get Application GUID from PPFTTRIGG
SELECT SINGLE
os_guid
FROM ppfttrigg
INTO l_guid_trigg
WHERE appl_oid EQ l_guid_pobj
AND ttype EQ c_ttype.
IF sy–subrc EQ 0.
* Set Trigger GUID
l_guid_trigger = l_guid_trigg.
SET PARAMETER ID ‘TRIGGERGUID’ FIELD l_guid_trigger.
* Create Message interface to trigger the activity messages
PERFORM sub_create_message_interface USING l_guid_trigger
CHANGING li_mes.
* Initialize the application log
PERFORM sub_initialize_applog CHANGING l_appl_log_handle
fp_i_bapiret2.
* Get the device type
PERFORM sub_get_device_type CHANGING l_devtype
fp_i_bapiret2.
* Get OTF data
PERFORM sub_get_otf_data USING l_devtype
l_guid_pobj
l_appl_log_handle
CHANGING fp_i_job_output_info []
fp_i_bapiret2.
ELSE.
* Update BAPIRET2 structure if data from PPFTTRIGG is not found
MOVE: c_type TO lw_bapiret2–type,
c_id TO lw_bapiret2–id,
c_num2 TO lw_bapiret2–number.
APPEND lw_bapiret2 TO fp_i_bapiret2.
CLEAR lw_bapiret2.
ENDIF.
ELSE.
* Update BAPIRET2 structure if data from /sapsll/corref is not found
MOVE: c_type TO lw_bapiret2–type,
c_id TO lw_bapiret2–id,
c_num2 TO lw_bapiret2–number.
APPEND lw_bapiret2 TO fp_i_bapiret2.
CLEAR lw_bapiret2.
ENDIF.
ENDFORM. ” SUB_FETCH_GUIDS
*&———————————————————————*
*& Form SUB_CREATE_MESSAGE_INTERFACE
*&———————————————————————*
* Creates message interface for activity messages
*———————————————————————-*
* –>FP_G_GUID_TRIGGER Trigger GUID
* <–FP_I_MES Table for message interface
*———————————————————————-*
FORM sub_create_message_interface USING fp_l_guid_trigger type char40
CHANGING fp_li_mes TYPE /sapsll/msg_if_t
.
* Local data declarations
DATA: lw_mes TYPE /sapsll/msg_if_s. “Message Interface – Reduced
*Create Message interface to trigger the activity message for Z0999
lw_mes–prosn = c_prosn.
lw_mes–procs = c_procs.
lw_mes–pross = c_pross.
lw_mes–prosa = c_prosa.
lw_mes–ttype = c_ttype.
lw_mes–lgreg = c_lgreg.
lw_mes–guid_ppf_trigg = fp_l_guid_trigger.
APPEND lw_mes TO fp_li_mes.
CLEAR lw_mes.
*FM to upload FP_I_MESS into the memory so that the program gets the activity message
CALL FUNCTION ‘/SAPSLL/CUHD_PPF_MEM_UPD_TRANS’
EXPORTING
it_msg_if = fp_li_mes.
ENDFORM. ” SUB_CREATE_MESSAGE_INTERFACE
*&———————————————————————*
*& Form SUB_INITIALIZE_APPLOG
*&———————————————————————*
* Initialize the application log
*———————————————————————-*
* <–FP_G_APPL_LOG_HANDLE Application log handle
* <–FP_I_BAPIRET2 text Return parameter
*———————————————————————-*
FORM sub_initialize_applog CHANGING fp_l_appl_log_handle TYPE balloghndl
fp_i_bapiret2 TYPE ty_t_bapiret2.
* Local data declarations
DATA: l_extnumber TYPE balnrext, “Application Log: External ID
l_modno (20) TYPE c, “Index of External Session
lw_bapiret2 TYPE bapiret2. “Return parameter
* Build external id
l_extnumber = sy–uname.
l_modno = sy–modno.
CONCATENATE l_extnumber l_modno INTO l_extnumber.
* FM to initialize the application log
CALL FUNCTION ‘/SAPSLL/APPLOG_INIT’
EXPORTING
iv_extnumber = l_extnumber
iv_delete_mess = c_x
iv_default_set = c_x
iv_skip_search = space
CHANGING
cv_handle = fp_l_appl_log_handle
EXCEPTIONS
invalid_call = 1
log_header_inconsistent = 2
internal_error = 3
OTHERS = 4.
IF sy–subrc <> 0.
* Update BAPIRET2 structure if FM fails
MOVE: c_type TO lw_bapiret2–type,
c_id TO lw_bapiret2–id,
c_num1 TO lw_bapiret2–number.
APPEND lw_bapiret2 TO fp_i_bapiret2.
CLEAR lw_bapiret2.
ENDIF.
ENDFORM. ” SUB_INITIALIZE_APPLOG
*&———————————————————————*
*& Form SUB_GET_DEVICE_TYPE
*&———————————————————————*
* Get the device type
*———————————————————————-*
* <–FP_G_DEVTYPE Device type
* <–FP_I_BAPIRET2 Return parameter
*———————————————————————-*
FORM sub_get_device_type CHANGING fp_l_devtype TYPE rspoptype
fp_i_bapiret2 TYPE ty_t_bapiret2.
* Local data declarations
DATA: lw_bapiret2 TYPE bapiret2. “Return parameter
* FM to get the device type
CALL FUNCTION ‘SSF_GET_DEVICE_TYPE’
EXPORTING
i_language = sy–langu
i_application = c_app
IMPORTING
e_devtype = fp_l_devtype
EXCEPTIONS
no_language = 1
language_not_installed = 2
no_devtype_found = 3
system_error = 4
OTHERS = 5.
IF sy–subrc <> 0.
* Update BAPIRET2 structure if FM fails
MOVE: c_type TO lw_bapiret2–type,
c_id TO lw_bapiret2–id,
c_num1 TO lw_bapiret2–number.
APPEND lw_bapiret2 TO fp_i_bapiret2.
CLEAR lw_bapiret2.
ENDIF.
ENDFORM. ” SUB_GET_DEVICE_TYPE
*&———————————————————————*
*& Form SUB_GET_OTF_DATA
*&———————————————————————*
* Get OTF data
*———————————————————————-*
* <–FP_W_JOB_OUTPUT_INFO OTF data
* <–FP_I_BAPIRET2 text Return parameter
*———————————————————————-*
FORM sub_get_otf_data USING fp_l_devtype TYPE rspoptype
fp_l_guid_pobj TYPE /sapsll/pobj_guid_16
fp_l_appl_log_handle TYPE balloghndl
CHANGING fp_w_job_output_info TYPE tsfotf
fp_i_bapiret2 TYPE ty_t_bapiret2.
*Local data declarations
DATA : l_guid TYPE /sapsll/guid_16,“Primary Key as GUID in “RAW” Format
lw_bapiret2 TYPE bapiret2, “Return parameter
lw_output_options TYPE ssfcompop, “SAP Smart Forms: Smart Composer (transfer) options
lw_control_parameters TYPE ssfctrlop, “Smart Forms: Control structure
lw_job_output_info TYPE ssfcrescl, “Smart Forms: Return value at end of form printing
lw_job_output_options TYPE ssfcresop, “Smart Forms: Return value at start of form printing
lw_document_output_info TYPE ssfcrespd, “Smart Forms: Return Document
li_error_tab TYPE tsferror . “SAP Smart Forms: Runtime Error
* Maintain the output structure
lw_output_options–tdprinter = fp_l_devtype.
* Maintain the control structure
lw_control_parameters–no_dialog = c_x.
lw_control_parameters–getotf = c_x.
* Update variable L_GUID for input in below FM
l_guid = fp_l_guid_pobj.
* FM to get the OTF data
CALL FUNCTION ‘/SAPSLL/PRN_FORM_PROCESS’
EXPORTING
iv_guid_cuhd = l_guid
iv_formname = c_form
iv_appl_log_handle = fp_l_appl_log_handle
is_control_parameters = lw_control_parameters
is_output_options = lw_output_options
IMPORTING
es_document_output_info = lw_document_output_info
es_job_output_info = lw_job_output_info
es_job_output_options = lw_job_output_options
et_form_error_tab = li_error_tab
EXCEPTIONS
output_canceled = 1
OTHERS = 2.
IF sy–subrc <> 0.
* Update BAPIRET2 structure if FM fails
MOVE: c_type TO lw_bapiret2–type,
c_id TO lw_bapiret2–id,
c_num1 TO lw_bapiret2–number.
APPEND lw_bapiret2 TO fp_i_bapiret2.
CLEAR lw_bapiret2.
ELSE.
* Move the OTF data
fp_w_job_output_info [] = lw_job_output_info–otfdata [].
ENDIF.
ENDFORM. “SUB_GET_OTF_DATA
It is a test program which is created to show only the linkage of the program with the RFC and to show the steps to display the smart form.
Report ztest MESSAGE-ID ztest.
Tables: vbrk.
Types: ty_t_bapiret2 type table of bapiret2.“Return parameter
data: i_otf type tsfotf,
i_bapiret2 type ty_t_bapiret2,
w_bapiret2 type bapiret2,
l_dest type rfcdest.
PARAMETERS: s_ref type vbrk–vbeln.
* Get the corresponding GTS server
call function ‘/SAPSLL/CD_ALE_RECEIVER_GET_R3’
importing
ev_rfc_dest = l_dest
exceptions
no_rfc_destination_maintained = 1
customs_server_not_unique = 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.
* Call RFC FM to fetch the smart form OTF data
call function ‘ZGOTC_COMMINVOICE_FORMDATA’ destination l_dest
exporting
g_ref_no = s_ref
tables
i_job_output_info = i_otf
i_bapiret2 = i_bapiret2.
If i_bapiret2 is initial.” No error found
if i_otf is not initial.” OTF table is filled
* Call FM for OTF display
call function ‘SSFDISPLAY_OTF’
tables
otf = i_otf
exceptions
error = 1
others = 2.
if sy–subrc <> 0.
message i276.” invoice could not be displayed
endif.
endif.” I_OTF
else.“I_BAPIRET2
* Loop at all the messages for display
loop at i_bapiret2 into w_bapiret2.
* Display the messages
message id w_bapiret2–id type w_bapiret2–type number w_bapiret2–number.
endloop.
endif.“I_BAPIRET2