Application Development 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: 

How to send a mail to the user when a job gets canceled?

Former Member
0 Kudos

Hi experts,

I need to send a mail when a job gets canceled to the user.I know the FM for sending mail and i can find if a job is canceled from tbtco,but i want to know how to send the mail from the same program ,once it got canceled ?

thanks in advance,

helpful answers will be awarded with points

regards,

ashwin

4 REPLIES 4

Former Member
0 Kudos

hi Ashwin,

check this thread out. Hope this might help you

Regards,

Santosh

sreeramkumar_madisetty
Active Contributor
0 Kudos

Hi Ashwin

Use the below peace of code:

REPORT ZBCJOBMONITOR .

TABLES: SOMLREC90,

TBTCO.

DATA: MAILDATA LIKE SODOCCHGI1.

DATA: MAILTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: MAILREC LIKE SOMLREC90 OCCURS 0 WITH HEADER LINE.

DATA: I_TBTCO LIKE TBTCO OCCURS 0 WITH HEADER LINE.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001 .

SELECT-OPTIONS: S_JOB FOR TBTCO-JOBNAME.

SELECT-OPTIONS: S_JOBC FOR TBTCO-JOBClass.

SELECT-OPTIONS: S_REC FOR SOMLREC90-RECEIVER.

SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

CLEAR: MAILDATA, MAILTXT, MAILREC, I_TBTCO.

REFRESH: MAILTXT, MAILREC, I_TBTCO.

PERFORM GET_ABENDED_JOBS.

PERFORM BUILD_RECEIVERS.

LOOP AT I_TBTCO.

PERFORM BUILD_TEXT_MESSAGE.

PERFORM SEND_MAIL_NODIALOG..

ENDLOOP.

************************************************************************

  • Form BUILD_TEXT_MESSAGE

************************************************************************

FORM GET_ABENDED_JOBS.

SELECT * FROM TBTCO

INTO CORRESPONDING FIELDS OF TABLE I_TBTCO

WHERE JOBNAME IN S_JOB

AND STATUS = 'A'

AND JOBCLASS IN S_JOBC

AND SDLSTRTDT = SY-DATUM.

ENDFORM.

************************************************************************

  • Form BUILD_TEXT_MESSAGE

************************************************************************

FORM BUILD_TEXT_MESSAGE.

DATA: DATE(10) TYPE C.

DATA: TIME(10) TYPE C.

MAILDATA-OBJ_NAME = 'MONITOR'.

MAILDATA-OBJ_DESCR = 'Batch Job Monitor'.

MAILDATA-OBJ_LANGU = SY-LANGU.

CONCATENATE 'Job Name:' I_TBTCO-JOBNAME

INTO MAILTXT-LINE SEPARATED BY SPACE.

APPEND MAILTXT.

PERFORM FORMAT_DATE USING I_TBTCO-SDLSTRTDT

DATE.

CONCATENATE I_TBTCO-SDLSTRTTM+0(2) ':'

I_TBTCO-SDLSTRTTM+2(2) ':'

I_TBTCO-SDLSTRTTM+4(2)

INTO TIME.

CONCATENATE 'Start Date/Time:' DATE TIME

INTO MAILTXT-LINE SEPARATED BY SPACE.

APPEND MAILTXT.

CONCATENATE 'Job Class:' I_TBTCO-JOBCLASS

INTO MAILTXT-LINE SEPARATED BY SPACE.

APPEND MAILTXT.

MAILTXT-LINE = 'Job has terminated abnormally'.

APPEND MAILTXT.

ENDFORM.

************************************************************************

  • Form BUILD_RECEIVERS

************************************************************************

FORM BUILD_RECEIVERS.

LOOP AT S_REC.

CLEAR MAILREC.

MAILREC-RECEIVER = S_REC-LOW.

MAILREC-REC_TYPE = 'U'.

APPEND MAILREC.

ENDLOOP.

ENDFORM.

************************************************************************

  • Form SEND_MAIL_NODIALOG

************************************************************************

FORM SEND_MAIL_NODIALOG.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = MAILDATA

DOCUMENT_TYPE = 'RAW'

PUT_IN_OUTBOX = 'X'

TABLES

OBJECT_HEADER = MAILTXT

OBJECT_CONTENT = MAILTXT

RECEIVERS = MAILREC

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.

ENDFORM.

************************************************************************

  • Form FORMAT_DATE

************************************************************************

FORM FORMAT_DATE USING IN

OUT.

CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'

EXPORTING

DATE_INTERNAL = IN

IMPORTING

DATE_EXTERNAL = OUT

EXCEPTIONS

DATE_INTERNAL_IS_INVALID = 1

OTHERS = 2.

ENDFORM.

Regards,

Sree

Former Member
0 Kudos

Thanks for the immediate response,both the answers were helpful.

But is it possible to add sme code in the same program which gets canceled.If it is possible kindly mention how ?

I am not able to figure out how to trigger the mail from the same program because once the program gets canceled it will not go below that point of the code. That is what i assume,kindly suggest any help.

thanks

Ashwin

0 Kudos

Hi Ashwin,

Please have a look on the documentation for FM SO_NEW_DOCUMENT_ATT_SEND_API1. There is a sample code on how to send a mail out. And you can add this portion of code into your exsiting program, trigger the code whenever error hits as you mentioned.

Hope it helps.