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

Email notification

Former Member
0 Likes
1,131

Hi Friends,

I am doing one interface report the purpose of this report is to genarate flat file with data from SAP syatem

and this should be placed in some location at app server

so here mu doubt is........

An email notification should be sent to the user if any of the following error occured

a)Failure to export file

b)Duplicate file exist

c)Missing parameters in export

plz help in this.

Warm regards,

divya

1 ACCEPTED SOLUTION
Read only

Laxmana_Appana_
Active Contributor
0 Likes
829

Hi,

first capture the errors into one internal table while creating the file on application server like :

data : begin of i_errmsg occurs 0,
        x_msg(100) type c,
       end of i_errmsg.

OPEN DATASET x_file FOR output 
                            MESSAGE l_msg
                       IN text MODE ENCODING DEFAULT.
  x_RCODE = sy-subrc. 
  IF x_RCODE <> 0.
    <b>i_errmsg-x_msg = l_msg.
    append i_errmsg.</b>  endif.

then use the internal table i_errmsg to send error message details.

then use FM SO_NEW_DOCUMENT_ATT_SEND_API1 to send mail with error details

check this link for sample code:

/people/thomas.jung3/blog/2004/09/07/sending-e-mail-from-abap--version-46d-and-lower--api-interface

See below FM to send mails , it has two import parameters and one table parameter.

<b>pass user name to X_USNAM parameter

pass mail header text to X_MAIL_HEADER parameter

pass error messages to MAIL_CONTENT table parameter and call this FM , it will work</b>

FUNCTION z_mail_user.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(X_USNAM) TYPE USNAM
*" REFERENCE(X_MAIL_HEADER) TYPE SO_OBJ_DES
*" TABLES
*" MAIL_CONTENT STRUCTURE SOLISTI1
*" EXCEPTIONS
*" INVALID_PARAM
*" USER_NOT_FOUND
*"----------------------------------------------------------------------


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,
tab_lines TYPE i,
doc_size TYPE i.

IF x_usnam IS INITIAL .
RAISE invalid_param.
ENDIF.



* 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 sales manager User Id
reclist-receiver = x_usnam.
reclist-rec_type = 'B'.
APPEND reclist.

* Send Message
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = docdata
put_in_outbox = ''
commit_work = 'X'
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
TABLES
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = objtxt
* CONTENTS_HEX = objhex
* OBJECT_PARA =
* OBJECT_PARB =
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 invalid_param.
ENDIF.

ENDFUNCTION.

Regards

Appana

*Reward Points for helpful answers

Message was edited by: L Appana

5 REPLIES 5
Read only

Former Member
0 Likes
829

DS ,

If u are downloading/writing the data frm SAP then u can Raise Notification.

like this .

open data----


based on the SUBRC

EMAIL.

regards

Prabhu

Read only

Laxmana_Appana_
Active Contributor
0 Likes
830

Hi,

first capture the errors into one internal table while creating the file on application server like :

data : begin of i_errmsg occurs 0,
        x_msg(100) type c,
       end of i_errmsg.

OPEN DATASET x_file FOR output 
                            MESSAGE l_msg
                       IN text MODE ENCODING DEFAULT.
  x_RCODE = sy-subrc. 
  IF x_RCODE <> 0.
    <b>i_errmsg-x_msg = l_msg.
    append i_errmsg.</b>  endif.

then use the internal table i_errmsg to send error message details.

then use FM SO_NEW_DOCUMENT_ATT_SEND_API1 to send mail with error details

check this link for sample code:

/people/thomas.jung3/blog/2004/09/07/sending-e-mail-from-abap--version-46d-and-lower--api-interface

See below FM to send mails , it has two import parameters and one table parameter.

<b>pass user name to X_USNAM parameter

pass mail header text to X_MAIL_HEADER parameter

pass error messages to MAIL_CONTENT table parameter and call this FM , it will work</b>

FUNCTION z_mail_user.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(X_USNAM) TYPE USNAM
*" REFERENCE(X_MAIL_HEADER) TYPE SO_OBJ_DES
*" TABLES
*" MAIL_CONTENT STRUCTURE SOLISTI1
*" EXCEPTIONS
*" INVALID_PARAM
*" USER_NOT_FOUND
*"----------------------------------------------------------------------


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,
tab_lines TYPE i,
doc_size TYPE i.

IF x_usnam IS INITIAL .
RAISE invalid_param.
ENDIF.



* 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 sales manager User Id
reclist-receiver = x_usnam.
reclist-rec_type = 'B'.
APPEND reclist.

* Send Message
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = docdata
put_in_outbox = ''
commit_work = 'X'
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
TABLES
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = objtxt
* CONTENTS_HEX = objhex
* OBJECT_PARA =
* OBJECT_PARB =
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 invalid_param.
ENDIF.

ENDFUNCTION.

Regards

Appana

*Reward Points for helpful answers

Message was edited by: L Appana

Read only

0 Likes
829

hi appana,

i am writing code for sending email and i dont know what are the parameters i need to pass to this FM

PLZ CORRECT ME

REPORT ZMAILEXAMPLE123.

DATA: g_rcode TYPE sy-subrc.

DATA : BEGIN OF gt_errmsg OCCURS 0,

g_msg(100) TYPE c,

END OF gt_errmsg.

OPEN DATASET 'filename' FOR output MESSAGE zmsg IN text MODE ENCODING DEFAULT.

g_rcode = sy-subrc.

IF g_rcode <> 0.

gt_errmsg-g_msg = zmsg.

append gt_errmsg.

endif

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA =

  • PUT_IN_OUTBOX = ' '

  • COMMIT_WORK = ' '

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

PACKING_LIST =

  • OBJECT_HEADER =

  • CONTENTS_BIN =

  • CONTENTS_TXT =

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

RECEIVERS =

  • 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 SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

ENDIF.

REGARDS,

DIVYA

Read only

Former Member
0 Likes
829

Logic for your querry --

In your pgm.

OPEN DATASET....

IF sy-subrc <> 0.

LERR = 'Failure to Open File'.

endif.

If parameter = SPace.

Lerr = 'Missing Parameter'.

endif.

...

If Lerr <> SPACE.

call function SO_DOCUMENT_SEND_API1

--to send email with the above message.

endif.

Read only

0 Likes
829

Hi Friends,

I am doing one interface report the purpose of this report is to genarate flat file with data from SAP syatem

and this should be placed in some location at app server

so here mu doubt is........

An email notification should be sent to the user if any of the following error occured

a)Failure to export file

b)Duplicate file exist

c)Missing parameters in export

plz help in this Clearley what parameters i have to pass and all the stuff please.

Warm regards,

divya