Gyan Factory

Gyan Factory
SAP Technical Project Support

Thursday, January 7, 2016

Need to Convert Spool Request(Generated Background Job ) Into PDF!

Standard FM-'CONVERT_OTFSPOOLJOB_2_PDF' is used to convert script otx spool to PDF.
Standard FM-'CONVERT_ABAPSPOOLJOB_2_PDF' is used to convert background job spool to PDF.

Step1. Here we have a simple program. Execute it.

Step2. We have the below output.

Step3. Go to Tx- SM36 and create and schedule a background job for the above report.

Step4. Background Job program name.

Step5. In Tx- SM37 run the job.The spool is generated. Select the spool.

Step6. Spool number is 3173 and click on the icon under type.

Step7. So here is the spool output as a result of background job.

Step8. The spool entry in the data base table.

 

Step9. Here is the program that reads the spool and converts it into PDF and saves it in a destination folder.
---------------------------------------------------------------------------------------------------------------------------------

PARAMETERS spool_no TYPE tsp01-rqident DEFAULT '3173',
             path TYPE string DEFAULT 'C:\Users\c5201446\Documents\DOWNLOAD\BGSPOOL.PDF'.


DATA ls_spool TYPE tsp01,
              lt_pdf TYPE TABLE OF tline,
             objtype LIKE rststype-type,
              file_size TYPE i.

START-OF-SELECTION.

  SELECT SINGLE FROM tsp01 INTO ls_spool WHERE rqident spool_no.
  IF sy-subrc IS INITIAL .
    CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
      EXPORTING
        client          ls_spool-rqclient
        name          ls_spool-rqo1name
        part          1
      IMPORTING
        objtype       objtype.

    IF objtype(3'OTF'" OTF TEXT- SAP SCRIPT OUTPUT


      CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
        EXPORTING
          src_spoolid     ls_spool-rqident
          no_dialog       ' '
        IMPORTING
          pdf_bytecount   file_size
        TABLES
          pdf             lt_pdf.

    ELSEIF objtype 'TEXT'"Job spool output of background report job


      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
        EXPORTING
          src_spoolid          ls_spool-rqident
          no_dialog            ' '
        IMPORTING
          pdf_bytecount        file_size
        TABLES
          pdf                  lt_pdf.


    ENDIF.


    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        bin_filesize file_size
        filename     path
        filetype     'BIN'
      TABLES
        data_tab     lt_pdf.


  ENDIF. 

---------------------------------------------------------------------------------------------------------------------------------
Step10. Execute the report and provide the spool number and a destination path to download the PDF.

Step11. Destination folder.

Step12. Execute it.

Step13. Destination folder. open the file.

Step14. So here we have the PDF.

No comments:

Post a Comment