SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Convert spool to PDF format and download as PC file or Unix



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Conversion
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sat Sep 15, 2007 9:18 pm    Post subject: Convert spool to PDF format and download as PC file or Unix Reply with quote

Convert spool to PDF format and download as PC file or Unix dataset

Code:
report z.

data: w_ident     like tsp01-rqident,
      w_doctype   like tsp01-rqdoctype,
      w_bytecount type i.

data: itab_pdf    like tline occurs 0 with header line.

parameter spoolnum like tsp01-rqident obligatory.

selection-screen begin of block a2 with frame.
parameters:  to_pc   radiobutton group a2 default 'X',
             pcfile like rlgrap-filename lower case,
             to_unix radiobutton group a2,
             unixfile(255) lower case.
selection-screen end of block a2.

********************************
at selection-screen on block a2.
********************************
  if to_pc = 'X' and pcfile is initial.
    message e398(00) with 'Enter PC File Name.'.
  elseif to_unix = 'X' and unixfile is initial.
    message e398(00) with 'Enter Unix File Name.'.
  endif.

*******************************
at selection-screen on spoolnum.
*******************************
  select single rqident rqdoctype
         into (w_ident, w_doctype)
         from tsp01
         where rqident = spoolnum.
  if sy-subrc ne 0.
    message e398(00) with 'Spool' spoolnum 'not found'.
  endif.

************************************************
at selection-screen on value-request for pcfile.
************************************************
  call function 'WS_FILENAME_GET'
       exporting
            mask     = ',*.*,*.*.'
       importing
            filename = pcfile
       exceptions
            others   = 1.
  if sy-subrc <> 0.
    message id sy-msgid type 'I' number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.


*******************
start-of-selection.
*******************
  if w_doctype = 'LIST'.
    perform get_abap_spool_in_pdf.
  elseif w_doctype = 'OTF'.
    perform get_otf_spool_in_pdf.
  endif.

  if to_pc = 'X'.
    perform write_pdf_spool_to_pc.
  else.
    perform write_pdf_spool_to_unix.
  endif.

  message i398(00) with 'Completed OK'.

************************************************************************
form get_abap_spool_in_pdf.
  refresh itab_pdf.
  call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
       exporting
            src_spoolid              = w_ident
       importing
            pdf_bytecount            = w_bytecount
       tables
            pdf                      = itab_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 ne 0.
    message e398(00) with 'Cannot convert to PDF. Error =' sy-subrc.
  endif.
endform.

************************************************************************
form get_otf_spool_in_pdf.
  refresh itab_pdf.
  call function 'CONVERT_OTFSPOOLJOB_2_PDF'
       exporting
            src_spoolid              = w_ident
       importing
            pdf_bytecount            = w_bytecount
       tables
            pdf                      = itab_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.
    message e398(00) with 'Cannot convert to PDF. Error =' sy-subrc.
  endif.
endform.

************************************************************************
form write_pdf_spool_to_unix.
  open dataset unixfile for output in binary mode.
  if sy-subrc ne 0 .
    message e398(00) with 'Cannot open unix file for output:' unixfile.
  endif.

  loop at itab_pdf.
    transfer itab_pdf to unixfile.
    if sy-subrc ne 0 .
      message e398(00) with 'Cannot write to unix file:' unixfile.
    endif.
  endloop.

  close dataset unixfile.
endform.

************************************************************************
form write_pdf_spool_to_pc.
  call function 'WS_DOWNLOAD'
       exporting
            bin_filesize            = w_bytecount
            filename                = pcfile
            filetype                = 'BIN'
       tables
            data_tab                = itab_pdf
       exceptions
            file_open_error         = 1
            file_write_error        = 2
            invalid_filesize        = 3
            invalid_type            = 4
            no_batch                = 5
            unknown_error           = 6
            invalid_table_width     = 7
            gui_refuse_filetransfer = 8
            customer_error          = 9
            others                  = 10.
  if sy-subrc <> 0.
    message e398(00) with 'Cannot download to PC. Error =' sy-subrc.
  endif.
endform.

****


Source: http://www.geocities.com/victorav15/sapr3/utilities/spool_to_pdf.txt
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Conversion All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.