Skip to Content
0

Combine multiple spool request into one PDF file using CONVERT_OTFSPOOLJOB_2_PDF

May 05, 2017 at 08:26 AM

287

avatar image

HI

While combine the spool requests into one PDF using FM CONVERT_OTFSPOOLJOB_2_PDF , Somehow i'm not able to generate single PDF file. Instead it's generating separate PDF fils for each record.

Also after downloading the PDF files when I checked the content the all the PDF file.

i found all the file contains are same as first file.

But when I checked In SP01 all the PDF files have proper content according to the fetched record .

I have gone through all related threads but could not find anything related to the particular issue.

Here i am sharing the code in detail .

Please let me know for further detail.

Regards,

Prabin

Inside Main program :
 
 LOOP AT r_invoices.    " selected invoices stored here                    
        IF save_ok_code = 'PDF'.
         PERFORM create_pdf.
        ENDIF.
  ENDLOOP.


Form CREATE_PDF : 
*&---------------------------------------------------------------------*
*&      Form  CREATE_PDF
*&---------------------------------------------------------------------*
FORM create_pdf.
  CHECK mem_email = 'X' OR mem_email = 'S'.
  DATA: w_rq2name       LIKE nast-dsuf2,
        w_spoolno       LIKE tsp01-rqident,
        w_infile_cust   LIKE vbak-kunnr,
        w_infile_suf(4) TYPE c,
        p_file LIKE rlgrap-filename,         
        p_infile(50)    TYPE c.             "PDF file path
  w_infile_suf  = '.PDF'.

* Here we select Single in the pop up so control always goes to else part to genearte single PDF file.
  IF w_pdf_type = 'M'.
*   Multiple PDF
    w_infile_cust = p_kunag-low.
    IF NOT p_kunag-high IS INITIAL.
      w_infile_cust = 'Multiple'(025).
    ENDIF.
    SHIFT w_infile_cust LEFT DELETING LEADING '0'.
    CONCATENATE 'C:\temp\invoice_' w_infile_cust w_infile_suf
                 INTO p_infile.
    MOVE sy-uname TO w_rq2name.
  ELSE.
*   Single PDF
    if path is not INITIAL.
      CONCATENATE path 'invoice_' r_invoices-low w_infile_suf
                 INTO p_infile.
    else.
      CONCATENATE 'C:\temp\invoice_' r_invoices-low w_infile_suf
                 INTO p_infile.
    endif.
    MOVE r_invoices-low TO w_rq2name.
  ENDIF.


  CALL FUNCTION 'RSPO_FIND_SPOOL_REQUESTS'
    EXPORTING
*     ALLCLIENTS    = ' '
*     AUTHORITY     = ' '
*     DATATYPE      = '*'
*     HAS_OUTPUT_REQUESTS = '*'
*     RQ0NAME       = '*'
      rq1name       = 'PDF'
*     rq2name       = sy-uname    
      rq2name       = w_rq2name   
*     RQDEST        = '*'
*     RQIDENT       = 0
      rqowner       = sy-uname
    TABLES
      spoolrequests = rsporq
*    EXCEPTIONS
*     NO_PERMISSION = 1
*     OTHERS        = 2
    .
  IF sy-subrc = 0.
    CLEAR: sy-tfill, w_spoolno.
    DESCRIBE TABLE rsporq LINES sy-tfill.
    IF NOT sy-tfill IS INITIAL.
      SORT rsporq BY rqcretime DESCENDING.
      READ TABLE rsporq INDEX 1.
      MOVE rsporq-rqident TO w_spoolno.

      p_file = p_infile.
  if path is INITIAL.   
*      p_infile = 'test'.
      PERFORM download_w_ext           "dowload to file path 
                       USING p_file
                             'pdf'
                             'BIN'
*                             filesize
                             cancel.
     p_file = fullpath.
  endif.
   check cancel = space.

* Save the spool file to a local file
      SUBMIT zrstxpdft4                " calling Report   ZRSTXPDFT4                         
*                     via selection-screen
                       WITH spoolno  = w_spoolno
                       WITH download = 'X'
                       WITH p_file   = p_file
                       AND RETURN.
    ENDIF.
  ENDIF.
