Skip to Content
Author's profile photo Former Member

Creating Smartform output as PDF format in Spool/send any PDF file output to spool in backend:

Creating Smartform output as PDF format in Spool/send any PDF file output to
spool in backend:

This is required mostly when file size is more in SAP SPOOL
due to that printing might get delayed.

File size would be more when we are using more images in smartform
and also using pre-printed images. Sometimes it is must and should require
preprinted images in smartform, so we could not remove that from the smartform,
hence in this case we can go ahead with this method.

Even sometimes there is a requirement to pick the file from
presentation server/Any directory of application server/via some web based pdf
forms(http links), if we have to send those pdf files to spool in background to
generate spool request in pdf format we can go ahead with this code.

I have searched many links but I did not find any link to
send pdf output to spool in PDF format not in OTF format. Hence sharing this.

Below steps are required to generate the spool request in PDF format.

  1. After getting OTF data from smatform, convert it to
    pdf using “Convert_OTF” FM.
  2. Again convert this pdf output to xstring using below
    code.
  3. From step 2 pass this xstring internal table to
    spool using “ADS_CREATE_PDF_SPOOLJOB” FM.

Here we have to note one point i.e SAP Printer name which we are passing should support
PDF type else we will get error
. For this printer settings or configuration we have to
contact BASIS team.

Please find the below code regarding this:

REPORT ztest_pdffile_1.

DATA: cs_return        TYPE ssfcrescl.
DATA: formname TYPE tdsfname VALUE ‘ZTEST_TEST123’,

      fmname  TYPE rs38l_fnam.
DATA:      lc_pdf TYPE sopcklsti1doc_type VALUE ‘PDF’,

            gt_otf TYPE STANDARD TABLE OF itcoo.
DATAct_tline TYPE TABLE OF tline,

      cs_tline TYPE tline.
DATA: op_option TYPE ssfctrlop.
* ->Get smartform function module name
CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’

  EXPORTING

    formname = formname
*  VARIANT  = ‘ ‘
*  DIRECT_CALL              = ‘ ‘

  IMPORTING

    fm_name  = fmname
* EXCEPTIONS
*  NO_FORM  = 1
*  NO_FUNCTION_MODULE      = 2
*  OTHERS  = 3

  .
IF sysubrc <> 0.
* Implement suitable error handling here
ENDIF.

op_optiongetotf = ‘X’.

op_optionno_dialog = ‘X’.

op_optionpreview = space.
* -> Call smartform
CALL FUNCTION fmname

  EXPORTING
*  ARCHIVE_INDEX      =
*  ARCHIVE_INDEX_TAB  =
*  ARCHIVE_PARAMETERS =

    control_parameters = op_option
*  MAIL_APPL_OBJ      =
*  MAIL_RECIPIENT    =
*  MAIL_SENDER        =
*  OUTPUT_OPTIONS    =
*  USER_SETTINGS      = ‘X’

  IMPORTING

    job_output_info    = cs_return.
*->Convert OTF output to PDF

gt_otf[] = cs_returnotfdata[].
CALL FUNCTION ‘CONVERT_OTF’

  EXPORTING

    format                = lc_pdf

    max_linewidth        = 134
*  IMPORTING
*  bin_filesize          = lv_bin_size

  TABLES

    otf                  = gt_otf

    lines                = ct_tline

  EXCEPTIONS

    err_max_linewidth    = 1

    err_format            = 2

    err_conv_not_possible = 3

    err_bad_otf          = 4

    OTHERS                = 5.
* ->Convert PDF output to XSTRING
DATA: lv_pdfsource TYPE xstring.
FIELD-SYMBOLS:<p> TYPE x. ” <p> type any.
LOOP AT ct_tline INTO cs_tline.

  ASSIGN cs_tline TO <p> CASTING TYPE x.

  CONCATENATE lv_pdfsource <p> INTO lv_pdfsource IN BYTE MODE.
ENDLOOP.
* ->Create spool request in PDF format
CALL FUNCTION ‘ADS_CREATE_PDF_SPOOLJOB’

  EXPORTING

    printer  = ‘LOCL’            “Printer name supporting PDF device type
*  DEST    =

    pages    = 1

    pdf_data = lv_pdfsource        “XSTRING internal table
*  NAME    =
*  SUFFIX1  =
*  SUFFIX2  =
*  COPIES  =
*  PRIO    =

    IMMEDIATE_PRINT        = ‘X’
*  AUTO_DELETE            =
*  TITLELINE              =
*  RECEIVER =
*  DIVISION =
*  AUTHORITY              =
*  LIFETIME = ‘0’
* IMPORTING
*  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 sysubrc <> 0.
* Implement suitable error handling here
ENDIF.

Please find the attached document.

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Dipeshkumar Bhavsar
      Dipeshkumar Bhavsar

      Hi,

       

      I have a question here. I have PDF file stored at presentation system on specific location.

      I need to print the PDF file using SAP Spool.

       

      It would be very helpful if you can give some inputs.

      Regards,

      Dipeshkumar Bhavsar

      Author's profile photo Volkan Bekci
      Volkan Bekci

      Hi Guys;

      I use this usefull code to send OTF data to spool as PDF. Then I need PDF data from spool as binary. Generic CONVERT_ABAPSPOOLJOB_2_PDF  function is not working because of document type in spool, You may use RSPO_GET_MERGED_PDF_FROM_SPOOL  to get PDF spool data.