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 ABAP Report's Output into PDF Format..

Former Member
0 Kudos

Hello Experts,

I want to convert the outout of an ABAP report to an PDF file. I have succedded in doing the following :

Data statistics -


Number of

Records passed ---4

After executing the program RSTXPDFT4, i can get PDF file saying number of records in the above format...

But i want to have the output of the report in PDF. suppose a list is being displayed in the output olf the ABAP report, i want to save that report in PDF format....

Please help........

Anupam...

1 ACCEPTED SOLUTION

venkat_o
Active Contributor

Hi Anupam,

Try this way

<font color=blue><pre>

REPORT ztest_notepad.

"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. </pre></font>

Thanks

Venkat.O

12 REPLIES 12

Former Member
0 Kudos

Hi Anupam,

use this code for genearating spool number and then use std pgm to convert spool number to pdf.

TYPES: BEGIN OF str_mara,

matnr TYPE mara-matnr,

ersda TYPE mara-ersda,

ernam TYPE mara-ernam,

laeda TYPE mara-laeda,

aenam TYPE mara-aenam,

vpsta TYPE mara-vpsta,

END OF str_mara.

DATA: i_mat TYPE TABLE OF str_mara,

wa_mat LIKE LINE OF i_mat.

DATA:params LIKE pri_params.

DATA: days(1) TYPE n VALUE 2,

valid TYPE c.

DATA: obj TYPE REF TO cl_salv_table.

SELECT matnr

ersda

ernam

laeda

aenam

vpsta

UP TO 10 ROWS FROM mara INTO CORRESPONDING FIELDS OF TABLE i_mat.

TRY.

CALL METHOD cl_salv_table=>factory

IMPORTING

r_salv_table = obj

CHANGING

t_table = i_mat.

CATCH cx_salv_msg .

ENDTRY.

CALL FUNCTION 'GET_PRINT_PARAMETERS'

EXPORTING

  • destination = 'QAS'

list_name = 'ZTEST_VERTEX'

list_text = 'TEST'

no_dialog = 'X'

immediately = ' '

expiration = days

IMPORTING

  • OUT_ARCHIVE_PARAMETERS =

out_parameters = params

valid = valid

  • VALID_FOR_SPOOL_CREATION =

EXCEPTIONS

archive_info_not_found = 1

invalid_print_params = 2

invalid_archive_params = 3

OTHERS = 4

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

TRY .

NEW-PAGE PRINT ON PARAMETERS params NO DIALOG.

CATCH cx_sy_nested_print_on .

ENDTRY.

CALL METHOD obj->display.

NEW-PAGE PRINT OFF.

Hope this will solve your problem.

Regards,

Vijay

0 Kudos

I have got the spool request number...but when i use that in program RSTXPDFT4, then it only returning the number of records being displayed......

how to get the original output???

Anupam...

0 Kudos

Hi Anupam again,

I have given sample code for open a spool number and contents of internal table to be written on spool.

Execute the same sample code and check generated spool number.

Regards,

Vijay

0 Kudos

This message was moderated.

Former Member
0 Kudos

Hi,

Check this link..

venkat_o
Active Contributor

Hi Anupam,

Try this way

<font color=blue><pre>

REPORT ztest_notepad.

"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. </pre></font>

Thanks

Venkat.O

Former Member
0 Kudos

AFter executing the program, it's showing "Spool request 0 does not exist"...

What to do???

Anupam

Former Member
0 Kudos

Thank You all...

But one problem is when i open my PDF file, it's zoom percent is 71%... to view the all the columns properly, i have zoom it upto 1200% as my table contents 23 columns & some of them may contain 255 chacracters....

is there any way so that i can see the PDF file properly with less zoom percentage line 100-150% or so????

Please Help..

Anupam...

Former Member
0 Kudos

Hi,

I hope you are creating a spool before using the RSTXPDFT4 program for converting the spool output to PDF. The overview of which you are seeing is the part of list creation and this needs to be supressed while creating the spool.

Execute the program. It will show you the report output on screen.

For generating spool, click on print button. it will ask you for output device, give your local printer (locl/ LP01).

After giving output device click on "properties" button. under this check for cover sheets parameter and make the value as NO.

This will eliminate the overview of screen while creating the spool.

if overview is not there in spool, then no question of having the same in PDF.

Regards

Former Member
0 Kudos

Hi,

You can do it by creating a spool and then convert this spool data into pdf format.

You are showing your report output via write statement and all the 'WRITE' statements inside the statement

New-page print on and New-page print off create a spool.

NEW-PAGE PRINT ON

KEEP IN SPOOL l_keep (variable type c default u2018Xu2019)

LINE-SIZE 137

LIST NAME l_list (variable(30) TYPE c default 'file_pdf')

NO DIALOG.

LOOP AT g_t_text.

write: report output

WRITE: g_t_text-data.

ENDLOOP.

NEW-PAGE PRINT OFF.

COMMIT WORK.

now select fetch thie spool number from table TSP01 WHERE rqowner = sy-uname AND rq2name = 'file_PDF'.

SORT g_t_com BY rqcretime DESCENDING.

READ TABLE g_t_com INDEX 1. ( This will give you the latest spool.)

Now convert this data into pdf format and download this

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = g_t_data-rqident (spool number)

IMPORTING

pdf_bytecount = l_size (variable type i)

TABLES

pdf = g_pd f(table LIKE TABLE OF tline)

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = l_size "size

filename = file name

filetype = 'BIN'

TABLES

data_tab = g_pdf.

hope this will help you.

I355602
Advisor
Advisor
0 Kudos

Hi,

Refer this wiki code:-

https://wiki.sdn.sap.com/wiki/display/Snippets/SaveReportOutputtoaPDFFile

Hope this helps you.

Regards,

Tarun

Former Member
0 Kudos

Hi ,

Read the given below link ....it will help you

https://wiki.sdn.sap.com/wiki/display/ABAP/PDF%20Downlaod%20By%20Creating%20Spool%20Request

Thanks and Regards.

Priyank dixit