ENDFORM.                    " CREATE_PDF


REPORT ZRSTXPDFT4 :

*********************Report******************************************
******************************************************************
REPORT ZRSTXPDFT4 line-size 80.
*
* Read spool job contents (OTF or ABAP list) and convert
* to PDF, download PDF
* B20K8A0IKH replace WS_DOWNLOAD with GUI_DOWNLOAD
*
PARAMETERS:
  SPOOLNO LIKE TSP01-RQIDENT,
  DOWNLOAD AS CHECKBOX DEFAULT 'X',
  P_FILE LIKE RLGRAP-FILENAME DEFAULT 'C:\temp\file.pdf'. "#EC NOTEXT


  selection-screen skip 1.


selection-screen begin of block list_width with frame title text-010.
  parameters:
    report radiobutton group g1 default 'X',
    format radiobutton group g1,
    real radiobutton group g1.
selection-screen end of block list_width.


DATA otf like itcoo occurs 100 with header line.
DATA CANCEL.
DATA PDF LIKE TLINE OCCURS 100 WITH HEADER LINE.
DATA DOCTAB LIKE DOCS OCCURS 1 WITH HEADER LINE.
DATA: NUMBYTES TYPE I,
      ARC_IDX LIKE TOA_DARA,
      pdfspoolid like tsp01-rqident,
      jobname like tbtcjob-jobname,
      jobcount like tbtcjob-jobcount,
      is_otf,
      txt(80) type c.
data: client like tst01-dclient,
      name like tst01-dname,
      objtype like rststype-type,
      type like rststype-type.
data: GET_SIZE_FROM_FORMAT type c,
      get_size_from_format_default type c.
tables: tsp01.

INITIALIZATION.
get_size_from_format_default = CL_RSTX_PDF_PARAMETER=>get_value( 'USE_FORMAT_WIDTH' ). "#EC NOTEXT
case get_size_from_format_default.
  when 'X'.
    real = ' '.
    report = ' '.
    format = 'X'.
  when ' '.
    real = ' '.
    report = 'X'.
    format = ' '.
  when 'N'.
    real = 'X'.
    report = ' '.
    format = ' '.
endcase.

AT SELECTION-SCREEN OUTPUT.
* Only display 'Real width', if parameter USE_FORMAT_WIDTH is set to 'N',
* because only in this case the real width is written into table TSP02A
loop at screen.
  if screen-name = 'REAL'.
    if get_size_from_format_default = 'N'.
      screen-active = 1.
    else.
      screen-active = 0.
    endif.
    modify screen.
  endif.
endloop.

END-OF-SELECTION.
select single * from tsp01 where rqident = spoolno.
if sy-subrc <> 0.
  perform bd_textbox_err(zrstxpdft) using 80
   'Spoolauftrag existiert nicht'(003).
  exit.
endif.
client = tsp01-rqclient.
name   = tsp01-rqo1name.
CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
       EXPORTING
            AUTHORITY     = 'SP01'
            CLIENT        = client
            NAME          = name
            PART          = 1
       IMPORTING
*           CHARCO        =
*           CREATER       =
*           CREDATE       =
*           DELDATE       =
*           MAX_CREDATE   =
*           MAX_DELDATE   =
*           NON_UNIQ      =
*           NOOF_PARTS    =
*           RECTYP        =
*           SIZE          =
*           STOTYP        =
            TYPE          = type
            OBJTYPE       = objtype
       EXCEPTIONS
            FB_ERROR      = 1
            FB_RSTS_OTHER = 2
            NO_OBJECT     = 3
            NO_PERMISSION = 4.
if objtype(3) = 'OTF'.
  is_otf = 'X'.
else.
  is_otf = space.
endif.
clear sy-msgno.
if is_otf = 'X'.
  CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
      EXPORTING
        SRC_SPOOLID                    = spoolno
        NO_DIALOG                      = ' '
*       DST_DEVICE                     =
*       PDF_DESTINATION                =
      IMPORTING
        PDF_BYTECOUNT                  = numbytes
        PDF_SPOOLID                    = pdfspoolid
