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: 

Convert spool to PDF and save it to the local drive

Former Member
0 Kudos

Hi all,

We have a requirement to convert spool to PDF and save it to the local drive(Presentation server).Is it possible ? if so please provide the sample code.

Thanks and Regards

Kiran

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi ,

copy and paste this program in your report.

Enter the Report name to execute whose output need to be in PDF.

It will work

---TABLES----

tables:

tsp01.

---STRUCTURES---

data:

mstr_print_parms like pri_params,

mc_valid(1) type c,

mi_bytecount type i,

mi_length type i,

mi_rqident like tsp01-rqident.

---INTERNAL TABLES---

data:

mtab_pdf like tline occurs 0 with header line,

mc_filename like rlgrap-filename.

---SELECTION SCREEN---

parameters:

p_repid like sy-repid, " Report to execute

p_linsz like sy-linsz default 132, " Line size

p_paart like sy-paart default 'X_65_132'. " Paper Format

start-of-selection.

concatenate 'c:\'

p_repid

'.pdf'

into mc_filename.

*-- 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.

*-- Make sure that a printer destination has been set up.

*-- If this is not done the PDF function module ABENDS

if mstr_print_parms-pdest = space.

mstr_print_parms-pdest = 'LOCL'.

endif.

*-- 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

  • in_archive_parameters = space

  • in_parameters = space

  • layout = space

  • mode = 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.

submit (p_repid) to sap-spool without spool dynpro

spool parameters mstr_print_parms

via selection-screen

and return.

*-- Find out the spool number

perform get_spool_number using sy-repid

sy-uname

changing mi_rqident.

*-- Convert Spool to 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 = 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.

*-- Download the file

call function 'DOWNLOAD'

exporting

bin_filesize = mi_bytecount

filename = mc_filename

filetype = 'BIN'

importing

act_filename = mc_filename

tables

data_tab = mtab_pdf.

----


  • FORM get_spool_number *

----


  • Get the most recent spool created by user/report *

----


  • --> F_REPID *

  • --> F_UNAME *

  • --> F_RQIDENT *

----


form get_spool_number using f_repid

f_uname

changing f_rqident.

data:

lc_rq2name like tsp01-rq2name.

concatenate f_repid+0(9)

f_uname+0(3)

into lc_rq2name.

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

Edited by: Anusha on May 13, 2009 5:51 PM

8 REPLIES 8

GauthamV
Active Contributor
0 Kudos

Plz SEARCH in SCN before posting.

Use this program.

RSTXPDFT4

Former Member
0 Kudos

Hi ,

copy and paste this program in your report.

Enter the Report name to execute whose output need to be in PDF.

It will work

---TABLES----

tables:

tsp01.

---STRUCTURES---

data:

mstr_print_parms like pri_params,

mc_valid(1) type c,

mi_bytecount type i,

mi_length type i,

mi_rqident like tsp01-rqident.

---INTERNAL TABLES---

data:

mtab_pdf like tline occurs 0 with header line,

mc_filename like rlgrap-filename.

---SELECTION SCREEN---

parameters:

p_repid like sy-repid, " Report to execute

p_linsz like sy-linsz default 132, " Line size

p_paart like sy-paart default 'X_65_132'. " Paper Format

start-of-selection.

concatenate 'c:\'

p_repid

'.pdf'

into mc_filename.

*-- 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.

*-- Make sure that a printer destination has been set up.

*-- If this is not done the PDF function module ABENDS

if mstr_print_parms-pdest = space.

mstr_print_parms-pdest = 'LOCL'.

endif.

*-- 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

  • in_archive_parameters = space

  • in_parameters = space

  • layout = space

  • mode = 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.

submit (p_repid) to sap-spool without spool dynpro

spool parameters mstr_print_parms

via selection-screen

and return.

*-- Find out the spool number

perform get_spool_number using sy-repid

sy-uname

changing mi_rqident.

*-- Convert Spool to 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 = 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.

*-- Download the file

call function 'DOWNLOAD'

exporting

