0% found this document useful (0 votes)
145 views

Print PDF Forms Batch Mode

The document provides ABAP code for opening a print job, printing a form, and closing the print job, including calling various SAP printing functions and retrieving the generated PDF table. It includes notes on using functions like GET_PRINT_PARAMETERS, FP_JOB_OPEN, FP_FUNCTION_MODULE_NAME, and FP_JOB_CLOSE to manage the print job and output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views

Print PDF Forms Batch Mode

The document provides ABAP code for opening a print job, printing a form, and closing the print job, including calling various SAP printing functions and retrieving the generated PDF table. It includes notes on using functions like GET_PRINT_PARAMETERS, FP_JOB_OPEN, FP_FUNCTION_MODULE_NAME, and FP_JOB_CLOSE to manage the print job and output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Daniel,

I've used these notes to get it working:

Job open:

FORM open_job.
DATA: fp_outputparams TYPE sfpoutputparams.
DATA: ls_params TYPE pri_params.

CALL FUNCTION 'GET_PRINT_PARAMETERS'


EXPORTING
no_dialog = 'X'
user = sy-uname
IMPORTING
out_parameters = ls_params.

fp_outputparams-reqimm = 'X'.
fp_outputparams-copies = ls_params-prcop.
fp_outputparams-device = 'PRINTER'.
fp_outputparams-preview = ' '.
fp_outputparams-nodialog = 'X'.
fp_outputparams-reqnew = 'X'.
fp_outputparams-connection = cl_fp=>get_ads_connection( ).
fp_outputparams-dest = ls_params-pdest.
fp_outputparams-reqfinal = 'X'.
fp_outputparams-getpdf = 'M'.
fp_outputparams-assemble = 'X'.
fp_outputparams-bumode = 'M'. " this is bundle mode

CALL FUNCTION 'FP_JOB_OPEN'


CHANGING
ie_outputparams = fp_outputparams
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 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.
ENDFORM.

Print:

FORM print.
DATA:
ls_function TYPE rs38l_fnam,
lp_interfacetype TYPE fpinterfacetype,
lp_outputparams TYPE sfpoutputparams,
lp_docparams TYPE sfpdocparams,
lp_formoutput TYPE fpformoutput,
lv_errstr TYPE string,
lo_error TYPE REF TO cx_root..
ADD 1 TO gv_index.

TRY.

CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'


EXPORTING
i_name = 'FORM_NAME'
IMPORTING
e_funcname = ls_function
e_interface_type = lp_interfacetype.

lp_docparams-langu = sy-langu.

CALL FUNCTION ls_function


EXPORTING
/1bcdwb/docparams = lp_docparams
IMPORTING
/1bcdwb/formoutput = lp_formoutput
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc NE 0.
CALL FUNCTION 'FP_GET_LAST_ADS_ERRSTR'
IMPORTING
e_adserrstr = lv_errstr.
WRITE:/ lv_errstr.
ELSE.
PERFORM retrieve_pdf_table USING gv_index
lp_formoutput-pages
CHANGING gt_result.
ENDIF.
CATCH cx_root INTO lo_error.
ENDTRY.
ENDFORM.

Job close:

FORM close_job.

DATA: ls_result TYPE sfpjoboutput,


lv_spoolid TYPE rspoid,
l_errstr TYPE string,
ls_result2 TYPE gty_result.

DATA: l_dest TYPE sypri_pdest,


l_spool_handle TYPE i,
l_spoolid TYPE tsp01-rqident,
l_total TYPE i.
DATA: ls_params TYPE pri_params.

CALL FUNCTION 'FP_JOB_CLOSE'


IMPORTING
e_result = ls_result
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
CALL FUNCTION 'FP_GET_LAST_ADS_TRACE'
IMPORTING
e_adstrace = l_errstr.

ELSE.
PERFORM retrieve_pdf_table USING gv_index
ls_result-remaining_pages
CHANGING gt_result.
READ TABLE gt_result INTO ls_result2 INDEX 1.

CALL FUNCTION 'GET_PRINT_PARAMETERS'


EXPORTING
no_dialog = 'X'
user = sy-uname
IMPORTING
out_parameters = ls_params.

l_dest = ls_params-pdest.
CALL FUNCTION 'ADS_CREATE_PDF_SPOOLJOB'
EXPORTING
dest = l_dest
pages = ls_result2-pages
pdf_data = ls_result2-content
immediate_print = 'X'
IMPORTING
spoolid = l_spoolid
EXCEPTIONS
no_data = 1
not_pdf = 2
wrong_devtype = 3
operation_failed = 4
cannot_write_file = 5
device_missing = 6
no_such_device = 7
OTHERS = 8.
IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDFORM.

Retrieve PDF table:

FORM retrieve_pdf_table USING VALUE(p_index) TYPE syindex


VALUE(p_pages) TYPE fppagecount
CHANGING p_pdf_tab TYPE gty_result_tab.
DATA lt_pdf_table TYPE tfpcontent.
DATA ls_result TYPE gty_result.

CALL FUNCTION 'FP_GET_PDF_TABLE'


IMPORTING
e_pdf_table = lt_pdf_table.
LOOP AT lt_pdf_table INTO ls_result-content.
MOVE p_index TO ls_result-index.
GET TIME.
MOVE sy-uzeit TO ls_result-time.
ls_result-size = xstrlen( ls_result-content ).
IF sy-tabix = lines( lt_pdf_table ).
ls_result-pages = p_pages.
ENDIF.
INSERT ls_result INTO TABLE p_pdf_tab.
ENDLOOP.
ENDFORM. "retrieve_pdf_table

You might also like