Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Want to download PDF from Spool using 'CONVERT_ABAPSPOOLJOB_2_PDF'

jaiganesh_s
Newcomer
0 Kudos
984


Hi ABAPers, I want to Download the PDF file using Program which is already generated in the SPOOL, I Tried using the below code

FM CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
    EXPORTING
      src_spoolid              = lv_spool_id
      no_dialog                = 'X'
      dst_device               = 'PDF1'
      pdf_destination          = 'X'
    IMPORTING
      pdf_bytecount            = lv_bin_size
      pdf_spoolid              = ev_spoolid
      bin_file                 = lv_xstring
    TABLES
      pdf                      = lta_lt_pdf
    EXCEPTIONS
      err_no_abap_spooljob     = 1
      err_no_spooljob          = 2
      err_no_permission        = 3
      err_conv_not_possible    = 4
      err_bad_destdevice       = 5
      user_cancelled           = 6
      err_spoolerror           = 7
      err_temseerror           = 8
      err_btcjob_open_failed   = 9
      err_btcjob_submit_failed = 10
      err_btcjob_close_failed  = 11
      OTHERS                   = 12.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
 LTA_LT_PDF internal table is getting not any data from the FM, I can only see the binsize and xstring getting filled up, How to proceed further, Tried to convert xstring to PDF using  

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer     = lv_xstring
    TABLES
      binary_tab = data_tab.
and

CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      bin_filesize            = lv_bin_size
      filename                = lv_path
      filetype                = 'BIN'
    TABLES
      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
      OTHERS                  = 22.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

 

But PDF which is getting downloading looks corrupted, What could be the reason? 

 

2 REPLIES 2

Sandra_Rossi
Active Contributor
0 Kudos
953

Please format your code nicely. See Solved: How to post code in SAP Community >=2024 - SAP Community.

e.g. see how it looks after:

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer     = lv_xstring
    TABLES
      binary_tab = data_tab.

 

Sandra_Rossi
Active Contributor
942

First of all, there are several types of spool requests, ABAP List, OTF (SAPScript Form, Smart Form), Adobe PDF, etc.

CONVERT_ABAPSPOOLJOB_2_PDF is only for spool requests of type ABAP List.

If you use PDF_DESTINATION = 'X', only the parameter BIN_FILE is filled (not PDF_BYTECOUNT and not PDF).

One possible solution (among others):

  1. don't use PDF_DESTINATION (same as passing it = space) which will fill the parameters PDF_BYTECOUNT and PDF,
  2. declare LTA_LX_PDF of type SOLIX_TAB (lines with one component of type X and length 255),
  3. no need of SCMS_XSTRING_TO_BINARY,
  4. download with BIN_FILESIZE = lv_bin_size and DATA_TAB = lta_lx_pdf.