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: 

how to convert an internal table to a PDF

Former Member
0 Kudos

Hello Experts,

Is there a way that an internal table can be converted into a PDF file?

The itab is:

data: i_data(100) type c occurs 0 with header line.

Thanks.

12 REPLIES 12

Former Member
0 Kudos

hi,

I think u can use the fm 'CONVERT_ABAPSPOOLJOB_2_PDF' to do this...

but u can check the sample codes in SDN.... u will find lot of stuff on the same issue.

0 Kudos

Naveen,

Thanks for the reply. But that FM will convert Spool to PDF.

But I need to convert ITAB to PDF/any other file format.

0 Kudos

Sam,

what kind of data you have in your internal table?

is it any form or any other data?

0 Kudos

Naveen

Thanks for the reply. Basically my itab has the list details as following:

-


Report: ZREP1

User: XXXXXX Notify Price Change

System: DEV

-


|Material | Material Description | Price

-


|181701 | XXXXXXXX 2.5MG TABS | 250.00

-


Edited by: SAM K on Mar 21, 2008 12:25 PM

0 Kudos

i have look for the same solution for quite some times and i found that most of the solution will follow the steps:

internal table>spool/smartform>PDF file-->email.

if you can find some solution without convert to spool/smartform, kindly keep me in post.

Former Member
0 Kudos

Refer the following link for similar program:

http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

Former Member
0 Kudos

Hai,

first convert ur internal table data to OTF.by usinf thid Function Module

data: t_otf LIKE itcoo OCCURS 100 WITH HEADER LINE,

  • t_pdf LIKE tline OCCURS 100 WITH HEADER LINE*.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

  • MAX_LINEWIDTH = 132

  • ARCHIVE_INDEX = ' '

  • COPYNUMBER = 0

  • ASCII_BIDI_VIS2LOG = ' '

  • PDF_DELETE_OTFTAB = ' '

IMPORTING

BIN_FILESIZE = w_size

  • BIN_FILE =

TABLES

otf = t_otf

lines = t_pdf

EXCEPTIONS

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

ERR_BAD_OTF = 4

OTHERS = 5

.

IF sy-subrc <> 0.

  • RAISE error. " oops

ENDIF.

and then use gui_download function module.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

BIN_FILESIZE = w_size

filename = 'C:\Documents and Settings\adc\Desktop\pdf123.pdf'

FILETYPE = 'BIN'

  • APPEND = ' '

  • WRITE_FIELD_SEPARATOR = 'X'

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = 'X'

  • COL_SELECT_MASK = 'XX X XX'

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • IMPORTING

  • FILELENGTH =

tables

data_tab = t_pdf

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

reward if helpful

raam

Former Member
0 Kudos

Use CONVERT_OTF function module to convert an Internal table to PDF format.

Iyswarya

Former Member
0 Kudos

Hi

refer this thread there are many mentioned to convert

Regards

Shiva

AmritRaj
Explorer
0 Kudos

Hi,

please refer to this code for converting your internal table to pdf ,

please don't forget to read the below comments.

Note :- You can use any internal table for this code.

DATA:g_val TYPE c,
w_pripar TYPE pri_params,
w_arcpar TYPE arc_params,
i_pdf type table of tline,
spoolid type tsp01-rqident,
l_no_of_bytes TYPE i,
l_pdf_spoolid type tsp01-rqident,
l_jobname type tbtcjob-jobname,
l_jobcount type tbtcjob-jobcount.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
in_archive_parameters = w_arcpar
in_parameters = w_pripar
layout = 'X_65_132'
line_count = 65
line_size = 132
no_dialog = 'X'
IMPORTING
out_archive_parameters = w_arcpar
out_parameters = w_pripar
valid = g_val.
IF g_val NE space AND sy-subrc = 0.
w_pripar-prrel = space.
w_pripar-primm = space.
NEW-PAGE PRINT ON NEW-SECTION PARAMETERS w_pripar ARCHIVE PARAMETERS w_arcpar NO DIALOG.
ENDIF.
TRY.
cl_salv_table=>factory(
EXPORTING
list_display = if_salv_c_bool_sap=>false
IMPORTING
r_salv_table = DATA(it_final_display)
CHANGING
t_table = T_TABLE "Your internal table where data is available
).
CATCH cx_salv_msg.
ENDTRY.

it_final_display->display( ).
NEW-PAGE PRINT OFF.
CALL FUNCTION 'ABAP4_COMMIT_WORK'.
spoolid = sy-spono.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = spoolid
no_dialog = ' '
IMPORTING
pdf_bytecount = l_no_of_bytes
pdf_spoolid = l_pdf_spoolid
btc_jobname = l_jobname
btc_jobcount = l_jobcount
TABLES
pdf = i_pdf.

CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = fILENAME "Give the pdf location of your system where you want to store
filetype = 'BIN'
TABLES

data_tab = i_pdf.

0 Kudos

Not sure your answer will be spotted, there are dozens of same questions and answers, but no blog post as far as I can see. I recommend publishing a first blog post about this topic, it will be much more visible.

EDIT:

The calls to GET_PRINT_PARAMETERS, CONVERT_ABAPSPOOLJOB_2_PDF and GUI_DOWNLOAD are missing EXCEPTIONS.

CALL FUNCTION without EXCEPTIONS will not set SY-SUBRC, so it should not be tested.

The PDF parameter of CONVERT_ABAPSPOOLJOB_2_PDF is obsolete in Unicode systems because it returns characters, you should use BIN_FILE instead.

The function module GUI_DOWNLOAD is obsolete, you should use CL_GUI_FRONTEND_SERVICES instead (method of same name).

When GUI_DOWNLOAD is used with binary files, you must pass the number of bytes, otherwise extra null bytes are appended to the file, which can make the file corrupted by some PDF readers (well-known issue explained a lot in the forum). Also it's best using DATA_TAB with an internal table made of bytes instead of mojibake characters (it's okay only in the old Non-Unicode systems, and considered "bad" programming in Unicode systems).

Sandra_Rossi
Active Contributor
0 Kudos

It's a 2008 question (15 years ago...)

Not sure your answer will be spotted, there are dozens of same questions and answers, but no blog post as far as I can see. I recommend publishing a first blog post about this topic, it will be much more visible.