Skip to Content
0
Former Member
Aug 14, 2008 at 09:03 AM

Spool to PDF - Problems with downloading PDF file when converting with job

912 Views

Hi all!

I've got a problem. I've got a program that writes a smartform into the spool. After that, I am using the function modules RSTS_GET_ATTRIBUTES and CONVERT_OTFSPOOLJOB_2_PDF to convert it into PDF. I retrieve a internal table with the binary content for the PDF file. Now i can download the file to the desktop by using the method cl_gui_frontend_services=>gui_download.

But there is a problem: when the spool excesses 99 pages, the function module CONVERT_OTFSPOOLJOB_2_PDF asks the user via popup if the PDF should be created in background. If the user commits, the internal tables that should contain the binary PDF data is emtpy. A background job writes the binary data into the spool. The user has got an empty file that will be generated by cl_gui_frontend_services=>gui_download.

So, is it possible to suppress the popup to create the PDF allways online? Or how can I write the PDF file if there will be create any spool id in background? You'll find my current code below.

* Prüfen ob es die übergebene Spoolnummer überhaupt gibt
  SELECT SINGLE * FROM tsp01 INTO ls_tsp01 WHERE rqident = id_spoolid.
  IF ( sy-subrc <> 0 ).
    cf_error = 'X'.
    EXIT.
  ENDIF.


* TemSe-Objekte speichern sequentielle Daten. Ein TemSe-Objekt kann aus
* mehreren Teilen bestehen. Dieser FB ermittelt die wichtigsten Attribute
* eines TemSe-Objekts. Falls das Objekt aus mehreren Teilen besteht, werden
* die Attribute entsprechend zusammengefaßt.
  CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
    EXPORTING
      client        = ls_tsp01-rqclient
      name          = ls_tsp01-rqo1name
      part          = 1
    IMPORTING
      objtype       = ld_objtype
    EXCEPTIONS
      fb_error      = 1
      fb_rsts_other = 2
      no_object     = 3
      no_permission = 4
      OTHERS        = 5.

  IF ( sy-subrc <> 0 ).
    cf_error = 'X'.
    EXIT.
  ENDIF.

  IF ld_objtype(3) = 'OTF'.
    lf_is_otf = 'X'.
  ELSE.
    lf_is_otf = ' '.
  ENDIF.

  IF ( lf_is_otf = 'X' ).
*   Konvertiere OTF-Spoolauftrag nach PDF
    CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
      EXPORTING
        src_spoolid              = id_spoolid
        no_dialog                = ' '
*        pdf_destination          = 'T'
      IMPORTING
        pdf_bytecount            = ld_numbytes
        pdf_spoolid              = ld_pdfspoolid
        btc_jobname              = ld_jobname
        btc_jobcount             = ld_jobcount
      TABLES
        pdf                      = lt_pdf
      EXCEPTIONS
        err_no_otf_spooljob      = 1
        err_no_spooljob          = 2
        err_no_permission        = 3
        err_conv_not_possible    = 4
        err_bad_dstdevice        = 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.

    IF ( sy-subrc <> 0 ).
      cf_error = 'X'.
      EXIT.
    ENDIF.
  ELSE.
*   Konvertiere ABAP-Liste-Spoolauftrag nach PDF
    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
      EXPORTING
        src_spoolid              = id_spoolid
        no_dialog                = ' '
      IMPORTING
        pdf_bytecount            = ld_numbytes
        pdf_spoolid              = ld_pdfspoolid
        btc_jobname              = ld_jobname
        btc_jobcount             = ld_jobcount
      TABLES
        pdf                      = 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.

    IF ( sy-subrc <> 0 ).
      cf_error = 'X'.
      EXIT.
    ENDIF.
  ENDIF.

  WHILE ( lf_file_ok = '' ).

*   Die in der Tabelle lt_pdf enthaltenen Binärdaten werden nun in eine
*   Datei geschrieben. Da alle übergebenen Tickets in die gleiche Datei
*   geschrieben werden, kann der im Speicher gehaltente Protokolleintrag
*   gelesen werden
    CALL METHOD cl_gui_frontend_services=>gui_download
      EXPORTING
        bin_filesize              = ld_numbytes
        filename                  = cd_filename
        filetype                  = 'BIN'
*    append                    = SPACE
*    write_field_separator     = SPACE
*    header                    = '00'
*    trunc_trailing_blanks     = SPACE
*    write_lf                  = 'X'
*    col_select                = SPACE
*    col_select_mask           = SPACE
*    dat_mode                  = SPACE
      confirm_overwrite         = 'X'
*    no_auth_check             = SPACE
*    codepage                  = SPACE
*    ignore_cerr               = ABAP_TRUE
*    replacement               = '#'
*    write_bom                 = SPACE
*    trunc_trailing_blanks_eol = 'X'
*    wk1_n_format              = SPACE
*    wk1_n_size                = SPACE
*    wk1_t_format              = SPACE
*    wk1_t_size                = SPACE
*  IMPORTING
*    filelength                =
      CHANGING
        data_tab                  = lt_pdf
      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.