Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 

Introduction:


I came across a situation where my client wants to download and print or access adobe form through Spool id. Here, we have to generate a Spool id.


The below are the following function modules and methods:




  • FP_JOB_OPEN

  • FP_FUNCTION_MODULE_NAME

  • FP_JOB_CLOSE

  • CALL FUNCTION 'FP_JOB_CLOSE'

  • POPUP_TO_CONFIRM

  • RSPO_OUTPUT_SPOOL_REQUEST

  • SCMS_XSTRING_TO_BINARY

  • cl_gui_frontend_services=>gui_download

  • cl_gui_frontend_services=>execute


Step 1:


Here, the default printer is being assigned along with other required parameters will create a new spool id.



    lv_fp_outputparams-dest     = default_printer.
lv_fp_outputparams-nodialog = 'X'.
lv_fp_outputparams-preview = ' '.
lv_fp_outputparams-reqnew = 'X'.
lv_fp_outputparams-reqimm = 'X'.

Step 2:


Call function ‘FP_JOB_OPEN’.


Here, the function module will open the adobe form and passes the parameters for printing.



    CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = lv_fp_outputparams
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
ENDIF.

Step 3:


Call function ‘FP_FUNCTION_MODULE_NAME’.


Gets the technical name of the generated form(Adobe form).



CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'           "& Form Processing Generation
EXPORTING
i_name = ' ' "&Adobe form name
IMPORTING
e_funcname = lv_fm_name.
IF sy-subrc <> 0.
ENDIF.
ELSE.

Step 4:


Call function ‘lv_fm_name’.


This variable contains technical name of the form.Here, this function module will take the name of the adobe form as the parameter and redirects to the form output. Here, we get a pdf in xsting format generated in ‘lv_fp_formutput-pdf’.



*&--- Call the generated function module

CALL FUNCTION lv_fm_name
EXPORTING
/1bcdwb/docparams = lv_fp_docparams
gw_loa = gw_loa
IMPORTING
/1bcdwb/formoutput = lv_fp_formoutput
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3.
IF sy-subrc <> 0.
ENDIF.

Step 5:


Call function ‘FP_JOB_CLOSE’.


This FM will close the current adobe form for printing. Declare a variable 'lv_spid' which takes the current spool id.



*&---- Close the spool job

CALL FUNCTION 'FP_JOB_CLOSE'
IMPORTING
e_result = lv_spid
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
ENDIF.

Step 6:


This block reads the list of all the spool id's and stores the current active spool id.



    lt_spid[] = lv_spid-spoolids[].
READ TABLE lt_spid INTO DATA(wa_spid) INDEX 1 .
wa_spoolid = wa_spid.
IF wa_spoolid > 0.

Step 7:


call function 'RSPO_OUTPUT_SPOOL_REQUEST'.

This FM will assign a spool id request to the default device.



      CALL FUNCTION 'RSPO_OUTPUT_SPOOL_REQUEST'
EXPORTING
device = default_printer
spool_request_id = wa_spoolid.
ENDIF.

Step 8:


Call function ‘SCMS_XSTRING_TO_BINARY’.


This function module converts xstring data to binary data from lv_fp_formoutput-pdf into data_tab.



CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_fp_formoutput-pdf
TABLES
binary_tab = data_tab.

Step 9:


Using this method we can download the generated form. Here, we have to mention the desired file path in the exporting parameter ‘Filename’. We can save and open our file in the desired path.



 CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = filename1
filetype = 'BIN'
CHANGING
data_tab = data_tab
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24.
IF sy-subrc <> 0.
ENDIF.

Step 10:


After printing the output in the pdf format, click on the print button to generate the spool request. Spool will be generated as we see the message 'Output request created'.



Step 11:


Navigate to 'SP02' which shows the list of active spool id's. The status 'Compl.' indicates that the spool id is successfully generated and 'Waiting' is under processing.



 

Conclusion:


This is how we generate adobe form with the help of spool id. We can get the spool id through the transaction as shown in the above step and the adobe form will be generated.


Thanks for Reading.


Hope this post would be helpful.