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: 

Emailing Sap Scripts

Former Member
0 Kudos

Hi,

I wanted to Email a Sap Script to MS outlook.How can i proceed to Email.

I came to know that there are some function modules available for emailing.namley the following

1. RS_SEND_MAIL_FOR_SPOOLLIST

2. SO_NEW_DOCUMENT_ATT_SEND_API1

I donno where to place these function module in the Driver program and what will be the parameters that will be passed over there.

Kindly suggest me reg this.

Regards

Yamini.A

6 REPLIES 6

former_member214131
Active Contributor
0 Kudos

Hello,

Check this thread:

Hope this helps you.

Best Regards, Murugesh AS

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Check this link.Here I am mailing the output of smartform by converting it as PDF.I have used 'SO_NEW_DOCUMENT_ATT_SEND_API1 '

https://sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap code samples/smartforms/smart form in abap.pdf

Former Member
0 Kudos

Hi,

Thanks for your response.

I cheked the links given by you..i wanted to know where to call those function module

Is it between the open form and close form or after the close form.

Kindly suggest.

Regards

Yamini.A

0 Kudos

Please follow the steps:

1. Mark 'X' in the field TDGETOTF of the structure ITCPO of the FM: OPEN_FORM.

2. You will get the OTF data of the form in tables parameter of the FM: CLOSE_FORM.

3. After step 2, OTF data may be converted to PDF data by FM: CONVERT_OTF_2_PDF.

4. This PDF data may be downloaded by FM: WS_DOWNLOAD or GUI_DOWNLOAD.

5. You can send this as attachment as a mail by FM: SO_NEW_DOCUMENT_ATT_SEND_API1. Detailed documentation is available for this FM.

please code in the sequence of the above steps described.

I hope this helps you.

Regards, Murugesh AS

0 Kudos

Try this

  • Set print defaults

ls_itcpo-tdpreview = p_prev.

ls_itcpo-tdgetotf = p_email.

ls_itcpo-tdnewid = 'X'.

ls_itcpo-tdimmed = 'X'.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

device = 'PRINTER'

dialog = space

form = gv_form

language = sy-langu

options = ls_itcpo

EXCEPTIONS

canceled = 1

device = 2

form = 3

options = 4

unclosed = 5

mail_options = 6

archive_error = 7

invalid_fax_number = 8

more_params_needed_in_batch = 9

OTHERS = 10.

IF sy-subrc <> 0.

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

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

ENDIF.

blah, blah, blah....

CALL FUNCTION 'CLOSE_FORM'

TABLES

otfdata = lt_otfdata.

lt_content_in[] = lt_otfdata[].

CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'

EXPORTING

format_src = 'OTF'

format_dst = 'PDF'

devtype = 'PRINTER'

len_in = lv_len_in

TABLES

content_in = lt_content_in

content_out = lt_content_out.

gt_pdfdata[] = lt_content_out[].

  • File Name

ls_doc_chng-obj_name = 'SENDFILE'.

  • Mail Subject

CONCATENATE 'Certificate of Analysis for LWR' gs_header-lwr

INTO ls_doc_chng-obj_descr

SEPARATED BY space.

  • Mail Contents

lt_objtxt = 'Please refer to the attached document'.

APPEND lt_objtxt.

lt_objtxt = ''.

APPEND lt_objtxt.

lt_objtxt = 'Regards'.

APPEND lt_objtxt.

lt_objtxt = 'Ian Stubbings'.

APPEND lt_objtxt.

DESCRIBE TABLE lt_objtxt LINES lv_tab_lines.

READ TABLE lt_objtxt INDEX lv_tab_lines.

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

  • Creation of the entry for the email body

CLEAR lt_objpack-transf_bin.

lt_objpack-head_start = 1.

lt_objpack-head_num = 0.

lt_objpack-body_start = 1.

lt_objpack-body_num = lv_tab_lines.

lt_objpack-doc_type = 'RAW'.

APPEND lt_objpack.

  • Add attachment

DESCRIBE TABLE gt_pdfdata LINES lv_tab_lines.

READ TABLE gt_pdfdata INDEX lv_tab_lines.

CLEAR lt_objpack.

lt_objpack-transf_bin = 'X'.

lt_objpack-head_start = 1.

lt_objpack-head_num = 0.

lt_objpack-body_start = 1.

lt_objpack-body_num = lv_tab_lines.

lt_objpack-doc_type = 'PDF'.

lt_objpack-obj_name = 'email'.

lt_objpack-obj_descr = 'Certificate of analysis'.

lt_objpack-doc_size =

( 255 * ( lv_tab_lines - 1 ) ) + STRLEN( gt_pdfdata-line ).

APPEND lt_objpack.

  • Completing the recipient list

LOOP AT s_email.

lt_reclist-receiver = s_email-low.

lt_reclist-express = 'X'.

lt_reclist-rec_type = 'U'.

APPEND lt_reclist.

ENDLOOP.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = ls_doc_chng

put_in_outbox = 'X'

TABLES

packing_list = lt_objpack

object_header = lt_objhead

contents_bin = gt_pdfdata

contents_txt = lt_objtxt

receivers = lt_reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

CASE sy-subrc.

WHEN 0.

WRITE: / 'Result of the send process:'.

LOOP AT lt_reclist.

WRITE: / lt_reclist-receiver(48), ':'.

IF lt_reclist-retrn_code = 0.

WRITE 'The document was sent'.

ELSE.

WRITE 'The document could not be sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'No authorization for sending to the specified number',

'of recipients'.

WHEN 2.

WRITE: / 'Document could not be sent to any recipient'.

WHEN 4.

WRITE: / 'No send authorization'.

WHEN OTHERS.

WRITE: / 'Error occurred while sending'.

ENDCASE.

Former Member
0 Kudos

Hi,

Thanks Jayanthi,Murugesh,Ian Stubbings for your replies.

I was able to convert it to pdf using FM:SX_OBJECT_CONVERT_OTF_PDF and when i use the CONVERT_OTF_2_PDF i am not able to poplulate the value for tlines.

Ian Stubbings i have some doubts in your code can you kindly clarify .

what table should it refer for the lv_tab_lines in describe statment.

Regards

yamini.A