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: 

Converting internal to PDF Format

Former Member
0 Kudos

Hi All,

I had a requirement that i need to convert the internal table to PDF format and to download it.I am not displaying the internal table values in report, but i need to download directly the internal table data to PDF format.Please help me is there any method or function module available?..

Thanks a lot in advance.

Regards,

Vijay Dhanasekar

1 ACCEPTED SOLUTION

former_member181962
Active Contributor
0 Kudos

Alternatively, YOu can export the internal table to memory id.

Submit a zreport in background mode.

IN the zreport import the itab and display the itab.

It creates a spool.

Get the spool number and use the FM:

CONVERT_ABAPSPOOLJOB_2_PDF

Regards,

Ravi

11 REPLIES 11

former_member181962
Active Contributor
0 Kudos

Use the FM:

CONVERT_OTF_2_PDF

REgards,

Ravi

Former Member
0 Kudos

hi,

Plz try like this.

Lets suppose internal table itab has 3 fields.

Create a SAP Script with only MAIN window.

In it, just code

P1 itab-f1,,itab-f2,,itab-f3

Now, in your report program,

perform open_form.

loop at itab.

perform write_form.

endloop.

perform close_form.

In FM Close_form, you have a parameter to get the otf table. you send this otf table to fm CONVERT_OTF_PDF.

Now, you can get the pdf file.

Regards,

Sailaja.

former_member181962
Active Contributor
0 Kudos

Alternatively, YOu can export the internal table to memory id.

Submit a zreport in background mode.

IN the zreport import the itab and display the itab.

It creates a spool.

Get the spool number and use the FM:

CONVERT_ABAPSPOOLJOB_2_PDF

Regards,

Ravi

Former Member
0 Kudos

Hi Ravi,

The function module you had specified will convert OTF format to PDF. I having only the internal table, i need to convert to PDF format. If i need to use the OFT to PDF function module, First i need to convert the internal table to OTF how??

Thanks & Regards,

Vijay Dhanasekar

Former Member
0 Kudos

hi,

You can not convert to otf directly.

When you use function module close_form, then you will be having a parameters which gets populated with otf data.

this is the only way how you can get otf table populated.

Regards,

Sailaja.

Former Member
0 Kudos

first u write Internal table to spool then u can convert the spool to pdf....see the below code.. hope it helps...

DATA: BEGIN OF i_mara OCCURS 0,

matnr LIKE mara-matnr.

DATA: END OF i_mara.

DATA: v_dest LIKE tsp01-rqdest,

v_handle LIKE sy-tabix,

v_spool_id LIKE tsp01-rqident,

v_rc TYPE c,

v_errmessage(100) TYPE c,

v_text(70) TYPE c.

START-OF-SELECTION.

SELECT matnr FROM mara INTO TABLE i_mara.

CALL FUNCTION 'RSPO_OPEN_SPOOLREQUEST'

EXPORTING

dest = 'LOCL'

  • LAYOUT =

  • NAME =

  • SUFFIX1 =

  • SUFFIX2 =

  • COPIES =

  • PRIO =

  • IMMEDIATE_PRINT =

  • AUTO_DELETE =

  • TITLELINE =

  • RECEIVER =

  • DIVISION =

  • AUTHORITY =

  • POSNAME =

  • ACTTIME =

  • LIFETIME = '8'

  • APPEND =

  • COVERPAGE =

  • CODEPAGE =

  • DOCTYPE =

IMPORTING

handle = v_handle

spoolid = gd_spool_nr

rc = v_rc

errmessage = v_errmessage.

LOOP AT i_mara.

v_text = i_mara-matnr.

CALL FUNCTION 'RSPO_WRITE_SPOOLREQUEST'

EXPORTING

handle = v_handle

text = v_text

  • LENGTH =

  • CODEPAGE =

  • TRUNCATE =

IMPORTING

rc = v_rc

errmessage = v_errmessage

EXCEPTIONS

handle_not_valid = 1

OTHERS = 2.

IF sy-subrc <> 0.

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

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

ENDIF.

ENDLOOP.

