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 Function Module

Former Member
0 Likes
559

Hi Experts

Can anyone give the general Function module name that sends an email when there is any error occurs in the ABAP Code,

Thanks

PR

4 REPLIES 4
Read only

Former Member
0 Likes
531

I dont think there is a seperate FM available to send dump messages. You will have to capture the dump message and code it to be sent as a email using any of the FM's to send a email.

Read only

Former Member
0 Likes
531

Hi,

You have to read the error message from t001 table with message type E into an intrenal table and then mail the same intrenal table using the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'.

Serach the forum ...you will get many other post on sending the email.

Pooja

Read only

Former Member
0 Likes
531

HI,

Try using FM:

SO_NEW_DOCUMENT_ATT_SEND_API1

You can go through the sample code below:

REPORT ZBC_ITAB_TO_EXCEL_NEW .

CLASS: cl_abap_char_utilities DEFINITION LOAD.

DATA: docdata LIKE sodocchgi1,

objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,

objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objbin1 LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objbin2 LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objbin_final LIKE solisti1 OCCURS 10 WITH HEADER LINE,

reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE,

tab_lines TYPE sy-tabix.

DATA: gd_sender_type LIKE soextreci1-adr_typ.

DATA: c_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

c_ret TYPE c VALUE cl_abap_char_utilities=>cr_lf.

DATA: c_dev TYPE sy-sysid.

DATA: BEGIN OF i_data OCCURS 0,

a(20),

b(20),

END OF i_data.

DATA: BEGIN OF st,

f1(2) TYPE c,

f2(2) TYPE n,

END OF st.

DATA: itab1 LIKE TABLE OF st WITH HEADER LINE,

itab2 LIKE TABLE OF st WITH HEADER LINE.

DATA: n TYPE i.

PARAMETER: p_email1 LIKE somlreci1-receiver,

p_sender LIKE somlreci1-receiver.

START-OF-SELECTION.

itab1-f1 = 'AA'. itab1-f2 = '01'. APPEND itab1.

itab1-f1 = 'BB'. itab1-f2 = '02'. APPEND itab1.

itab1-f1 = 'CC'. itab1-f2 = '03'. APPEND itab1.

itab2-f1 = 'ZZ'. itab2-f2 = '26'. APPEND itab2.

itab2-f1 = 'YY'. itab2-f2 = '25'. APPEND itab2.

LOOP AT itab1.

CONCATENATE itab1-f1 itab1-f2 INTO objbin1 separated BY c_tab.

CONCATENATE c_ret objbin1 INTO objbin1.

APPEND objbin1.

ENDLOOP.

LOOP AT itab2.

CONCATENATE itab2-f1 itab2-f2 INTO objbin2 separated BY c_tab.

CONCATENATE c_ret objbin2 INTO objbin2.

APPEND objbin2.

ENDLOOP.

LOOP AT objbin1.

MOVE objbin1-line TO objbin_final-line.

APPEND objbin_final.

ENDLOOP.

LOOP AT objbin2.

MOVE objbin2-line TO objbin_final-line.

APPEND objbin_final.

ENDLOOP.

PERFORM process_email.

c_dev = sy-sysid.

IF sy-sysid = c_dev.

wait up to 5 seconds.

SUBMIT rsconn01 WITH mode = 'INT'

WITH output = 'X'

AND RETURN.

ENDIF.

IF sy-subrc = 0.

WRITE: / 'Email succesfilly delivered'.

ELSE.

WRITE: / 'failure'.

ENDIF.

FORM process_email.

IF p_sender EQ space.

gd_sender_type = space.

ELSE.

gd_sender_type = 'INT'.

ENDIF.

*Body

docdata-obj_name = 'Mail_Excel_File'.

docdata-obj_descr = 'Excel file attachment'.

objtxt = 'Attached is the sample Excel file'.

APPEND objtxt.

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.

*Attachment

n = 1.

DESCRIBE TABLE objbin1 LINES tab_lines.

objpack-doc_size = tab_lines * 255.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = n.

objpack-body_num = tab_lines.

objpack-doc_type = 'XLS'.

docdata-obj_name = 'Excel_File_Attachment1'.

objpack-obj_descr = 'Excel File Attachment1'.

APPEND objpack.

n = n + tab_lines.

DESCRIBE TABLE objbin2 LINES tab_lines.

objpack-doc_size = tab_lines * 255.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = n.

objpack-body_num = tab_lines.

objpack-doc_type = 'XLS'.

docdata-obj_name = 'Excel_File_Attachment2'.

objpack-obj_descr = 'Excel File Attachment2'.

APPEND objpack.

*Create the list of recipients

reclist-receiver = p_email1.

reclist-rec_type = 'U'.

reclist-express = 'X'.

APPEND reclist.

*Send the e-mail

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = docdata

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = objpack

contents_bin = objbin_final

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.

COMMIT WORK.

ENDFORM. "process_email

Hope this helps

Regards

Mansi

Read only

Former Member
0 Likes
531

Thanks