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: 

send script as a pdf

Former Member
0 Kudos

hi,

i need to send the script as a pdf to external mail id...

how can i do this,kindly send the code so that it wud help...

it's urgent..

thanks in advance

5 REPLIES 5

gopi_narendra
Active Contributor
0 Kudos

Conversion to PDF - CONVERT_OTF_2_PDF

Email - SO_DOCUMENT_SEND_API1

Regards

- Gopi

Former Member
0 Kudos

Hi,

use the following code,

*Output PO to PDF

form output_pdf tables tab_ekko structure tab_ekko.

loop at tab_ekko.

waers = tab_ekko-waers.

perform itcpo_setup.

perform form_open.

*Write logo

call function 'WRITE_FORM' exporting

element = 'LOGO'

window = 'COMPANY'.

*Write Vendor Name and Address

perform get_vendor_details.

call function 'WRITE_FORM'

exporting

element = 'ADDRESS'

window = 'VENDOR'.

*Write Line Item

perform get_lineitem_details.

*Write Total

call function 'WRITE_FORM'

exporting

element = 'TOTAL'

window = 'MAIN'.

*Write Footer

call function 'WRITE_FORM'

exporting

element = 'FOOTER'

window = 'FOOTER'.

*Write PO Text

call function 'END_FORM'

importing

result = i_itcpp.

perform form_close.

perform otf_convert.

perform copy_to_wsdirectory_pdf.

perform send_po_att_mail.

endloop.

endform. "OUTPUT_PDF

form itcpo_setup.

  • SELECT SINGLE * FROM NAST

  • WHERE KAPPL ='EF' AND OBJKY = TAB_EKKO-EBELN.

  • IF SY-SUBRC = 0.

  • MOVE-CORRESPONDING NAST TO ITCPO.

clear: itcpo-tdpreview, itcpo-tdimmed, itcpo-tdnoprint,

itcpo-tdgetotf, xdialog.

itcpo-tdgetotf = 'X'.

itcpo-tdnoprint = 'X'.

clear: itcpo-tdpreview, itcpo-tdimmed.

itcpo-tdcover = nast-tdocover.

  • ITCPO-TDDEST = NAST-LDEST.

itcpo-tddest = 'HP0P'.

itcpo-tddataset = nast-dsnam.

itcpo-tdsuffix1 = nast-dsuf1.

itcpo-tdsuffix2 = nast-dsuf2.

itcpo-tddelete = nast-delet.

itcpo-tdcopies = nast-anzal.

itcpo-tdprogram = sy-repid.

itcpo-tdsenddate = nast-vsdat.

itcpo-tdsendtime = nast-vsura.

itcpo-tdiexit = 'X'.

  • ENDIF.

endform. "ITCPO_SETUP

form form_open.

call function 'OPEN_FORM'

exporting

form = 'YUTAC_PO_V01'

language = sy-langu

  • DEVICE = ' '

options = itcpo

dialog = ' '

exceptions

others = 1.

if xdialog = 'X'.

xdialog = space.

endif.

if sy-subrc ne 0.

retcode = sy-subrc.

perform protocol_update.

endif.

endform. "FORM_OPEN

*OTF Convert

form otf_convert.

refresh t_tline.

call function 'CONVERT_OTF'

exporting

format = 'PDF'

importing

bin_filesize = v_binfile

tables

otf = t_itcoo

lines = t_tline

exceptions

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

others = 4.

endform. "OTF_CONVERT

form copy_to_wsdirectory_pdf.

concatenate p_wsdir tab_ekko-ebeln '_' sy-datum sy-uzeit '.PDF'

into p_wsfile.

condense p_wsfile no-gaps.

call function 'WS_DOWNLOAD'

exporting

filename = p_wsfile

bin_filesize = v_binfile

filetype = 'BIN'

importing

filelength = v_binfile

tables

data_tab = t_tline

exceptions

file_open_error = 1

file_write_error = 2

invalid_filesize = 3

invalid_table_width = 4

invalid_type = 5

no_batch = 6

unknown_error = 7

gui_refuse_filetransfer = 8

others = 9.

end form

form form_close.

call function 'CLOSE_FORM'.

endform. "FORM_CLOSE

Regards,

Rajesh.

Former Member
0 Kudos

Hi,

you give me your mail id. i pass you the complete code.

Regards,

Rajesh.

0 Kudos

shakti.agnihotri@gmail.com

Kindly send the whole code,it's urgent

thanks yaar

