Skip to Content
author's profile photo Former Member
Former Member

How to set Automated emails on ABAP job failure (sm37)?

Hello,

Can u please tell me how to How to set Automated emails on ABAP job failure (sm37)?

Scenario:

We have scheduled jobs in SM37.

And at the end of job completion or failure we need to generate automated e mails

Please provide me with the steps.

Thank you,

Rezwan

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Apr 09, 2009 at 02:47 PM

    Hi,

    You can try this solution.

    Check for a BADI or User exit for the transaction SM37.

    At the end of Job completion, write the coding logic to send the details of the job (Which you can find from the signatureof the BADI or User exit like properties, attributes, etc.).

    The job details will be obtained in an internal table. Just use that internal table and try to check for a field which contains the status of the job.

    Then write some IF logic.. If jobstatus = completed or jobstatus = cancelled, then intimate the person responsible with a mail.

    Write this in the coding logic.

    You can use the function module : SO_NEW_DOCUMENT_SEND_API1.

    But the problem here is that, COMMIT_WORK in the function module should be set to X. But inside BADI or User exit, you should not do the commit work.

    Search for the forum for this alone. I think some person have already requested how to do commit_work in BADI.

    Hope this might help you.

    Best Regards,

    Suresh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 09, 2009 at 03:07 PM

    Hi asraf

    U can write a report which will check for the failed jobs for the specified time back from the current time (status available in the table TBTCO) and prepare a mail from that details, and send it to the required users.

    This report has to be scheduled in SM37 as a periodic job so that it will continuosly check and send mails.

    The specified time in the report and the periodicity of the backgrouund job should be in par so that u neither miss any detail nor get repated one.

    if this condition is ok for u , u can use the following code.

    This code will check for the previouus 24 hrs and send mail to the respective users who scheduled the job.

    *********

    TABLES : TBTCO.

    DATA: USER TYPE SO_RECNAME .

    DATA : CURR_DT TYPE SY-DATUM,

    PERIOD TYPE SY-DATUM.

    DATA : BEGIN OF IT_BKST OCCURS 0.

    INCLUDE TYPE TBTCO .

    DATA : S_DATE(10),

    S_TIME(15),

    END OF IT_BKST.

    DATA J_NAME(50).

    CONSTANTS: IN_SPACE(20) VALUE ' '.

    CONSTANTS: IN_SPACE2(5) VALUE ' '.

    DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

    DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

    DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

    DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

    DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

    DATA: DOC_CHNG LIKE SODOCCHGI1.

    DATA: TAB_LINES LIKE SY-TABIX.

    DATA: PERIOD2(10).

    SELECT-OPTIONS: REQ_DT FOR SY-DATUM NO-DISPLAY,

    REQ_TIME FOR SY-UZEIT NO-DISPLAY.

    INITIALIZATION.

    CURR_DT = SY-DATUM.

    PERIOD = SY-DATUM - 1.

    START-OF-SELECTION.

    PERFORM GET_DATA.

    IF NOT IT_BKST[] IS INITIAL.

    PERFORM SEND_MAIL.

    ENDIF.

    *&----


    *

    *& Form get_data

    *&----


    *

    • text

    *----


    *

    • --> p1 text

    • <-- p2 text

    *----


    *

    FORM GET_DATA .

    SELECT * FROM TBTCO INTO CORRESPONDING FIELDS OF TABLE IT_BKST WHERE STATUS EQ 'A' AND STRTDATE EQ PERIOD.

    IF NOT IT_BKST[] IS INITIAL.

    SORT IT_BKST[] BY SDLUNAME ASCENDING STRTDATE DESCENDING STRTTIME ASCENDING.

    LOOP AT IT_BKST.

    CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'

    EXPORTING

    DATE_INTERNAL = IT_BKST-STRTDATE

    IMPORTING

    DATE_EXTERNAL = IT_BKST-S_DATE

    EXCEPTIONS

    DATE_INTERNAL_IS_INVALID = 1

    OTHERS = 2.

    IF SY-SUBRC <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

    ENDIF.

    CONCATENATE IT_BKST-STRTTIME0(2) ':' IT_BKST-STRTTIME2(2) ':' IT_BKST-STRTTIME+4(2) INTO IT_BKST-S_TIME SEPARATED BY SPACE.

    MODIFY IT_BKST TRANSPORTING S_DATE S_TIME.

    ENDLOOP.

    CONCATENATE PERIOD6(2) PERIOD4(2) PERIOD+0(4) INTO PERIOD2 SEPARATED BY '.'.

    ENDIF.

    ENDFORM. " get_data

    *&----


    *

    *& Form send_mail

    *&----


    *

    • text

    *----


    *

    • --> p1 text

    • <-- p2 text

    *----


    *

    FORM SEND_MAIL .

    LOOP AT IT_BKST .

    CLEAR: OBJTXT[],DOC_CHNG,RECLIST[],OBJPACK[],OBJTXT,DOC_CHNG,RECLIST,OBJPACK.

    IF IT_BKST-SDLUNAME EQ USER.

    CONTINUE.

    ENDIF.

    USER = IT_BKST-SDLUNAME.

    DOC_CHNG-OBJ_NAME = 'STATUS'.

    DOC_CHNG-OBJ_DESCR = 'Canceled Background job(s)' .

    OBJTXT = 'Dear Sir/Madam'.

    APPEND OBJTXT.

    OBJTXT = ' '.

    APPEND OBJTXT.

    CONCATENATE 'This is to notify that the following background job(s) you''ve scheduled on ' ' ' PERIOD2 ' has been canceled, please check SM37 for details' INTO OBJTXT.

    APPEND OBJTXT.

    OBJTXT = ' '.

    APPEND OBJTXT.

    LOOP AT IT_BKST WHERE SDLUNAME EQ USER.

    WRITE IT_BKST-JOBNAME TO J_NAME.

    CONCATENATE J_NAME IT_BKST-S_DATE IN_SPACE2 IT_BKST-S_TIME INTO OBJTXT RESPECTING BLANKS.

    APPEND OBJTXT.

    ENDLOOP.

    OBJTXT = ' '.

    APPEND OBJTXT.

    OBJTXT = 'Thankyou'.

    APPEND OBJTXT.

    DESCRIBE TABLE OBJTXT LINES TAB_LINES.

    READ TABLE OBJTXT INDEX TAB_LINES.

    DOC_CHNG-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'.

    • OBJPACK-TRANSF_BIN = 'X'.

    APPEND OBJPACK.

    RECLIST-RECEIVER = USER.

    RECLIST-REC_TYPE = 'B'.

    RECLIST-EXPRESS = 'X'.

    APPEND RECLIST.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    DOCUMENT_DATA = DOC_CHNG

    PUT_IN_OUTBOX = 'X'

    COMMIT_WORK = 'X'

    TABLES

    PACKING_LIST = OBJPACK

    OBJECT_HEADER = OBJHEAD

    • CONTENTS_BIN = OBJBIN

    CONTENTS_TXT = OBJTXT

    RECEIVERS = RECLIST

    EXCEPTIONS

    TOO_MANY_RECEIVERS = 1

    DOCUMENT_NOT_SENT = 2

    OPERATION_NO_AUTHORIZATION = 4

    OTHERS = 99.

    WAIT UP TO 2 SECONDS.

    IF SY-SUBRC EQ 0.

    SUBMIT RSCONN01 WITH MODE = '*'

    WITH OUTPUT = ' '

    AND RETURN.

    ENDIF.

    ENDLOOP.

    ENDFORM. " send_mail

    All the best

    Regards

    Prabumanoharan

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi, i'm learning workflows and i think what this is the typical case for apply workflows by event when one job is canceled, the bussines object is BPJOB and the event is the ABORTED, controlled by one workflow and to send email to agent recipient, but i don't know as to do this workflow.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.