CALL FUNCTION 'RSPO_CLOSE_SPOOLREQUEST'

EXPORTING

handle = v_handle

IMPORTING

rc = v_rc

errmessage = v_errmessage

EXCEPTIONS

handle_not_valid = 1

OTHERS = 2.

IF sy-subrc <> 0.

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

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

ENDIF.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = gd_spool_nr

no_dialog = c_no

dst_device = c_device

IMPORTING

pdf_bytecount = gd_bytecount

TABLES

pdf = it_pdf_output

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.

CHECK sy-subrc = 0.

*

Former Member
0 Kudos

Hi,

I feel Madhu answer will help me.I had rewarded you madhu.

Thank you all for your response.

Thanks & Regards,

Vijay Dhanasekar

Former Member
0 Kudos

Hai Vijay

Try with the following code for your requirement

REPORT Z_ABAPOUTPUT_PDF_SREE_13424 .

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.

you will just replace the structure of itab_pdf to MARA table structure

Thanks & regards

Sreenivasulu P

0 Kudos

TRY THIS GUYS...

  • with OTF data returned from SMARTFORM

  • convert the Smartform OTF to PDF

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

IMPORTING

bin_filesize = lv_bin_size

bin_file = lv_bin_file

TABLES

otf = ls_output_info-otfdata.

zcl_util=>conv_bin_2_text(

EXPORTING

bin_file = lv_bin_file

bin_size = lv_bin_size

IMPORTING

et_att_text = lt_att_text ).

method conv_bin_2_text.

data: ls_text type solisti1.

data: l_rest type i.

data: l_offset type i.

data: l_string type string.

data: converter type ref to cl_abap_conv_in_ce.

converter = cl_abap_conv_in_ce=>create( input = bin_file ).

converter->read( importing data = l_string ).

l_offset = 0.

l_rest = bin_size.

while l_rest > 255.

ls_text-line = l_string+l_offset(255).

append ls_text to et_att_text.

l_offset = l_offset + 255.

l_rest = l_rest - 255.

endwhile.

if l_rest > 0.

ls_text = l_string+l_offset(l_rest).

append ls_text to et_att_text.

endif.

endmethod.

Former Member
0 Kudos

Convert SAP documents (SAPScript) to other types.

CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT                = 'PDF'
IMPORTING    
BIN_FILESIZE          = FILE_LEN
TABLES_OTF            = OTFDATA
LINES                 = PDFDATA
EXCEPTIONS   
ERR_MAX_LINEWIDTH     = 1                   
ERR_FORMAT            = 2
ERR_CONV_NOT_POSSIBLE = 3
OTHERS                = 4.

Then you can use funtion module to download.

gui_download
ws_download
download

Regards,

Lalit Mohan Gupta.

Former Member
0 Kudos

Hi,

Try this code

  • Subroutine to get the print parameters
  • WAIT UP TO 1 SECONDS.
  • To fetch the spool number from TSP01 table
CALL FUNCTION 'GET_PRINT_PARAMETERS' EXPORTING destination = 'LP01' list_name = 'TEST' list_text = 'SUBMIT ... TO SAP-SPOOL' immediately = ' ' line_size = '1023' no_dialog = 'X' IMPORTING out_parameters = wa_pri_params valid = w_valid. IF w_valid EQ 'X'. CONCATENATE 'E' w_tabix sy-datum+4(4) sy-uzeit INTO wa_pri_params-plist. ENDIF. NEW-PAGE PRINT ON NO DIALOG PARAMETERS wa_pri_params. WRITE : / text-s32. ULINE. LOOP AT t_error INTO wa_error. WRITE : / wa_error-text. ENDLOOP. WRITE : / text-s33. NEW-PAGE PRINT OFF. SELECT rqident FROM tsp01 INTO w_rqident UP TO 1 ROWS WHERE rq2name = wa_pri_params-plist. ENDSELECT. CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF' EXPORTING src_spoolid = w_rqident no_dialog = 'X' dst_device = 'LP01' pdf_destination = 'X' TABLES pdf = t_pdf.

Regards

Krishna