bin_filesize = mi_bytecount

filename = mc_filename

filetype = 'BIN'

importing

act_filename = mc_filename

tables

data_tab = mtab_pdf.

----


  • FORM get_spool_number *

----


  • Get the most recent spool created by user/report *

----


  • --> F_REPID *

  • --> F_UNAME *

  • --> F_RQIDENT *

----


form get_spool_number using f_repid

f_uname

changing f_rqident.

data:

lc_rq2name like tsp01-rq2name.

concatenate f_repid+0(9)

f_uname+0(3)

into lc_rq2name.

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

Edited by: Anusha on May 13, 2009 5:51 PM

Former Member
0 Kudos

Hi,

Submit program RSTXPDFT4 with the spool number to convert the spool to pdf format.

To get the spool number, you can query table TSP01.

Regards,

Hema.

Former Member
0 Kudos

This is Anusha Again.Let me paste the code in correct way.

*-----TABLES------*
tables:
  tsp01.
*-----STRUCTURES-----*
data:
  mstr_print_parms like pri_params,
  mc_valid(1)      type c,
  mi_bytecount     type i,
  mi_length        type i,
  mi_rqident       like tsp01-rqident.

*-----INTERNAL TABLES-----*
data:
  mtab_pdf    like tline occurs 0 with header line,
  mc_filename like rlgrap-filename.

*-----SELECTION SCREEN-----*
parameters:
  p_repid like sy-repid, " Report to execute
  p_linsz like sy-linsz default 132, " Line size
  p_paart like sy-paart default 'X_65_132'.  " Paper Format

start-of-selection.
  concatenate 'c:\'
              p_repid
              '.pdf'
    into mc_filename.

*-- 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.

*-- Make sure that a printer destination has been set up.
*-- If this is not done the PDF function module ABENDS
  if mstr_print_parms-pdest = space.
    mstr_print_parms-pdest = 'LOCL'.
  endif.

*-- 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
*      in_archive_parameters  = space
*      in_parameters          = space
*      layout                 = space
*      mode                   = 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.

  submit (p_repid) to sap-spool without spool dynpro
                   spool parameters mstr_print_parms
                   via selection-screen
                   and return.

*-- Find out the spool number
  perform get_spool_number using sy-repid
             sy-uname

    changing mi_rqident.

.

0 Kudos

Continued..

*-- Convert Spool to 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                      = 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.
*-- Download the file
  call function 'DOWNLOAD'
    exporting
      bin_filesize = mi_bytecount
      filename     = mc_filename
      filetype     = 'BIN'
    importing
      act_filename = mc_filename
    tables
      data_tab     = mtab_pdf.
*---------------------------------------------------------------------*
*       FORM get_spool_number *
*---------------------------------------------------------------------*
*       Get the most recent spool created by user/report              *
*---------------------------------------------------------------------*
*  -->  F_REPID               *
*  -->  F_UNAME               *
*  -->  F_RQIDENT             *
*---------------------------------------------------------------------*
form get_spool_number using f_repid
     f_uname
                changing f_rqident.
  data:
    lc_rq2name like tsp01-rq2name.
  concatenate f_repid+0(9)
              f_uname+0(3)
    into lc_rq2name.
  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

.

0 Kudos

Hi all,

Thanks for your replies.I want to do this in background mode so will the above reports and code suggested work??

Thanks and Regards

Kiran

0 Kudos

Hi Kiran,

Yes! It is posible to run in background mode.But you have to submit the main programs selection screen parameters using vaients "USING SELECTION-SET variant " command in the current programs submit statement.

submit (p_repid) to sap-spool without spool dynpro

spool parameters mstr_print_parms

via selection-screen <Varient-name>

and return.

You can take the varient name as an input field in the current program or you hardcode the varient name in the program as specified above..

After executing the current program enter the selection screen values and goto menu PROGRAM->EXECUTE IN BACKGROUND.

Edited by: Anusha on May 14, 2009 10:36 AM

0 Kudos

is there a limit for the spool number of page? my spool is more than 10000 pages!