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: 

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

Former Member
0 Kudos

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

5 REPLIES 5

former_member181962
Active Contributor
0 Kudos

Hi Thomas,

Is the proces to build the pdf file different for foreground and background?

Can you show us your coding?

Regards,

Ravi

former_member188685
Active Contributor
0 Kudos

Hi,

Check is there any extra NEW-PAGE triggering in background. do you have any NEW-PAGE in your Report.

Regards

vijay

0 Kudos

In background procesing this FM call program RSTXPDF5. ¿Can you run this program in background and foreground and tell us abaout results?

Regards.

0 Kudos

Thomas,

I just ran into this same problem today. This is ocurring because when you run your program in foreground with the NEW-PAGE PRINT OFF command, the dataset is immediately sent to the spool list with the previous sy-spono number. You can see this by running in debug, then checking SP01 right after the NEW-PAGE PRINT OFF command. If you run in background, the dataset is not committed to the spool list by the time you get to the PDF conversion function module. Therefore, when the dataset is finally committed, the sy-spono has one more page number added to it from the NEW-PAGE PRINT OFF command which I think is part of the cause. I found if you use the GET_PRINT_PARAMETERS function module to build your parameters for the new-page print on command, the blank page and page count correct themselves.

Marie

Message was edited by: Marie Wislocki

Former Member
0 Kudos

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