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: 

Error while downloading data in pdf

Former Member
0 Kudos
376

I have a requirement to download data from a table into pdf format and save in my local folder........

But Whenever I am executing this code it is showing error that spool number 0 doed not exist.

Can some body help me in this regards....Should I nedd to set anithing in spool or it will be done just programmaticaly...

   *&---------------------------------------------------------------------*
*& Report  YDEMO_PDF_2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  YDEMO_PDF_2.
"Variables
DATA:
l_lay         TYPE pri_params-paart,
l_lines       TYPE pri_params-linct,
l_cols        TYPE pri_params-linsz,
l_val         TYPE c,
l_no_of_bytes TYPE i,
l_pdf_spoolid LIKE tsp01-rqident,
l_jobname     LIKE tbtcjob-jobname,
l_jobcount    LIKE tbtcjob-jobcount,
spoolno       TYPE tsp01-rqident.
*Types
TYPES:
t_pripar      TYPE pri_params,
t_arcpar      TYPE arc_params.
"Work areas
DATA:
lw_pripar     TYPE t_pripar,
lw_arcpar     TYPE t_arcpar.
DATA:
it_t100       TYPE t100  OCCURS 0 WITH HEADER LINE,
it_pdf        TYPE tline OCCURS 0 WITH HEADER LINE.

"Start-of-selection.

START-OF-SELECTION.
l_lay   = 'X_65_132'.
l_lines = 65.
l_cols  = 132.
"Read, determine, change spool print parameters and archive parameters
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
in_archive_parameters  = lw_arcpar
in_parameters          = lw_pripar
layout                 = l_lay
line_count             = l_lines
line_size              = l_cols
no_dialog              = 'X'
IMPORTING
out_archive_parameters = lw_arcpar
out_parameters         = lw_pripar
valid                  = l_val
EXCEPTIONS
archive_info_not_found = 1
invalid_print_params   = 2
invalid_archive_params = 3
OTHERS                 = 4.
IF l_val <> space AND sy-subrc = 0.
lw_pripar-prrel = space.
lw_pripar-primm = space.
NEW-PAGE PRINT ON
NEW-SECTION
PARAMETERS lw_pripar
ARCHIVE PARAMETERS lw_arcpar
NO DIALOG.
ENDIF.
"Get data
SELECT *
FROM t100
INTO TABLE it_t100
UP TO 100 ROWS
WHERE sprsl = sy-langu.
" Writing to Spool
LOOP AT it_t100.
WRITE😕 it_t100.
ENDLOOP.

NEW-PAGE PRINT OFF.
CALL FUNCTION 'ABAP4_COMMIT_WORK'.

spoolno = sy-spono.
"Convert spool to PDF
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid   = spoolno
no_dialog     = ' '
IMPORTING
pdf_bytecount = l_no_of_bytes
pdf_spoolid   = l_pdf_spoolid
btc_jobname   = l_jobname
btc_jobcount  = l_jobcount
TABLES
pdf           = it_pdf.
"Download PDF file C Drive
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'C:\itab_to_pdf.pdf'
filetype = 'BIN'
TABLES
data_tab = it_pdf.

1 REPLY 1

gouravkumar64
Active Contributor
0 Kudos
241

Hi,

First convert the data of table into OTF Format

then use CONVERT_OTF  to convert to PDF Format

use GUI_DOWNLOAD as u r  using now

otherwise please follow this thread

http://scn.sap.com/message/7384789

Thanks

Gourav.