‎2008 Nov 07 8:18 AM
hi ,
the report need to be executed in SM36 .
if the data doesnot exist for the selction criteria given or if the job failed in SM36 an email need to be triggered to particular mail id given in the selection screen. i have written code for if the data does not exists an email to be sent
but how to write code if the job cancelled then an email to be sent.
the status of the job exists in TBTCO table ,
code:
PERFORM get_data.
PERFORM check_job_done.
IF gt_final[] IS INITIAL.
PERFORM send_mail.
ENDIF.
-
PERFORM check_job_done.
-
SELECT jobname jobcount status enddate endtime
FROM tbtco
INTO CORRESPONDING FIELDS OF TABLE gt_tbtco
WHERE jobname = 'ZEMAIL'.
IF sy-subrc = 0.
READ TABLE gt_tbtco INDEX 1.
IF gt_tbtco-status = c_r_status
OR gt_tbtco-status = c_p_status
OR gt_tbtco-status = c_y_status
OR gt_tbtco-status = c_s_status
OR gt_tbtco-status = c_x_status
OR gt_tbtco-status = c_z_status.
Error when there is something wrong with the job
PERFORM send_mail.
endif.
ELSE.
IF gt_tbtco-status = c_f_status.
exit.
ENDIF.
endif.
-
PERFORM send_mail.
-
l_email_recvr = p_recvr.
Send email to the receiving person/group
CALL FUNCTION 'EFG_GEN_SEND_EMAIL'
EXPORTING
i_title = l_email_hdr
i_sender = l_email_sndr
i_recipient = l_email_recvr
TABLES
i_tab_lines = gt_msg.
‎2008 Nov 07 8:20 AM
Hello,
Try to use the class CL_SOTR_SEND_MAIL and method SEND_MAIL for sending mail.
Thanks,
Jayant
‎2008 Nov 07 8:25 AM
Hi,
Here is an example for you...
report zemail.
tables: adr6.
data: send_request type ref to cl_bcs,
document type ref to cl_document_bcs,
recipient type ref to if_recipient_bcs,
bcs_exception type ref to cx_bcs.
data: sent_to_all type os_boolean,
adresse type adr6-smtp_addr,
subject type so_obj_des,
text type bcsy_text,
line type soli-line.
data: reciever type table of adr6-smtp_addr.
* Email address
select-options: s_smtp for adr6-smtp_addr no intervals
default 'your.email.
start-of-selection.
*--Build the email body
line = 'Email body'.
append line to text.
*--Build the send request
try.
*--create the send request
send_request = cl_bcs=>create_persistent( ).
document = cl_document_bcs=>create_document( i_type = 'RAW'
i_text = text
i_subject = subject ).
*--add document to send request
send_request->set_document( document ).
*--create recipient and add to send request
loop at s_smtp.
check ( s_smtp-low is not initial ).
adresse = s_smtp-low.
recipient = cl_cam_address_bcs=>create_internet_address( adresse ).
send_request->add_recipient( i_recipient = recipient ).
endloop.
*--send mail now
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
if sent_to_all = 'X'.
message s022(so).
endif.
catch cx_bcs into bcs_exception.
message e865(so) with bcs_exception->error_type.
endtry.
commit work.Darren
‎2008 Nov 07 8:26 AM
Hi Hemal,
Please refer the below links:
http://searchsap.techtarget.com/tip/1,289483,sid21_gci868240,00.html
http://help.sap.com/saphelp_nw04/helpdata/en/2c/abb2e7ff6311d194c000a0c93033f7/content.htm
Hope these help you.
Thanks,
Dawood.