Former Member
0 Kudos

A similar case was handled,check this code

REPORT Z_SCRIPT .

DATA: itcpo LIKE itcpo,

tab_lines LIKE sy-tabix.

  • Variables for EMAIL functionality

DATA: maildata LIKE sodocchgi1.

DATA: mailpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.

DATA: mailhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.

DATA: mailbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: mailtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: mailrec LIKE somlrec90 OCCURS 0 WITH HEADER LINE.

DATA: solisti1 LIKE solisti1 OCCURS 0 WITH HEADER LINE.

PERFORM send_form_via_email.

************************************************************************

  • FORM SEND_FORM_VIA_EMAIL *

************************************************************************

FORM send_form_via_email.

CLEAR: maildata, mailtxt, mailbin, mailpack, mailhead, mailrec.

REFRESH: mailtxt, mailbin, mailpack, mailhead, mailrec.

  • Creation of the document to be sent File Name

maildata-obj_name = 'TEST'.

  • Mail Subject

maildata-obj_descr = 'Subject'.

  • Mail Contents

mailtxt-line = 'Here is your file'.

APPEND mailtxt.

  • Prepare Packing List

PERFORM prepare_packing_list.

  • Set recipient - email address here!!!

mailrec-receiver = 'RAVINDRANATH.K@IN.BOSCH.COM'.

mailrec-rec_type = 'U'.

APPEND mailrec.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = maildata

put_in_outbox = ' '

TABLES

packing_list = mailpack

object_header = mailhead

contents_bin = mailbin

contents_txt = mailtxt

receivers = mailrec

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

ENDFORM.

************************************************************************

  • Form PREPARE_PACKING_LIST

************************************************************************

FORM prepare_packing_list.

CLEAR: mailpack, mailbin, mailhead.

REFRESH: mailpack, mailbin, mailhead.

DESCRIBE TABLE mailtxt LINES tab_lines.

READ TABLE mailtxt INDEX tab_lines.

maildata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( mailtxt ).

  • Creation of the entry for the compressed document

CLEAR mailpack-transf_bin.

mailpack-head_start = 1.

mailpack-head_num = 0.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'RAW'.

APPEND mailpack.

  • Creation of the document attachment

  • This form gets the OTF code from the SAPscript form.

  • If you already have your OTF code, I believe that you may

  • be able to skip this form. just do the following code, looping thru

  • your SOLISTI1 and updating MAILBIN.

PERFORM get_otf_code.

LOOP AT solisti1.

MOVE-CORRESPONDING solisti1 TO mailbin.

APPEND mailbin.

ENDLOOP.

DESCRIBE TABLE mailbin LINES tab_lines.

mailhead = 'TEST.OTF'.

APPEND mailhead.

    • Creation of the entry for the compressed attachment

mailpack-transf_bin = 'X'.

mailpack-head_start = 1.

mailpack-head_num = 1.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'OTF'.

mailpack-obj_name = 'TEST'.

mailpack-obj_descr = 'Subject'.

mailpack-doc_size = tab_lines * 255.

APPEND mailpack.

ENDFORM.

************************************************************************

  • Form GET_OTF_CODE

************************************************************************

FORM get_otf_code.

DATA: BEGIN OF otf OCCURS 0.

INCLUDE STRUCTURE itcoo .

DATA: END OF otf.

DATA: itcpo LIKE itcpo.

DATA: itcpp LIKE itcpp.

CLEAR itcpo.

itcpo-tdgetotf = 'X'.

  • Start writing OTF code

CALL FUNCTION 'OPEN_FORM'

EXPORTING

form = 'Z08V3_COLLI'

language = sy-langu

options = itcpo

dialog = ' '

EXCEPTIONS

OTHERS = 1.

CALL FUNCTION 'START_FORM'

EXCEPTIONS

error_message = 01

OTHERS = 02.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

window = 'MAIN'

EXCEPTIONS

error_message = 01

OTHERS = 02.

  • Close up Form and get OTF code

CALL FUNCTION 'END_FORM'

EXCEPTIONS

error_message = 01

OTHERS = 02.

MOVE-CORRESPONDING itcpo TO itcpp.

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

result = itcpp

TABLES

otfdata = otf

EXCEPTIONS

OTHERS = 1.

  • Move OTF code to structure SOLI form email

CLEAR solisti1. REFRESH solisti1.

LOOP AT otf.

solisti1-line = otf.

APPEND solisti1.

ENDLOOP.

ENDFORM.]

Regards