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: 

email distribution

Former Member
0 Kudos

Hi,

Can anyone explain with an example how to send an email to multiple recepients if an error triggered. i have been trying with the FM SO_NEW_DOCUMENT_ATT_SEND_API1 for this. But i dont know to declare certain parameters in that. Could anyone help me out to clear it out with an example.

Thanks in Advance,

Regards

Rijish

2 REPLIES 2

Former Member
0 Kudos

Check the below code:

FUNCTION zm_sendmail_user.

*"----


""Local interface:

*" IMPORTING

*" REFERENCE(X_USER) TYPE USNAM

*" REFERENCE(X_MAIL_HEADER) TYPE SO_OBJ_DES

*" REFERENCE(X_EXPRESS) TYPE SO_SND_EX OPTIONAL

*" REFERENCE(X_NO_COMMIT) TYPE C OPTIONAL

*" TABLES

*" MAIL_CONTENT STRUCTURE SOLISTI1

*" EXCEPTIONS

*" USER_DOES_NOT_EXIST

*" MAIL_ERROR

*"----


DATA : docdata LIKE sodocchgi1,

objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,

objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,

objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objhex LIKE solix OCCURS 10 WITH HEADER LINE,

reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.

DATA: tab_lines TYPE i,

doc_size TYPE i,

ws_commit TYPE c,

lt_valid_user TYPE STANDARD TABLE OF uslocusers,

lt_serv_user TYPE STANDARD TABLE OF uslocusers,

ls_valid_user TYPE uslocusers.

  • Check if the User is valid

CALL FUNCTION 'VCM_GET_VALID_USERS'

TABLES

valid_users = lt_valid_user

service_users = lt_serv_user.

SORT lt_valid_user BY bname.

READ TABLE lt_valid_user WITH KEY bname = x_user

BINARY SEARCH INTO ls_valid_user.

IF sy-subrc EQ 0.

  • Fill Mail Contents

objbin = space.

APPEND objbin.

docdata-obj_name = x_mail_header.

docdata-obj_descr = x_mail_header.

  • Main Text

objtxt[] = mail_content[].

  • Write Packing List (Main)

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'RAW'.

APPEND objpack.

  • Add User Id

reclist-receiver = x_user.

reclist-rec_type = 'B'.

*To send express mail ( Changed by INSPU1 ).

reclist-express = x_express.

APPEND reclist.

*Set the commit flag

IF x_no_commit EQ 'X'.

CLEAR ws_commit .

ELSE.

ws_commit = 'X'.

ENDIF.

  • Send Message

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = docdata

put_in_outbox = ''

commit_work = ws_commit

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

IF sy-subrc <> 0.

  • MESSAGE ID 'SO' TYPE 'S' NUMBER '023' WITH docdata-obj_name.

RAISE mail_error.

ENDIF.

ELSE.

RAISE user_does_not_exist.

ENDIF.

ENDFUNCTION.

Regards,

Prakash.

Former Member
0 Kudos

http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm

check this link,will help you definitely.

also check this,

here refer the posts by Rich.

Regards

Srikanth

Message was edited by: Srikanth Kidambi