Downloading spool to PDF background

Hi friends
How can i downlaod spool to PDF format in back gorund.
i know we cna download background into server as we required in PDf format.
i am able to downlaod but when i go to AL11 tcode and open i am not able to see in PDF format..
is there any way to downlaod to front end PC through back ground ..
if the file store in application server how user can view the PDF document.
Please help

Hi Ramesh,
Check the Sample programs:
RSTXPDFT4
RSTXPDFT5
The FM is: CONVERT_ABAPSPOOLJOB_2_PDF
check this link as well.
http://help.sap.com/saphelp_47x200/helpdata/en/85/54c73cee4fb55be10000000a114084/frameset.htm
<b>Reward points if this helps.
Manish</b>

Similar Messages

  • Download spool to PDF document on application server

    Hi,
    I am using function CONVERT_OTFSPOOLJOB_2_PDF to convert a sapscript spool and then downloading the internal table provided to a pdf file on the application server. The sapscript form contains company logos.
    After transferring the file from the application server to PC and then opening the pdf document I get the following message:
    "There was an error while trying to parse an image."
    The PDF doc contains everything except the company logo.
    I noticed that this works (i.e. company logo is present in the downloaded file) when I transfer the internal table that contains the PDF contents onto my PC using GUI_DOWNLOAD using mode 'BIN'. However, when I transfer the contents of the same internal
    table to a file on the application server using abap statement:
    'Open Dataset <filename> FOR OUTPUT IN BINARY MODE'
    I get the problem described above.
    I noticed that SAP has provided standard program RSTXPDFT4 to convert a spool and download it into a PC file. However is there a similar program that downloads a spool onto the application server? Perhaps there is a 'special' way in downloading PDF documents onto the application server?
    I don't this problem with sapscripts that do not have a company logo.
    Is there a certain restriction on 'Open Dataset'with transfering logos in PDF documents?
    Any help would be greatly appreciated in the form of reward points.
    Thanks
    Liam

    Hi,
    We convert some of our spools to pdf and store them on the app server using following high level process.
    CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
           EXPORTING
                src_spoolid = p_spool
                no_dialog   = 'X'
                dst_device  = 'LOCL'
           TABLES
                pdf         = lt_pdf
           EXCEPTIONS
                OTHERS      = 0.
    Write PDF file
      CALL FUNCTION 'GUID_CREATE'
           IMPORTING
                ev_guid_32 = l_guid.
      CONCATENATE '/your_path_goes_here/'
                  l_guid
                  INTO l_filename.
      CONCATENATE l_filename '.pdf' INTO l_filename.
    Store
      OPEN DATASET l_filename IN TEXT MODE.
      IF NOT sy-subrc IS INITIAL.   " only write pdf if new
        LOOP AT lt_pdf.
          TRANSFER lt_pdf TO l_filename.
        ENDLOOP.
      ENDIF.
      CLOSE DATASET l_filename.
    If it doesn't work, I would 1st try and play with image type. I'm wondering if it's tripping on image conversion. Perhaps revert to 1st principles and try monochrome bitmap and a few variations thereof. I stand by my code above. Definitely works. HTH, Dave

  • Double print in one line,when convert spool to PDF

    Dear Expert:
    I have a problem to solve when convert spool to PDF,there is one line will double imaged.
    The form is created by smartforms.
    I have tryed many ways,retype the text or start a new line,all didn't works.
    So could any one tell me how to solve this problem.
    Many thanks.
    [Picture of the PDF|http://picasaweb.google.com/nika.wei/SAP#5274740000941172338]
    Edited by: Nika Wei on Dec 1, 2008 9:50 AM

    Thanks for your quick response.
    I used the program you mentioned to download spool to PDF.The download file is like the link picture.
    And the form will not overlap when I print it immediately.But it will overlap the first line when preview or convert to PDF. My user don't want to print it immediately they want to save it to PDF.
    I know maybe there is something wrong with the format, I tryed retype the text but it didn't works.

  • Download spool and convert it to pdf in background job

    Hello experts,
    RSTXPDFT4 works fine for me if i want to convert spools to pdf files in foreground mode.
    If i want to do this in background mode as a daily job i am not able to use RSTXPDFT4.
    With report RSTXPDFT5 i am able to download in background as binary data but not as pdf.
    So, i want to download spools to network shared folder in pdf formaat.
    Thanks for suggestions & Regards
    Janez

    If i use GUI_DOWNLOAD which is used in this function than i have to be loged on and file is saved in my sapworkdir on my computer and not on networh share.
    To create and save TXT file on network shared folder i have to use opendataset statement and write data in file. But i don't know how to use it or to implement it in program RSTXPDFT4 to save spool job with specific id as pdf file. If i pass spool job id to RSTXPDFT4 i can save pdf file on local drive inside of sapworkdir or any where on clien computer nd of course in dialog mode.
    I want to save specific spool job with specific spool ID in background mode on network folder.
    Thanks & Regards
    Janez

  • Spool to PDF Conversion in ECC6 from Report running in Background

    Hi Friends,
    Iam working in ECC6, I have created one Classical report with line size of 295 which is running in Background and spool is generating.
    But my requirement is I have to send this spool to email through PDF Attachment.
    Here i have to convert Spool of line size 295 to PDF format. and then using FM give mail to respective email ids.
    Here is the code i have written for your refference:
    IF sy-batch EQ 'X'.
        PERFORM get_job_details.
        PERFORM obtain_spool_id.
        PERFORM convert_spool_to_pdf.
        PERFORM process_email.
    endif.
    1.      FORM GET_JOB_DETAILS .
    Get current job details
         CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
            IMPORTING
            eventid                 = gd_eventid
            eventparm               = gd_eventparm
            external_program_active = gd_external_program_active
            jobcount                = gd_jobcount
            jobname                 = gd_jobname
            stepcount               = gd_stepcount
        EXCEPTIONS
          no_runtime_info         = 1
          OTHERS                  = 2.
    ENDFORM.                    " G
    2.  FORM OBTAIN_SPOOL_ID .
         CHECK NOT ( gd_jobname IS INITIAL ).
         CHECK NOT ( gd_jobcount IS INITIAL ).
         SELECT * FROM  tbtcp
                     INTO TABLE it_tbtcp
                     WHERE      jobname     = gd_jobname
                     AND        jobcount    = gd_jobcount
                     AND        stepcount   = gd_stepcount
                     AND        listident   <> '0000000000'
                     ORDER BY   jobname
                                jobcount
                                stepcount.
      READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
      IF sy-subrc = 0.
        MESSAGE s004(zdd) WITH gd_spool_nr.
        gd_spool_nr = wa_tbtcp-listident.
        MESSAGE s004(zdd) WITH gd_spool_nr.
      ELSE.
        MESSAGE s005(zdd).
      ENDIF.
    ENDFORM.                    " OBTAIN_SPO
    3.       CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
              EXPORTING
              src_spoolid              = gd_spool_nr
             no_dialog                = c_no
            dst_device               = c_device
         dst_device               = 'ZLOCL'
          PDF_DESTINATION          = 'X'
        IMPORTING
          pdf_bytecount            = gd_bytecount
        TABLES
          pdf                      = it_pdf_output
        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.
      CHECK sy-subrc = 0.
    *Transfer the 132-long strings to 255-long strings
      LOOP AT it_pdf_output.
        TRANSLATE it_pdf_output USING ' ~'.
        CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
      ENDLOOP.
      TRANSLATE gd_buffer USING '~ '.
      DO.
        it_mess_att = gd_buffer.
        APPEND it_mess_att.
        SHIFT gd_buffer LEFT BY 255 PLACES.
        IF gd_buffer IS INITIAL.
          EXIT.
        ENDIF.
      ENDDO.
    ENDFORM.                    " CONVERT_SPOOL_TO_PDF
    4.     FORM PROCESS_EMAIL .
            DESCRIBE TABLE it_mess_att LINES gd_recsize.
          *DESCRIBE TABLE it_pdf_output LINES gd_recsize.
          CHECK gd_recsize > 0.
          PERFORM send_email USING p_email1.
    ENDFORM.                    " P
    5.   FORM SEND_EMAIL  USING    P_EMAIL.
         CHECK NOT ( p_email IS INITIAL ).
         REFRESH it_mess_bod.
    Default subject matter
      gd_subject         = 'Subject'.
      gd_attachment_desc = 'Attachnament'.
      CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
      it_mess_bod        = 'Message Body text, line 1'.
      APPEND it_mess_bod.
      it_mess_bod        = 'Message Body text, line 2...'.
      APPEND it_mess_bod.
    If no sender specified - default blank
      IF p_sender EQ space.
        gd_sender_type  = space.
      ELSE.
        gd_sender_type  = 'INT'.
      ENDIF.
    Send file by email as PDF  format
      PERFORM send_file_as_email_attachment
                                   TABLES it_mess_bod
                                          it_mess_att
                                          it_pdf_output
                                    USING  p_email1
                                          'PDF Document Attached'
                                          'PDF'
                                          gd_attachment_name
                                          gd_attachment_desc
                                          p_sender
                                          gd_sender_type
                                 CHANGING gd_error
                                          gd_reciever.
    ENDFORM.                    " SEND_EMAIL
    6.         FORM SEND_FILE_AS_EMAIL_ATTACHMENT  TABLES  it_message
                                                it_attach
                                          USING p_email
                                                p_mtitle
                                                p_format
                                                p_filename
                                                p_attdescription
                                                p_sender_address
                                                p_sender_addres_type
                                       CHANGING p_error
                                                p_reciever.
    DATA: ld_error    TYPE sy-subrc,
            ld_reciever TYPE sy-subrc,
            ld_mtitle LIKE sodocchgi1-obj_descr,
            ld_email LIKE  somlreci1-receiver,
            ld_format TYPE  so_obj_tp ,
            ld_attdescription TYPE  so_obj_nam ,
            ld_attfilename TYPE  so_obj_des ,
            ld_sender_address LIKE  soextreci1-receiver,
            ld_sender_address_type LIKE  soextreci1-adr_typ,
            ld_receiver LIKE  sy-subrc.
      DATA:   t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
              t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
              t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
              t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
              t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
              w_cnt TYPE i,
              send_mail LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
              w_sent_all(1) TYPE c,
              w_doc_data LIKE sodocchgi1.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    Fill the document data.
      w_doc_data-doc_size = 1.
    Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      LOOP AT p_email1.
        t_receivers-receiver =  p_email1-low.
        t_receivers-rec_type = 'U'.
        t_receivers-com_type = 'INT'.
        t_receivers-notif_del = 'X'.
        t_receivers-notif_ndel = 'X'.
        APPEND t_receivers.
      ENDLOOP.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
        EXPORTING
          document_data              = w_doc_data
          put_in_outbox              = 'X'
          sender_address             = ld_sender_address
          sender_address_type        = ld_sender_address_type
          commit_work                = 'X'
        IMPORTING
          sent_to_all                = w_sent_all
        TABLES
          packing_list               = t_packing_list
          contents_bin               = t_attachment
          contents_txt               = it_message
          receivers                  = t_receivers
        EXCEPTIONS
          too_many_receivers         = 1
          document_not_sent          = 2
          document_type_not_exist    = 3
          operation_no_authorization = 4
          parameter_error            = 5
          x_error                    = 6
          enqueue_error              = 7
          OTHERS                     = 8.
    Populate zerror return code
      ld_error = sy-subrc.
    Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.                    " SEND_FILE_AS_EMAIL_ATTACHMENT
    But when iam executing the report in Background mail is coming to respective email ids but when i opened that attachment which is in PDF is not opening, giving error as below:
    "Could not parsed Attachment.PDF!"
    and file size is less oringinallly file size should be 125 KB buit in mail it is coming only 3 KB.
    When i executed FM CONVERT_ABAPSPOOLJOB_2_PDF in foreground, its working fine for that Spool id.
    Any suggestions from u friends.
    regards,
    Sekhar.

    Hi when ur running tha application in background pass the below parameters .
    DATA:
    w_form_name TYPE tdsfname VALUE 'Zpramu_TEST',
    w_fmodule TYPE rs38l_fnam,
    w_cparam TYPE ssfctrlop,
    w_outoptions TYPE ssfcompop,
    W_bin_filesize TYPE i, " Binary File Size
    w_FILE_NAME type string,
    w_File_path type string,
    w_FULL_PATH type string.
    Internal tables declaration
    Internal table to hold the OTF data
    DATA:
    t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
    Internal table to hold OTF data recd from the SMARTFORM
    t_otf_from_fm TYPE ssfcrescl,
    Internal table to hold the data from the FM CONVERT_OTF
    T_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.
    This function module call is used to retrieve the name of the Function
    module generated when the SMARTFORM is activated
    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
    formname = w_form_name
    VARIANT = ' '
    DIRECT_CALL = ' '
    IMPORTING
    fm_name = w_fmodule
    EXCEPTIONS
    no_form = 1
    no_function_module = 2
    OTHERS = 3
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    Calling the SMARTFORM using the function module retrieved above
    GET_OTF parameter in the CONTROL_PARAMETERS is set to get the OTF
    format of the output
    w_cparam-no_dialog = 'X'.
    w_cparam-preview = space. " Suppressing the dialog box
                                                        " for print preview
    w_cparam-getotf = 'X'.
    Printer name to be used is provided in the export parameter
    OUTPUT_OPTIONS
    w_outoptions-tddest = 'LP01'.
    CALL FUNCTION w_fmodule
    EXPORTING
    ARCHIVE_INDEX =
    ARCHIVE_INDEX_TAB =
    ARCHIVE_PARAMETERS =
    control_parameters = w_cparam
    MAIL_APPL_OBJ =
    MAIL_RECIPIENT =
    MAIL_SENDER =
    output_options = w_outoptions
    USER_SETTINGS = 'X'
    IMPORTING
    DOCUMENT_OUTPUT_INFO =
    job_output_info = t_otf_from_fm
    JOB_OUTPUT_OPTIONS =
    EXCEPTIONS
    formatting_error = 1
    internal_error = 2
    send_error = 3
    user_canceled = 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.
    t_otf[] = t_otf_from_fm-otfdata[].
    Function Module CONVERT_OTF is used to convert the OTF format to PDF
    CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
    FORMAT = 'PDF'
    MAX_LINEWIDTH = 132
    ARCHIVE_INDEX = ' '
    COPYNUMBER = 0
    ASCII_BIDI_VIS2LOG = ' '
    PDF_DELETE_OTFTAB = ' '
    IMPORTING
    BIN_FILESIZE = W_bin_filesize
    BIN_FILE =
    TABLES
    otf = T_OTF
    lines = T_pdf_tab
    EXCEPTIONS
    ERR_MAX_LINEWIDTH = 1
    ERR_FORMAT = 2
    ERR_CONV_NOT_POSSIBLE = 3
    ERR_BAD_OTF = 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.
    To display File SAVE dialog window
    CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
    WINDOW_TITLE =
    DEFAULT_EXTENSION =
    DEFAULT_FILE_NAME =
    FILE_FILTER =
    INITIAL_DIRECTORY =
    WITH_ENCODING =
    PROMPT_ON_OVERWRITE = 'X'
    CHANGING
    filename = w_FILE_NAME
    path = w_FILE_PATH
    fullpath = w_FULL_PATH
    USER_ACTION =
    FILE_ENCODING =
    EXCEPTIONS
    CNTL_ERROR = 1
    ERROR_NO_GUI = 2
    NOT_SUPPORTED_BY_GUI = 3
    others = 4
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Use the FM GUI_DOWNLOAD to download the generated PDF file onto the
    presentation server
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    BIN_FILESIZE = W_bin_filesize
    filename = w_FULL_PATH
    FILETYPE = 'BIN'
    APPEND = ' '
    WRITE_FIELD_SEPARATOR = ' '
    HEADER = '00'
    TRUNC_TRAILING_BLANKS = ' '
    WRITE_LF = 'X'
    COL_SELECT = ' '
    COL_SELECT_MASK = ' '
    DAT_MODE = ' '
    CONFIRM_OVERWRITE = ' '
    NO_AUTH_CHECK = ' '
    CODEPAGE = ' '
    IGNORE_CERR = ABAP_TRUE
    REPLACEMENT = '#'
    WRITE_BOM = ' '
    TRUNC_TRAILING_BLANKS_EOL = 'X'
    WK1_N_FORMAT = ' '
    WK1_N_SIZE = ' '
    WK1_T_FORMAT = ' '
    WK1_T_SIZE = ' '
    IMPORTING
    FILELENGTH =
    tables
    data_tab = T_pdf_tab
    FIELDNAMES =
    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.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

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

    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.

    Creating a PDF file with over 99 pages through SAP seems rather unreasonable to me. What are you printing - Encyclopedia Britannica? For cripes sake... Have you thought about creating more than one spool request or using something completely different? Why do you have to do this through spool? You can get Smartform output directly into PDF, there are a lot of example out there.
    The only solution that comes to mind is rather brutal - create a copy of the function module and get rid of the popup. Although it just might time out after that...

  • Spool to PDF - First page blank w/ run in background

    I have a report that I write to spool using NEW PAGE PRINT ON/OFF.  I use the FM 'CONVERT_ABAPSPOOLJOB_2_PDF' to convert it to PDF.  Everything works fine in the foreground.  The problem is when a background job is scheduled, and the file written to the app server, a blank page is inserted at the beginning of the PDF file.  No data is lost, just a blank page inserted. 
    Has anyone seen this before?  If so, what was the fix?
    Thanks in advance
    Message was edited by: Thomas Branom

    The process is the same for both foreground and background. 
    Here is some of the code, please not I took out the page break for each new customer name, but the blank page still occurs when executing in background.
    ** Routine to write to spool
    FORM write_to_spool USING rv_download TYPE xfeld.
      DATA: s_out      TYPE get_data=>type_out,
            t_temp_out LIKE STANDARD TABLE OF s_out,
            v_kunnr    TYPE kunnr,
    *        v_name1    TYPE name1_gp,
            v_pos      TYPE i VALUE '0'.
      APPEND LINES OF cl_get_data->t_out TO t_temp_out.
      SORT t_temp_out BY kna1-name1 kna1-kunnr vbak-bstnk.
      FORMAT RESET.
    ** Turn on writing to spool
      IF rv_download = 'X'.
        NEW-PAGE PRINT ON
        NEW-SECTION
        PARAMETERS gs_pri_param
        NO DIALOG.
      ENDIF.
      LOOP AT t_temp_out INTO s_out.
    ** This will cause a page break at each new customer
    ** name, I even commented out the 'NEW-PAGE' and I still
    ** get a blank page at the beginning of the PDF
        IF v_name1 <> s_out-kna1-name1.
          IF NOT v_name1 IS INITIAL.
            ULINE AT /(c_line_size).
            NEW-PAGE.
          ENDIF.
          v_name1 = s_out-kna1-name1.
        ENDIF.
        v_pos = 3.
        WRITE : / '|'.
        WRITE AT v_pos s_out-vbak-vbeln.
        v_pos = v_pos + 13.
        WRITE AT v_pos(16) s_out-vbak-bstnk.
        v_pos = v_pos + 18.
        WRITE AT v_pos s_out-likp-inco1.
        v_pos = v_pos + 11.
        WRITE AT v_pos(20) s_out-likp-inco2.
        v_pos = v_pos + 22.
    *      WRITE AT v_pos(20) s_out-kna1-name1.
    *      v_pos = v_pos + 22.
        WRITE AT v_pos(20) s_out-kna1-ort01.
        v_pos = v_pos + 22.
        WRITE AT v_pos s_out-kna1-regio.
        v_pos = v_pos + 10 .
        WRITE AT v_pos(20) s_out-likp-lifex.
        v_pos = v_pos + 23.
        IF NOT s_out-likp-wadat IS INITIAL.
          WRITE AT v_pos s_out-likp-wadat.
        ENDIF.
        v_pos = v_pos + 13.
        IF NOT s_out-estprt IS INITIAL.
          WRITE AT v_pos s_out-estprt.
        ENDIF.
        v_pos = v_pos + 13.
        IF NOT s_out-actprt IS INITIAL.
          WRITE AT v_pos s_out-actprt.
        ENDIF.
        v_pos = v_pos + 13.
        IF NOT s_out-bolsnt IS INITIAL.
          WRITE AT v_pos s_out-bolsnt.
        ENDIF.
        v_pos = v_pos + 13.
        IF NOT s_out-cstclr IS INITIAL.
          WRITE AT v_pos s_out-cstclr.
        ENDIF.
        v_pos = v_pos + 13.
        IF NOT s_out-likp-lfdat IS INITIAL.
          WRITE AT v_pos s_out-likp-lfdat.
        ENDIF.
        WRITE AT c_line_size '|'.
      ENDLOOP.
      ULINE AT /(c_line_size).
    ** Turn off writing to spool
      IF rv_download = 'X'.
        NEW-PAGE PRINT OFF.
      ENDIF.
    ** Routine to convert spool to pdf and save to file
    FORM convert_pdf CHANGING rv_rc  TYPE sysubrc.
      DATA:  t_seltab     TYPE STANDARD TABLE OF rsparams,
             s_seltab     TYPE rsparams,
             s_tsp01      TYPE tsp01,
             t_tsp01      LIKE STANDARD TABLE OF s_tsp01,
             v_objtype    LIKE rststype-type,
             v_type       LIKE rststype-type,
             is_otf       TYPE char1,
             v_numbytes   TYPE i,
             v_numbytes1  TYPE i,
             v_pdfspoolno LIKE tsp01-rqident,
             v_jobname    LIKE tbtcm-jobname,
             v_jobcount   LIKE tbtcjob-jobcount,
    *         t_pdf        TYPE type_t_pdf,
             t_pdf        LIKE tline OCCURS 0 WITH HEADER LINE,
             s_pdf        LIKE LINE OF t_pdf,
             v_pdflength  TYPE i,
             v_filename   TYPE string.
      FIELD-SYMBOLS <f> TYPE ANY.
    ** Get the spool, if no spool, then give error and exit
      SELECT * FROM tsp01 INTO TABLE t_tsp01
               WHERE rqident = sy-spono.
      IF sy-subrc <> 0.
        rv_rc = 1.
        MESSAGE s060(zb) WITH sy-spono.    "NO SPool
        EXIT.
      ENDIF.
      LOOP AT t_tsp01 INTO s_tsp01.
    * Determine spool format
        CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
             EXPORTING
                  authority = 'SP01'
                  client    = s_tsp01-rqclient
                  name      = s_tsp01-rqo1name
                  part      = 1
             IMPORTING
                  type      = v_type
                  objtype   = v_objtype.
        IF v_objtype(3) = 'OTF'.
          is_otf = 'X'.
        ELSE.
          is_otf = space.
        ENDIF.
    * Convert to PDF format
        IF is_otf = 'X'.
          CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
               EXPORTING
                    src_spoolid              = s_tsp01-rqident
               IMPORTING
                    pdf_bytecount            = v_numbytes
                    pdf_spoolno              = v_pdfspoolno
                    btc_jobname              = v_jobname
                    btc_jobcount             = v_jobcount
               TABLES
                    pdf                      = t_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
                    OTHERS                   = 12.
          IF sy-subrc <> 0.
            rv_rc = 1.
            MESSAGE s061(za) WITH sy-spono.    "NO SPool
            EXIT.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
        ELSE.
          CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
               EXPORTING
                    src_spoolid              = s_tsp01-rqident
               IMPORTING
                    pdf_bytecount            = v_numbytes
                    pdf_spoolno              = v_pdfspoolno
                    btc_jobname              = v_jobname
                    btc_jobcount             = v_jobcount
               TABLES
                    pdf                      = t_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.
            rv_rc = 1.
            MESSAGE s061(za) WITH sy-spono.    "NO SPool
            EXIT.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
        ENDIF.
    * Download the file to local pc if requested and not in background.
        IF NOT p_fname1 IS INITIAL AND sy-batch IS INITIAL.
          v_filename = p_fname1.
          CALL FUNCTION 'GUI_DOWNLOAD'
               EXPORTING
                    filename                = v_filename
                    filetype                = 'BIN'
                    bin_filesize            = v_numbytes
               IMPORTING
                    filelength              = v_numbytes1
               TABLES
                    data_tab                = t_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
                    OTHERS                  = 22.
          IF sy-subrc <> 0.
            MESSAGE s062(za) WITH p_fname1.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ELSE.
            MESSAGE s065(zb) WITH 'Downloaded' v_numbytes
    p_fname1.
          ENDIF.
        ENDIF.
    * Write the PDF file server if requested.
        IF NOT p_fname2 IS INITIAL.
          v_numbytes1 = v_numbytes.
          DESCRIBE FIELD t_pdf LENGTH v_pdflength.
          LOOP AT t_pdf INTO s_pdf.
            IF v_numbytes > v_pdflength.
              TRANSFER s_pdf TO p_fname2.
            ELSEIF v_numbytes <> 0.
              ASSIGN s_pdf(v_numbytes) TO <f>.
              TRANSFER <f> TO p_fname2.
            ENDIF.
            v_numbytes = v_numbytes - v_pdflength.
          ENDLOOP.
          CLOSE DATASET p_fname2.  "Open in perform chk_dwnld_param
          MESSAGE s065(zb)  WITH 'Wrote' v_numbytes1 p_fname2.
        ENDIF.
      ENDLOOP.
    Message was edited by: Thomas Branom

  • Background Submit to Spool,  convert spool to PDF send via email

    I am calling an ABAP in the background. this abap makes use of a custom table as the main driver ie on each change of vendor within this custom table I want to create a spool and email the spool - the spool is suppossed to be created via a submit RMCB0300  with screen selection to to sap-spool and return. I then want the program to take the spool convert it to PDF and email.
    Problems I am encountering:
    1. writing to the spool via background ABAP  as follows
       submit RMCB0300 with selection-table rspar
                  to sap-spool
                  spool parameters %_print
                 archive parameters %_archive
                 without spool dynpro and return.
    Doesn't appear to be creating the spool - rspar is populated.
    2. Best way to retrieve the correct spool number.
    3. how to successfully convert PDF output after CONVERT_ABAPSPOOLJOB_2_PDF for email attachment - if this returns IT_PDF_OUTPUT.
    is this the best way to do it:
    Loop at IT_PDF_OUTPUT
          Translate IT_PDF_OUTPUT using ' ~'.
          concatenate gd_buffer it_pdf_output into gd_buffer
        endloop.
       translate gd_buffer using '~ '
    Do it_mess_att = gd_buffer.
         append it_mess_att.
         shift gd_buffer left by 255 places
         if gd_buffer is initial
           exit.
         endif.
    enddo.
    Thanks
    Mark
    Edited by: Matt on Apr 2, 2009 11:03 AM - amended title with formatting problems.

    Please find the code for converting SPool to pdf and sending mail
    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
         EXPORTING
           SRC_SPOOLID              = LV_MI_RQIDENT
           NO_DIALOG                = 'X'
           DST_DEVICE               = LV_PRINT_PARMS-PDEST
         IMPORTING
           PDF_BYTECOUNT            = LV_BYTECOUNT
           PDF_SPOOLID              = LV_RQIDENT
         TABLES
           PDF                      = LT_MTAB_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.
         MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
       ENDIF.
       LOOP AT LT_MTAB_PDF INTO LWA_MTAB_PDF.
         TRANSLATE LWA_MTAB_PDF USING ' ~'.
         CONCATENATE LV_GD_BUFFER LWA_MTAB_PDF INTO LV_GD_BUFFER.
         CLEAR LWA_MTAB_PDF.
       ENDLOOP.
       TRANSLATE LV_GD_BUFFER USING '~ '.
       DO.
         LWA_MESS_ATT = LV_GD_BUFFER.
         APPEND LWA_MESS_ATT TO LT_MESS_ATT.
         CLEAR LWA_MESS_ATT.
         SHIFT LV_GD_BUFFER LEFT BY 255 PLACES.
         IF LV_GD_BUFFER IS INITIAL.
           EXIT.
         ENDIF.
       ENDDO.
       CLEAR:  LWA_RECLIST, LT_RECLIST[],
               LT_OBJHEAD, LT_OBJHEAD[],
               LWA_OBJTXT,  LT_OBJTXT[],
               LWA_OBJBIN,  LT_OBJBIN[],
               LWA_OBJPACK, LT_OBJPACK[].
       "   CLEAR LT_OBJBIN.
       REFRESH LT_OBJBIN.
       LT_OBJBIN[] = LT_MESS_ATT[].
       DESCRIBE TABLE  LT_OBJBIN LINES LV_L_ATTACHMENT.
       LWA_OBJTXT = ''.
       APPEND LWA_OBJTXT TO LT_OBJTXT.
       CLEAR LWA_OBJTXT.
       DESCRIBE TABLE LT_OBJTXT LINES LV_L_TESTO.
       LT_DOC_CHNG-OBJ_NAME   = 'STATUS_REPORT'.
       LT_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.
       LT_DOC_CHNG-OBJ_DESCR  = 'Generated File'.               "#EC NOTEXT
       LT_DOC_CHNG-SENSITIVTY = 'F'.
       LT_DOC_CHNG-SENSITIVTY = 'O'.
       LT_DOC_CHNG-OBJ_PRIO   = '1'.
       LT_DOC_CHNG-DOC_SIZE   = LV_L_TESTO * 255.
       CLEAR LWA_OBJPACK-TRANSF_BIN.
       LWA_OBJPACK-HEAD_START = 1.
       LWA_OBJPACK-HEAD_NUM   = 0.
       LWA_OBJPACK-BODY_START = 1.
       LWA_OBJPACK-BODY_NUM   = LV_L_TESTO.
       LWA_OBJPACK-DOC_TYPE   = 'RAW'.
       APPEND LWA_OBJPACK TO LT_OBJPACK.
       CLEAR LWA_OBJPACK.
       LWA_OBJPACK-TRANSF_BIN = 'X' .
       LWA_OBJPACK-HEAD_START = 1.
       LWA_OBJPACK-HEAD_NUM   = 1.
       LWA_OBJPACK-BODY_START = 1.
       LWA_OBJPACK-BODY_NUM   = LV_L_ATTACHMENT.
       LWA_OBJPACK-DOC_TYPE   = 'PDF'.
       LWA_OBJPACK-OBJ_NAME   ='SPOOL'.
       LWA_OBJPACK-OBJ_DESCR = 'Test'.     
       LWA_OBJPACK-DOC_SIZE = LV_L_ATTACHMENT * 255.
       APPEND LWA_OBJPACK TO LT_OBJPACK.
       CLEAR LWA_OBJPACK.
       CLEAR LWA_RECLIST.
       LWA_RECLIST-COPY = 'X'.
       LWA_RECLIST-RECEIVER   = P_EMAIL.
       LWA_RECLIST-REC_TYPE   = 'U'.
       LWA_RECLIST-NOTIF_DEL  = 'X'.
       LWA_RECLIST-NOTIF_NDEL = 'X'.
       APPEND LWA_RECLIST TO LT_RECLIST.
       CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
         EXPORTING
           DOCUMENT_DATA              = LT_DOC_CHNG
           PUT_IN_OUTBOX              = ' '
           COMMIT_WORK                = 'X'
         TABLES
           PACKING_LIST               = LT_OBJPACK
           OBJECT_HEADER              = LT_OBJHEAD
           CONTENTS_BIN               = LT_OBJBIN
           CONTENTS_TXT               = LT_OBJTXT
           RECEIVERS                  = LT_RECLIST
         EXCEPTIONS
           TOO_MANY_RECEIVERS         = 1
           DOCUMENT_NOT_SENT          = 2
           DOCUMENT_TYPE_NOT_EXIST    = 3
           OPERATION_NO_AUTHORIZATION = 4
           PARAMETER_ERROR            = 5
           X_ERROR                    = 6
           ENQUEUE_ERROR              = 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.

  • Convert Spool to PDF and mail for the jobs not run in background.

    Dear All,
    I need to convert the spool job into pdf and mail as attachment for job not run in background.
    I am printing the bills  using the program  SD70AV3A to print the bills in a batch using the SUBMIT.
    But i am not using the spool options since its going to into waiting state in spool...and i need to change the printer properties to G
    to get the printer to print the reports as these jobs run in backgroud....but this solution is not acceptable solution.
    SUBMIT SD70AV3A
             WITH RG_KSCHL-LOW = 'ZRR'
             WITH RG_NACHA-LOW = '1'
             WITH PM_VERMO = '2'
             WITH PM_NSORT = '1'
             WITH RG_VBELN IN range.
    *        TO SAP-SPOOL
    *        SPOOL PARAMETERS print_parameters
    *        WITHOUT SPOOL DYNPRO
    *        VIA JOB name NUMBER number
    *        AND RETURN.
    so how do i get the spool number from the above after the job is submitted....and then convert into pdf and mail
    please suggest some solution. I have searched on net but most the solutions are say to run the job as background job...
    i have also looked into the program RSTXPDFT4 but it asks for the spool id ....how can i get spool id for the job that has been completed.
    please suggest some solution.
    Thanks
    Bhargava.

    Hi,
    Spool to PDF : FM 'CONVERT_ABAPSOOLJOB_2_PDF'
    Table TSP01 to get spool number
    You ,may need to convert OTF to PDF: FM CONVERT_OTF
    and the to binary : FM 'SMCS_XSTRING_TO_BINARY'
    To send mail use class: cl_document _bcs.
    Regards,
    Maria João Rocha

  • Convert spool to pdf and send in email sometimes attachment duplicated.

    Hi all, I have a process that creates a spool, converts it to a pdf and then attaches it to an email. My problem is that sometimes, the same attachment is duplicated.
    The process seems to work fine in debug mode (the attachment changes for each loop) but when I run it in the background, every few emails, it will duplicate an attachment.
    I have noticed that the size of the pdf seems to change properly but that the content of the pdf does not match.  So, it is like it gets the correct size of the pdf but not the body.
    This is code that a consultant wrote and I am pretty new to abap/sap. I have changed some of the code because it was trying to handle an endless loop (I figured it should not have to handle (be in) an endless loop). I changed that code and it is working but this previous issue still exists. Thanks for your help.
    *&      Form  PROCESS_EMPLOYEE
    FORM process_employee .
    * process appraisal only
      IF it_final[] IS NOT INITIAL .
    *                READ DISTRIBUTION LIST                                *
        REFRESH : it_email, it_idlient. 
    *Sort by supervisor
        SORT it_final[] BY supervisor.
        LOOP AT it_final INTO wa_final .
          APPEND wa_final TO it_final1 .
          AT END OF supervisor .
    * Perform to create the PDF from the Output
           report = 'zhr_pm_appemail'.
           PERFORM create_pdf using report.
    ** Perform to email the PDF attachment
    ** to the supervisor and the Mailing list
            subject = 'Performance Appraisals'.
            PERFORM process_email using subject.
            REFRESH it_final1 .
            CLEAR it_final1 .
            CLEAR wa_final .
            FREE MEMORY ID 'MEM'.
          ENDAT .
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " PROCESS_EMPLOYEE
    *&      Form  CREATE_PDF
    FORM create_pdf using report.
      DATA:  spoolno TYPE tsp01-rqident.
      DATA : p_repid TYPE sy-repid .
      DATA: v_len  TYPE i , v_len1  TYPE i .
      DATA: v_temp(8) TYPE c .
      DATA: p_uname TYPE sy-uname .
      DATA: it_tsp01 TYPE STANDARD TABLE OF tsp01 WITH HEADER LINE .
    *  DATA: it_pdf TYPE tline OCCURS 0 WITH HEADER LINE .
      TABLES: tsp01.
      DATA: var  TYPE c .
    *-- STRUCTURES
      DATA:
        lc_rq2name TYPE tsp01-rq2name.
      DATA:
        mstr_print_parms TYPE pri_params,
        mc_valid(1)      TYPE c,
        mi_bytecount     TYPE i,
        mi_length        TYPE i,
        mi_rqident       TYPE tsp01-rqident.
    *-- INTERNAL TABLES
      DATA:
        mtab_pdf    TYPE tline OCCURS 0 WITH HEADER LINE,
        mc_filename TYPE rlgrap-filename.
    *-- SELECTION SCREEN
      DATA:
        p_linsz TYPE sy-linsz VALUE 80, " Line size
        p_paart TYPE sy-paart VALUE 'X_65_80'.  " Paper Format
        p_uname = sy-uname .
        var = var + 1.
        p_repid = report.
    * START-OF-SELECTION .
      concatenate p_repid+0(9)
                  p_uname+0(3)
            into mc_filename
       separated by '_'.
    translate mc_filename to upper case.
    *-- Setup the Print Parmaters
      CALL FUNCTION 'GET_PRINT_PARAMETERS'
        EXPORTING
          authority              = space
          copies                 = '1'
          cover_page             = space
          data_set               = space
          department             = space
          destination            = space
          expiration             = '1'
          immediately            = space
          new_list_id            = 'X'
          no_dialog              = 'X'
          user                   = sy-uname
        IMPORTING
          out_parameters         = mstr_print_parms
          valid                  = mc_valid
        EXCEPTIONS
          archive_info_not_found = 1
          invalid_print_params   = 2
          invalid_archive_params = 3
          OTHERS                 = 4.
    IF sy-subrc = 0 .
    *--Make sure that a printer destination has been set up. If this is not done the PDF module abends.
    *-- Explicitly set line width, and output format so that
    *-- the PDF conversion comes out OK
      mstr_print_parms-linsz = p_linsz.
      mstr_print_parms-paart = p_paart.
            EXPORT it_final1 it_email p_email1 p_sender p_date vl_nmth
            TO MEMORY ID 'MEM' .
          IF report =   'zhr_pm_appandprogemail'.
             SUBMIT zhr_pm_appandprogemail TO SAP-SPOOL WITHOUT SPOOL DYNPRO
          SPOOL PARAMETERS mstr_print_parms
          VIA SELECTION-SCREEN AND RETURN.
          ENDIF.
          IF report =   'zhr_pm_appemail'.
             SUBMIT zhr_pm_appemail TO SAP-SPOOL WITHOUT SPOOL DYNPRO
          SPOOL PARAMETERS mstr_print_parms
          VIA SELECTION-SCREEN AND RETURN.
          ENDIF.
    ENDIF.
    *Find out what the spool number is that was just created
      perform get_spool_number using p_repid p_uname changing mi_rqident.
    *converting the spool request into pdf
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
        EXPORTING
          src_spoolid              = mi_rqident
          no_dialog                = space
          dst_device               = mstr_print_parms-pdest
        IMPORTING
          pdf_bytecount            = mi_bytecount
        TABLES
          pdf                      = it_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.
    *  call function 'DOWNLOAD'
    *    exporting
    *      bin_filesize      = mi_bytecount
    *      filename          = mc_filename
    *      filetype          = 'BIN'
    *    importing
    *      act_filename      = mc_filename
    *    tables
    *      data_tab          = it_mess_att.
      CHECK sy-subrc = 0.
    * Transfer the 132-long strings to 255-long strings
      LOOP AT it_pdf INTO wa_pdf.
        TRANSLATE wa_pdf USING ' ~'.
        CONCATENATE v_gd_buffer wa_pdf INTO v_gd_buffer.
        CLEAR wa_pdf .
      ENDLOOP.
      TRANSLATE v_gd_buffer USING '~ '.
      DO.
        it_mess_att = v_gd_buffer.
       APPEND it_mess_att.
        SHIFT v_gd_buffer LEFT BY 255 PLACES.
        IF v_gd_buffer IS INITIAL.
          EXIT.
        ENDIF.
      ENDDO.
    ENDFORM.                    " CREATE_PDF
    * FORM get_spool_nunber *
    * Get the most recent spool created by user/report                      *
    form get_spool_number using f_repid
          f_uname changing f_rqident.
      data:
            lc_rq2name TYPE rlgrap-filename.
      concatenate f_repid+0(6)
                  f_repid+7(3)
                  f_uname+0(3)
            into lc_rq2name.
    *   separated by '_'.
    translate lc_rq2name to upper case.
      select * from tsp01 where rq2name = lc_rq2name
        order by rqcretime descending.
          f_rqident = tsp01-rqident.
          exit.
          endselect.
          if sy-subrc ne 0.
            clear f_rqident.
          endif.
    endform. " get spool number
    *&      Form  SEND_MAIL
    FORM send_email USING p_email subject.
      REFRESH it_mess_bod.
    * Default subject matter
      gd_subject         = text-019 ."'Subject'.
      gd_attachment_desc = text-020 ."'Performance Appraisal'.
      IF subject =   'Performance Appraisals and Progression I'.
        gd_attachment_desc = 'PerfAppAndProg'.
      ENDIF.
      IF subject =   'Performance Appraisals'.
        gd_attachment_desc = 'PerfAppraisal'.
      ENDIF.
    * If no sender specified - default blank
      IF p_sender EQ space.
        gd_sender_type  = space.
      ELSE.
        gd_sender_type  = 'INT'.
      ENDIF.
    * Send file by email as .pdf
      PERFORM send_file_as_email_attachment
                                   TABLES it_mess_bod
                                          it_mess_att
                                    USING p_email
                                          subject
                                          'PDF'
                                          gd_attachment_desc
                                          gd_attachment_desc
                                          p_sender
                                          gd_sender_type
                                 CHANGING gd_error
                                          gd_reciever.
    ENDFORM.                    " SEND_MAIL
    *       FORM process_email                                            *
    FORM process_email using subject.
      DESCRIBE TABLE it_mess_att LINES gd_recsize.
      CHECK gd_recsize > 0.
      PERFORM send_email USING p_email1 subject.
    *  perform send_email using p_email2.
    ENDFORM.                    "process_email
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
    *       Send email
    FORM send_file_as_email_attachment TABLES it_message
                                              it_attach
                                        USING p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     CHANGING p_error
                                              p_reciever.
      CLEAR : ld_email , ld_mtitle , ld_format , ld_attdescription  ,
        ld_attfilename , ld_sender_address , ld_sender_address_type ,
        w_doc_data.
      REFRESH: t_packing_list.
      ld_email   = p_email.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    * Fill the document data.
      w_doc_data-doc_size = 1.
    * Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    * Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    * Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    * Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    * Add the recipients email address
      CLEAR t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      LOOP AT it_email.
    * Add the recipients email address
        t_receivers-receiver = it_email.
        t_receivers-rec_type = 'U'.
        t_receivers-com_type = 'INT'.
        t_receivers-notif_del = 'X'.
        t_receivers-notif_ndel = 'X'.
        APPEND t_receivers.
      ENDLOOP.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
    *            CONTENTS_HEX               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           EXCEPTIONS
                too_many_receivers         = 1
                document_not_sent          = 2
                document_type_not_exist    = 3
                operation_no_authorization = 4
                parameter_error            = 5
                x_error                    = 6
                enqueue_error              = 7
                OTHERS                     = 8.
      IF sy-subrc = 0.
        PERFORM update_infotype_0019 .
      ENDIF.
    * Populate zerror return code
    *  ld_error = sy-subrc.
    **  stop .
    *  READ TABLE t_receivers WITH KEY retrn_code = '0' .
    *  IF sy-subrc = 0 .
    *    v_update_flag = '1' .
    *    EXPORT v_update_flag TO MEMORY ID 'MEM2' .
    *  ENDIF .
    ** Populate zreceiver return code
    *  LOOP AT t_receivers.
    *    ld_receiver = t_receivers-retrn_code.
    *  ENDLOOP.
    ENDFORM.                    "send_file_as_email_attachment
    *&      Form  GET_NEXT_MONTH
    FORM get_next_month .
      CLEAR v_month .
      v_month = vl_nmth+4(2).
      REFRESH it_t247 .
      CLEAR it_t247 .
      CALL FUNCTION 'IDWT_READ_MONTH_TEXT'
        EXPORTING
          langu = 'E'
          month = v_month
        IMPORTING
          t247  = it_t247.
      CLEAR v_mon_text .
      v_mon_text = it_t247-ltx .
    ENDFORM.                    " GET_NEXT_MONTH
    Edited by: Katie Doody on Feb 24, 2010 12:30 AM

    Thank you for your response, this has allowed me to identify the problem. It is when I create the spool by using the code below. If I add a wait after this, the program works successfully. Is there another way to write the data to create a spool within my initial program rather than doing the submit? Could it be that it is putting data in memory?
    SUBMIT zhr_pm_appandprogemail TO SAP-SPOOL WITHOUT SPOOL DYNPRO
          SPOOL PARAMETERS mstr_print_parms
          VIA SELECTION-SCREEN AND RETURN.
    *& Report  ZHR_PM_APPANDPROGEMAIL
    REPORT  ZHR_PM_APPANDPROGEMAIL
            NO STANDARD PAGE HEADING
            LINE-SIZE 80
            LINE-COUNT 65(8).
    *        MESSAGE-ID zhr.
    * INTERNAL TABLES DECLARATION
    DATA: it_pdf TYPE tline OCCURS 0 ." WITH HEADER LINE .
    * WORK AEA DECLARATION
    DATA: wa_pdf TYPE tline .
    * Spool to PDF conversions
    *DATA: "gd_spool_nr TYPE tsp01-rqident,
    *      gd_destination TYPE rlgrap-filename,
    *      gd_bytecount TYPE tst01-dsize,
    DATA:v_update_flag TYPE c .                                   "flag for updating infotype 41 last appraisal date
    DATA: v_gd_buffer TYPE string.
    DATA: BEGIN OF it_final1 OCCURS 0 ,
            supervisor      TYPE persno ,
            pernr           TYPE persno ,
            ename           TYPE pa0001-ename ,
            subgroup        TYPE persk ,
            stext           TYPE t503t-ptext ,
            lastapp         TYPE dats ,
            lastjob         TYPE dats ,
            email           TYPE ztype,
            darxx(5)        TYPE c,
            progression(1)  TYPE c,
            supervisor_desc(50) TYPE c,
          END OF it_final1 .
    DATA:   t_packing_list TYPE sopcklsti1 OCCURS 0 WITH HEADER LINE,
            t_contents TYPE solisti1 OCCURS 0 WITH HEADER LINE,
            t_receivers TYPE somlreci1 OCCURS 0 WITH HEADER LINE,
            t_attachment TYPE solisti1 OCCURS 0 WITH HEADER LINE,
            t_object_header TYPE solisti1 OCCURS 0 WITH HEADER LINE,
            w_cnt TYPE i,
            w_sent_all(1) TYPE c,
            w_doc_data TYPE sodocchgi1 .
    DATA: gd_error    TYPE sy-subrc,
          gd_reciever TYPE sy-subrc.
    DATA: v_flag TYPE c VALUE '1' .
    DATA: BEGIN OF it_final OCCURS 0 ,
            subgroup       TYPE persk ,
            supervisor     TYPE persno ,
            pernr          TYPE persno ,
            ename          TYPE pa0001-ename ,
            stext          TYPE t503t-ptext ,
            lastapp        TYPE dats ,
            lastjob        TYPE dats ,
            email          TYPE ztype,
            progression(1) TYPE c,
            supervisor_desc(50) TYPE c,
          END OF it_final .
    DATA:it_t247 TYPE STANDARD TABLE OF t247 WITH HEADER LINE .
    DATA: it_email TYPE STANDARD TABLE OF zemail WITH HEADER LINE.
    *VARIABLE DECLARATION
    DATA: p_date   TYPE sy-datum ,               "excution date
          vl_date  TYPE sy-datum ,
          p_email1 TYPE somlreci1-receiver ,     "receiver
          p_sender TYPE somlreci1-receiver .     "sender
    DATA:  w_recsize TYPE i.
    DATA: gd_recsize TYPE i.
    DATA : vl_nmth TYPE sy-datum.
    DATA: v_month(2) TYPE n .
    DATA: v_mon_text TYPE t247-ltx .
    *START OF SELECTION
    START-OF-SELECTION .
      REFRESH t_receivers.
      IMPORT it_final1 it_email p_email1 p_sender p_date vl_nmth FROM MEMORY ID 'MEM'.
      PERFORM get_next_month .
      LOOP AT it_final1 .
        IF  it_final1-progression IS NOT INITIAL.
          MOVE-CORRESPONDING it_final1 TO it_final .
          APPEND it_final .
          CLEAR  it_final .
    *   Add the recipients email address
          t_receivers-receiver = it_final1-email.
          t_receivers-rec_type = 'U'.
          t_receivers-com_type = 'INT'.
          t_receivers-notif_del = 'X'.
          t_receivers-notif_ndel = 'X'.
          APPEND t_receivers.
        ENDIF.
      ENDLOOP .
      PERFORM write_output .
    *END OF SELECTION
    END-OF-SELECTION .
    *&      Form  WRITE_OUTPUT
    FORM write_output .
      DATA: l_date(14) TYPE c ,
            l_date_temp(14) TYPE c ,
            v_date(10) TYPE c ,
            v_date1(20) TYPE c ,
            v_date1_temp(20) TYPE c ,
            f_date(10) TYPE c.
      DATA: lv_stext TYPE t503t-ptext .
      CLEAR : v_date, v_date1.
      CONCATENATE p_date+4(02) p_date+6(02) p_date+0(04)'.' INTO v_date.
      CONCATENATE v_mon_text p_date+0(4) INTO l_date_temp SEPARATED BY space.
      CONCATENATE l_date_temp '.' INTO l_date.
      CONCATENATE v_mon_text vl_nmth+6(2) INTO v_date1_temp SEPARATED BY space.
      CONCATENATE v_date1_temp ',' INTO v_date1_temp.
      CONCATENATE v_date1_temp vl_nmth(4) INTO v_date1_temp SEPARATED BY space.
      CONCATENATE v_date1_temp '.' INTO v_date1.
      CONDENSE l_date .
      FORMAT INTENSIFIED ON.
      SKIP 4.
      WRITE:/(80) text-001 CENTERED .         "'METROPOLITAN UTILITIES DISTRICT'.
      WRITE:/(80) text-002 CENTERED .         "'OMAHA NEBR.'.
      SKIP 2.
      WRITE:/(80) text-003 CENTERED .        "'Inter-Departmental Communication'.
      FORMAT INTENSIFIED OFF.
      WRITE  :/(80) v_date CENTERED using edit mask '__/__/____'.   " v_date.
      SKIP 2.
      WRITE: /10 text-004.                     "'SUBJECT:   Performance Appraisals and Progression Increase'.
      SKIP 1.
      WRITE: /10 text-005, it_final1-supervisor_desc.  "'TO: Supervisor'.
      SKIP 1.
      WRITE: /10 text-006.                     "'FROM:      Anne M. Undajon, Director of Compensation and Benefits'.
      SKIP 2.
      WRITE:/10 text-007 .                       "'Listed below are the employees in your area who are due a '.
      WRITE:/10 text-008 ,l_date.                "'Performance Appraisal during the month of ',l_date.'.      "v_mon_text , P_date+0(4)
      WRITE:/10 text-009 .                       "'These employees are also eligible for a progression increase.
      WRITE:/10 text-010 .                       "' A performance appraisal form can be found on-line in the MUD '.
      WRITE:/10 text-011 .                       "'template section. The Performance Appraisal is to be completed '
      WRITE:/10 text-012 .                       "'and discussed with the employee by the immediate supervisor.'
      SKIP 2.
      WRITE:/10 text-013.                        "Signed forms should be returned to the Human Resource Department by '.
      WRITE:/10 v_date1.
      SKIP 2 .
      SORT it_final[] BY subgroup .
      LOOP AT it_final .
        CLEAR: lv_stext .
        lv_stext =  it_final-stext.
        AT NEW subgroup .
          TRANSLATE lv_stext TO UPPER CASE .
          WRITE:/(80) lv_stext CENTERED .
          SKIP 2 .
          WRITE: 10 text-014 .                      "'Employee name' .
          WRITE: 32 text-015 .                      "'Job Date' .
          WRITE :44 text-016 .                      "'Last Appraisal' .
          WRITE :59 text-021 .                      "'Employee' .
          WRITE :/10 '--------------------' , 32'----------', 44 '--------------', 59 '--------'.
        ENDAT .
        WRITE:/10 it_final-ename .
        WRITE: 32 it_final-lastjob using edit mask '__/__/____'.
        CONCATENATE it_final-lastapp+4(02) it_final-lastapp+6(02) it_final-lastapp+0(04) INTO f_date.
        WRITE :44 f_date using edit mask '__/__/____'.
        SHIFT it_final-pernr left deleting leading '0'.
        WRITE : 59 it_final-pernr.
        SKIP 2 .
      ENDLOOP.
      SKIP 4.
      WRITE :10 text-017.             "'Anne M. Undajon'.
      FORMAT INTENSIFIED ON.
      WRITE:/10 text-018.              "'Director of Compensation & Benefits'.
      FORMAT INTENSIFIED OFF.
    ENDFORM.                    " WRITE_OUTPUT
    *&      Form  GET_NEXT_MONTH
    FORM get_next_month .
      CLEAR v_month .
      v_month = vl_nmth+4(2).
      REFRESH it_t247 .
      CLEAR it_t247 .
      CALL FUNCTION 'IDWT_READ_MONTH_TEXT'
        EXPORTING
          langu = 'E'
          month = v_month
        IMPORTING
          t247  = it_t247.
      CLEAR v_mon_text .
      v_mon_text = it_t247-ltx .
    ENDFORM.                    " GET_NEXT_MONTH
    Edited by: Katie Doody on Feb 24, 2010 4:07 PM

  • Spool to PDF stored in application server

    Hi Experts,
    Please, please.....I need help.......
    I have a problem with converting spool to PDF. If I download the spool to presentation, the output is fine, BUT when I download it to application server and try to view it in al11, a set of characters comes out and if I try to save it on my local drive from the application server, an error message pops out stating that it could not read the file because it is either not a supported file type or because the file has been damaged. Please help me. I've tried doing everything I can already. I cannot run the convertion of spool file to presentation because it always ends up as run time error, that's why I have no choice but to run it in background. These files will only be viewed by different offices. This files will NOT be sent via email.  Please, please.......help......I'm really, really desperate......Here's what I did with the program....Please tell me where I went wrong.....Help......I've been on it for days and this is really causing a major headache........
    DATA: BEGIN OF it_pdf_output OCCURS 0.
            INCLUDE STRUCTURE tline.
    DATA: END OF it_pdf_output.
    PARAMETERS: p_file TYPE LOCALFILE DEFAULT TEXT-F02 OBLIGATORY.
    DATA: gd_buffer TYPE STRING OCCURS 0 WITH HEADER LINE.
    lt_conv LIKE gd_buffer OCCURS 0 WITH HEADER LINE.
    DATA lv_string TYPE string.
    LOOP AT it_pdf_output.
    TRANSLATE it_pdf_output USING '~'.
    CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
    ENDLOOP.
    TRANSLATE gd_buffer USING '~'.
    APPEND gd_buffer.
    DO.
    counter = strlen( gd_buffer ).
    IF counter GE 255.
    lt_conv = gd_buffer(255).
    APPEND lt_conv.
    SHIFT gd_buffer LEFT BY 255 PLACES.
    ELSE.
    lt_conv = gd_buffer(counter).
    APPEND lt_conv.
    EXIT.
    ENDIF.
    ENDDO.
    IF lt_conv[] IS NOT INITIAL.
    OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    IF sy-subrc EQ 0.
    IF sy-subrc 0.
    MESSAGE e398(00) WITH 'Error creating file' p_file.
    ENDIF.
    LOOP AT lt_conv INTO lv_string.
    TRANSFER lv_string TO p_file.
    ENDLOOP.
    CLOSE DATASET p_file.
    IF sy-subrc EQ 0.
    ELSE.
    MESSAGE e398(00) WITH 'Error closing file' p_file.
    ENDIF.
    ELSE.
    MESSAGE e398(00) WITH 'Error creating file' p_file.
    ENDIF.
    ENDIF.

    Hi,
    maybe a look at Function Module 'CONVERT_ABAPSPOOLJOB_2_PDF' could solve your problem.
    Regards
    Mark-André

  • Spool to PDF output in application server

    Hi Experts,
               I have a problem with converting spool to PDF.  If I download the spool to presentation, the outputs is fine, BUT when I download it to application server and try to view it in al11, a set of characters comes out and if I try to save it on my local drive, an error message pops out stating that it could not read the file because it is either not a supported file type or because the file has been damaged.  Please help me.  I've tried doing everything I can already.  I cannot run the convertion of spool file to presentation because it always ends up as run time error, that's why I have no choice but to run it in background.  These files needs to be distributed to all branch offices.  Please, please.......help......I'm desperate......

    Hi Nikhil,
            I'm sorry....but I'm still stucked.  If I try to view the pdf output in AL11 this characters are still displayed "&#9552;&#17478;&#11569;&#11827;&#3338;&#9698;&#58319;&#54029;&#2610;‰&#8303;&#25194;&#3338;&#12119;&#26990;&#16750;&#29545;&#17774;&#25455;&#25705;&#28263;&#3338;&#25966;&#25711;&#25194;&#3338;&#13088;&#12320;&#28514;&#27149;&#2620;&#15373;&#2597;&#17509;&#30324;&#31088;&#25888;&#20559;&#21332;&#12832;†&#8262;&#28526;&#29728;&#17231;&#21842;&#18757;&#21024;&#8302;&#28530;&#28001;&#27680;&#19553;&#28263;&#8261;&#19981;&#2607;&#21625;&#28773;&#8239;&#18031;&#28276;&#3338;&#12115;&#30050;&#29817;&#28773;&#8239;&#21625;&#28773;&#12557;&#2607;&#16993;&#29541;&#18031;&#28276;&#8239;&#17263;&#30066;&#26981;&#29197;&#2607;&#20065;&#28005;&#8239;&#17968;", and when the basis transferred it to the local folder the same error came out that the file could not be read either it is corrupted or file type is not supported.  Please.....I've been on it for hours and can't seem to get the problem.  Here's what I did with the program....Please tell me where I went wrong.....Help......
    PARAMETERS: p_file TYPE LOCALFILE DEFAULT TEXT-F02 OBLIGATORY.
    DATA: gd_buffer TYPE STRING OCCURS 0 WITH HEADER LINE.
               lt_conv   LIKE gd_buffer OCCURS 0 WITH HEADER LINE.
    DATA lv_string TYPE string.
            LOOP AT it_pdf_output.
              TRANSLATE it_pdf_output USING '~'.
              CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
            ENDLOOP.
            TRANSLATE gd_buffer USING '~'.
            APPEND gd_buffer.
            DO.
              counter = strlen( gd_buffer ).
              IF counter GE 255.
                lt_conv = gd_buffer(255).
                APPEND lt_conv.
                SHIFT gd_buffer LEFT BY 255 PLACES.
              ELSE.
                lt_conv = gd_buffer(counter).
                APPEND lt_conv.
                EXIT.
              ENDIF.
            ENDDO.
            IF lt_conv[] IS NOT INITIAL.
              OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
              IF sy-subrc EQ 0.
                IF sy-subrc <> 0.
                  MESSAGE e398(00) WITH 'Error creating file' p_file.
                ENDIF.
                LOOP AT lt_conv INTO lv_string.
                  TRANSFER lv_string TO p_file.
                ENDLOOP.
                CLOSE DATASET p_file.
                IF sy-subrc EQ 0.
                ELSE.
                  MESSAGE e398(00) WITH 'Error closing file' p_file.
                ENDIF.
              ELSE.
                MESSAGE e398(00) WITH 'Error creating file' p_file.
              ENDIF.
            ENDIF.

  • Download Spool Asset History List

    Hi Gurus,
    I would like to download the spool of Asset History List (S_ALR_87011990).
    The standard download from SP01 isn't possible because the spool has many thousand pages.
    Anybody have a idea how is possible to download this spool?
    Thanks in advance,
    Have a nice day!
    Emanuele

    Honestly, I would never run a program even in the program which creates 66,000 pages.
    It is a sever stress on the system. I would truncate the report into different parts (may be by asset class??) and run the report.
    I do not think there is any program to download the report in the background.
    If you are interested to download the spool in pdf use transaction ZSPOOL

  • Spool to PDF using RSTXPDFT4

    Hello experts,
    I am using <b>RSTXPDFT4</b> to convert SPOOL(<b>Script</b>)  to PDF. It works fine in foreground if the number of pages is < 100.
    But, if the pages are > 100 then it asks for running in background. I have chosen to run in background. But It did not ask me to specify the file path for creating the pdf file!
    I am wondering where the pdf file is stored in this case ?? !!!.   Anybody has encountered this before ????
    It also noticed that it is creating one more spool number (<b>binary format</b>)  when u specify it run the program <b>RSTXPDFT4</b> in background.

    Hello experts,
    RSTXPDFT4 works fine for me if i want to convert spools to pdf files in foreground mode.
    If i want to do this in background mode as a daily job i am not able to use RSTXPDFT4.
    With report RSTXPDFT5  i am able to download in background as binary data but not as pdf.
    So, i want to download spools to network shared folder in pdf formaat.
    Thanks for suggestions & Regards
    Janez

  • Smart form: Spool to PDF Conversion more than 100 pages.

    Hi folks,
    I have an issue with Function Module (FM) CONVERT_ABAPSPOOLJOB_2_PDF when the report to be converted has more than 100 pages.....i have explained this scenario as below
    We have been using the FM CONVERT_ABAPSPOOLJOB_2_PDF to convert ABAP report to PDF file and then send this via mail using FM SO_DOCUMENT_SEND_API1.....
    PDF conversion using FM CONVERT_ABAPSPOOLJOB_2_PDF works well if the number of report pages is less than 100....i.e the table pdf of the FM will contain the output as expected.....
    If the report has more than 100 pages, the the FM CONVERT_ABAPSPOOLJOB_2_PDF will schedule the conversion job as a background job and returns with a SY-subrc eq 0 and the table parameter pdf will ne empty.
    Could you suggest me a woorkaround in this situtaion...i.e how do I then get the output of the background job
    And  any process to convert Spool to PDF if having more than 100 pages.
    Thanks in Advance............

    Pb,
    If the report has more than 100 pages, the the FM CONVERT_ABAPSPOOLJOB_2_PDF will schedule the conversion job as a background job and returns with a SY-subrc eq 0 and the table parameter pdf will ne empty
    i would suggest you to if pages are more than 100 than you need to send report output to sp01 with spool request number by using fm job_open..job_close..
    than from sp01 you can convert pdf by running RSTXPDFT4 in se38.
    hope this would solve your problem.
    Amit.

Maybe you are looking for