*       OTF_PAGECOUNT                  =
        BTC_JOBNAME                    = jobname
        BTC_JOBCOUNT                   = jobcount
      TABLES
        PDF                            = 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.
  case sy-subrc.
  when 0.
*    perform bd_textbox_msg(ZRSTXPDFT) using 80
*     'Funktion CONVERT_OTFSPOOLJOB_2_PDF erfolgreich'(001).
  when 1.
    perform bd_textbox_err(ZRSTXPDFT) using 80
     'Kein OTF- und kein ABAP-Spoolauftrag'(002).
    exit.
  when 2.
    perform bd_textbox_err(ZRSTXPDFT) using 80
     'Spoolauftrag existiert nicht'(003).
    exit.
  when 3.
    perform bd_textbox_err(ZRSTXPDFT) using 80
     'Keine Berechtigung zum Lesen Spoolauftrag'(004).
    exit.
  when others.
    if sy-msgno is not initial.
      message id sy-msgid type 'S' number sy-msgno
          with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into txt.
      perform bd_textbox_err(ZRSTXPDFT) using 80 txt.
    endif.


    perform bd_textbox_err(ZRSTXPDFT) using 80
     'Fehler bei Funktion CONVERT_OTFSPOOLJOB_2_PDF'(005).
    exit.
  endcase.
else.
  if real = 'X'.
    get_size_from_format = 'N'.
  elseif format = 'X'.
    get_size_from_format = 'X'.
  else.
    get_size_from_format = ' '.
  endif.
  CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
      EXPORTING
        SRC_SPOOLID                    = spoolno
        NO_DIALOG                      = ' '
*       DST_DEVICE                     =
*       PDF_DESTINATION                =
        GET_SIZE_FROM_FORMAT           = GET_SIZE_FROM_FORMAT
      IMPORTING
        PDF_BYTECOUNT                  = numbytes
        PDF_SPOOLID                    = pdfspoolid
*       LIST_PAGECOUNT                 =
        BTC_JOBNAME                    = jobname
        BTC_JOBCOUNT                   = jobcount
      TABLES
        PDF                            = 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.
  case sy-subrc.
  when 0.
*    perform bd_textbox_msg(ZRSTXPDFT) using 80
*     'Funktion CONVERT_ABAPSPOOLJOB_2_PDF erfolgreich'(006).
  when 1.
    perform bd_textbox_err(ZRSTXPDFT) using 80
     'Kein OTF- und kein ABAP-Spoolauftrag'(002).
    exit.
  when 2.
    perform bd_textbox_err(ZRSTXPDFT) using 80
     'Spoolauftrag existiert nicht'(003).
    exit.
  when 3.
    perform bd_textbox_err(ZRSTXPDFT) using 80
     'Keine Berechtigung zum Lesen Spoolauftrag'(004).
    exit.
  when others.
    if sy-msgno is not initial.
      message id sy-msgid type 'S' number sy-msgno
          with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into txt.
      perform bd_textbox_err(ZRSTXPDFT) using 80 txt.
    endif.
    perform bd_textbox_err(ZRSTXPDFT) using 80
     'Fehler bei Funktion CONVERT_ABAPSPOOLJOB_2_PDF'(007).
    exit.
  endcase.
endif.
*************** download PDF file ***********
check download = 'X'.
if not ( jobname is initial ).
  perform bd_textbox_var2_msg(ZRSTXPDFT) using 80
   'Konvertierung per Hintergrundjob'(008)
   jobname
   jobcount.
  exit.
endif.
perform download_w_ext(ZRSTXPDFT) tables pdf
                                 using p_file
                                       '.pdf'
                                       'BIN'
                                       numbytes
                                       cancel.
if cancel = space.
*  data: s(80).
*  s = numbytes. condense s.
*  concatenate s 'Bytes heruntergeladen in Datei'(009)
*    into s separated by space.
*  perform bd_textbox_var1_msg(ZRSTXPDFT) using 80
*                                    
*                                    p_file.
endif.




10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers