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: 

Report to spool

Former Member
0 Kudos

Hi frendz,

Can anyone pls tell me how to send reort output to spool.if possible can you guys provide sample code.Pls help me out.

8 REPLIES 8

FredericGirod
Active Contributor
0 Kudos

Hi,

get the print parameters with the function GET_PRINT_PARAMETERS or set it with SET_PRINT_PARAMETERS.

After you just have to use the : NEW-PAGE PRINT ON command.

All that you will write with the command WRITE will go into the spool.

Rgd

Frédéric

0 Kudos

See this sample code it might help u.

http://sap.ionelburlacu.ro/abap/sap2/Save_Report_Output_to_a_PDF_File.html

Save Report Output to a PDF File

This report takes another report as input, and captures the output of that report. The output is then converted to PDF and saved to a local file. This shows how to use some of the PDF function modules, as well as an easy way to create PDF files.

One thing I am not thrilled about is how the spool number is retrieved. If anyone has any better method, please let me know! Until I actually have a production use for a program like this, I will not try to find a better way.

Source Code Listing

report zabap_2_pdf.

*-- Enhancements: only allow to be run with variant. Then called

*-- program will be transparent to users

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

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

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

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

submit (p_repid) to sap-spool without spool dynpro

spool parameters mstr_print_parms

via selection-screen

and return.*-- Find out what the spool number is that was just created

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.

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(8)

f_uname+0(3)

into lc_rq2name separated by '_'.

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

Hope this helps u.

Also refer

0 Kudos

Thanks a lot for your quick reply....Can you pls provide me the sample code if possible...or can you pls specify what need to be passed to the function module..

Former Member
0 Kudos

If you execute the report in the background, the output will be sent to spool.

Regards,

Ravi

0 Kudos

Even i have to execute the report in backgroud....But do i need to do anything in SE38 program ?? if yes can you pls provide me the sample code...Pls its very urgent.

0 Kudos

You don't have to do any coding if you are executing the program in the background. By default the output of the report will be sent to spool.

Regards,

Ravi

Note : Please mark all the helpful answers

Former Member
0 Kudos

Hai

go theough the following Code

REPORT Z_ABAPOUTPUT_PDF .

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.

Thanks & regards

Sreeni

sridharreddy_kondam
Active Contributor
0 Kudos

Hi Rak,

Check this Link and it would definitely solve u r problem with an example

<b>http://help.sap.com/saphelp_nw04/helpdata/en/9f/dba5fc35c111d1829f0000e829fbfe/content.htm</b>

And alternatively if u execute the report in the background (se38> program>execute-->background)

and for this u have to create a variant and supply the values for selection screen..

Regards,

Sridhar