Application Development and Automation 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: 
Read only

pdf

Former Member
0 Likes
758

Hi

how to use this FM. CONVERT_ABAPSPOOLJOB_2_PDF

is this FM download the data to PC.

5 REPLIES 5
Read only

Former Member
0 Likes
721

Hi

This is the fun module used to convert the output of any document to PDF format using the spool ID of that output of the document.

After that you can use GUI_DOWNLOAD to download that PDF file to desktop.

<b>Reward points for useful Answers</b>

Regards

Anji

Read only

0 Likes
721

please give me code.

Read only

0 Likes
721

hi,

here is a code example


CALL FUNCTION 'GUI_DOWNLOAD'
   EXPORTING
      bin_filesize                     = lv_bytecount " imported from the prev function
      filename                         = lv_file
      filetype                           = 'BIN'
   TABLES
      data_tab                        = itab_pdf

Best regards

Marcus

Read only

Former Member
0 Likes
721

Hi,

Check the below code.........

REPORT yacpr0013 .

PARAMETERS: p_rec TYPE somlreci1 DEFAULT 'test@hotmail.com' LOWER CASE OBLIGATORY,

p_spool LIKE tsp01-rqident OBLIGATORY.

CONSTANTS: c_true TYPE boolean_flg VALUE 'X'.

TYPES: ty_tab_pdf TYPE tline OCCURS 0.

  • Type for binary attachment table.

TYPES: ty_tab_objbin TYPE solisti1 OCCURS 0.

DATA: i_objbin TYPE ty_tab_objbin.

START-OF-SELECTION.

PERFORM f_convert_to_pdf CHANGING i_objbin.

PERFORM f_send_email USING p_rec i_objbin.

&----


*& @FORMS

&----


&----


*& Form send_email

&----


  • Subroutine to be able to send a simple email. Check transaction

  • SOST for output. If it makes it to SOST, it's then just a matter

  • of ensuring BASIS has done the appropriate config.

----


FORM f_send_email USING pv_rec TYPE somlreci1

pi_objbin TYPE ty_tab_objbin.

DATA: li_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE.

DATA: li_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: li_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.

DATA: ls_doc_chng LIKE sodocchgi1.

DATA: li_objhead LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: lv_tab_lines LIKE sy-tabix.

  • Creation of the document to be sent

  • File Name

ls_doc_chng-obj_name = 'SENDFILE'.

  • Mail Subject

ls_doc_chng-obj_descr = 'Email header'(em1).

  • Completing the recipient list

li_reclist-receiver = pv_rec.

li_reclist-rec_type = 'U'.

APPEND li_reclist.

  • Mail Contents

li_objtxt = 'line 1 of the email body'(bd1).

APPEND li_objtxt.

CLEAR li_objtxt. " put in a blank line

APPEND li_objtxt.

li_objtxt = 'line 2 of the email body'(bd2).

APPEND li_objtxt.

li_objtxt = 'line 3 of the email body'(bd3).

APPEND li_objtxt.

  • Calculate email size in bytes

DESCRIBE TABLE li_objtxt LINES lv_tab_lines.

READ TABLE li_objtxt INDEX lv_tab_lines.

ls_doc_chng-doc_size = ( lv_tab_lines - 1 ) * 255 + STRLEN( li_objtxt ).

  • Creation of the entry for the compressed document

  • for the email text

CLEAR li_objpack-transf_bin.

li_objpack-head_start = 1.

li_objpack-head_num = 0.

li_objpack-body_start = 1.

li_objpack-body_num = lv_tab_lines.

li_objpack-doc_type = 'RAW'.

APPEND li_objpack.

  • Creation of the document attachment

  • (Assume that the data in OBJBIN is in BMP format)

DESCRIBE TABLE pi_objbin LINES lv_tab_lines.

li_objhead = 'Save as name.PDF'(em5).

APPEND li_objhead.

CLEAR li_objpack.

**/ Creation of the entry for the compressed/attached document

li_objpack-transf_bin = c_true.

li_objpack-head_start = 1.

