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

Error Email

Former Member
0 Likes
505

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.

3 REPLIES 3
Read only

Former Member
0 Likes
450

Hello,

Try to use the class CL_SOTR_SEND_MAIL and method SEND_MAIL for sending mail.

Thanks,

Jayant

Read only

Former Member
0 Likes
450

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

Read only

Former Member