li_objpack-head_num = 1.

li_objpack-body_start = 1.

li_objpack-body_num = lv_tab_lines.

li_objpack-doc_type = 'PDF'.

li_objpack-obj_name = 'Possibly hover name'.

li_objpack-obj_descr = 'Real Name'(em6).

li_objpack-doc_size = lv_tab_lines * 255.

APPEND li_objpack. "/ .

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' "/ .

EXPORTING

document_data = ls_doc_chng

put_in_outbox = 'X'

TABLES

packing_list = li_objpack

object_header = li_objhead

contents_bin = pi_objbin

contents_txt = li_objtxt

receivers = li_reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

IF sy-subrc <> 0.

WRITE: / 'unsuccessful', sy-subrc.

ELSE.

WRITE: / 'successful'.

ENDIF.

**/Take_note it is a requirement to do a commit work for the

  • email to go into transaction SOST.

COMMIT WORK. "/Take_note .

ENDFORM. "send_email

&----


*& Form convert_to_pdf

&----


  • Convert the spool number on the screen to a PDF

----


FORM f_convert_to_pdf CHANGING pi_objbin TYPE ty_tab_objbin.

DATA: li_pdf TYPE ty_tab_pdf,

lv_spool LIKE tsp01-rqident.

lv_spool = p_spool.

**/ Call the standard function

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = lv_spool "/ .

no_dialog = ' '

  • DST_DEVICE =

  • PDF_DESTINATION =

  • IMPORTING

  • pdf_bytecount = numbytes

  • pdf_spoolid = pdfspoolid

    • LIST_PAGECOUNT =

  • btc_jobname = jobname

  • btc_jobcount = jobcount

TABLES

pdf = li_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.

IF sy-subrc <> 0.

WRITE: / 'error', sy-subrc.

ENDIF.

**/ Convert the PDF format to the table type required for the attachment.

CALL FUNCTION 'QCE1_CONVERT' "/ .

TABLES

t_source_tab = li_pdf

t_target_tab = pi_objbin

EXCEPTIONS

convert_not_possible = 1

OTHERS = 2.

IF sy-subrc <> 0.

WRITE: / 'error', sy-subrc.

ENDIF.

The function module will just create a pdf file..after that you have to call GUI_DOWNLOAD to download it to pc.

Cheers,

Phani

Message was edited by:

Phani Shankar

Read only

Former Member
0 Likes
721

hi

you need use FM CONVERT_OTF_2_PDF for convert and then use FM GUI_DOWNLOAD or DOWNLOAD, for example:

.........................CONVERT TO OTF TO PDF.......................

CALL FUNCTION 'CONVERT_OTF_2_PDF'

IMPORTING

bin_filesize = v_bin_filesize

TABLES

otf = st_job_output_info-otfdata

doctab_archive = it_docs

lines = it_lines

EXCEPTIONS

err_conv_not_possible = 1

err_otf_mc_noendmarker = 2

OTHERS = 3.

IF sy-subrc EQ 0.

concatenate 'C:\constancia_' sy-datum6(2) sy-datum4(2)

sy-datum+0(4) '.pdf' into v_filename.

perform fo_download_pdf tables it_lines

using v_bin_filesize

v_filename.

ENDIF.

else.

message i000(SU) with 'Genere el Formulario'

'ZHRO_CONST_PREST_ANT'.

endif.

&----


*& Form fo_download_pdf

&----


  • text

----


  • -->P_IT_LINES text

  • -->P_V_BIN_FILESIZE text

  • -->P_V_FILENAME text

----


FORM fo_download_pdf TABLES P_LINES structure tline

USING P_BIN_FILESIZE

P_FILENAME.

CALL FUNCTION 'DOWNLOAD'

EXPORTING

bin_filesize = p_bin_filesize

filename = p_filename

filetype = 'BIN'

FILETYPE_NO_CHANGE = 'X'

TABLES

data_tab = p_lines

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.

ENDFORM. " fo_download_pdf

Reward points

Regards

Gregory