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

E-mail notification

Former Member
0 Likes
3,263

Hi,

I have job's running on production system. I have access to SM37 ... but everyday I have to go & check SM37 to see wether any job failed or not at SAP's end ... Is there a way where in the users & myself can get an e-mail notification if the job fails ...

Thank You,

SB.

1 ACCEPTED SOLUTION
Read only

Juwin
Active Contributor
0 Likes
2,901

Hi,

Create a report to do the following select, to get the job failure.

Select * from V_OP where STATUS = 'F' "(For failure).

If anything gets selected, then send the details using the function module mentioned in the previous post.

Thanks,

Juwin.

Hi,

Create a report to do the following select, to get the job failure.

Select * from V_OP where STATUS = 'F' "(For failure).

If anything gets selected, then send the details using the function module mentioned in the previous post.

Thanks,

Juwin.

11 REPLIES 11
Read only

Former Member
0 Likes
2,901

I don't know of an SAP provided solution, but you could easily write your own program to monitor the background jobs (tables TBTCO, TBTCP) and send emails when an error is detected. I did something similar to this to monitor errored transactions in SM58.

Read only

Former Member
0 Likes
2,901

Tyy the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'.

&----


& Mail to External email

*&----


DATA : SEND LIKE SONV-FLAG VALUE 'X',

V_LINE TYPE I.

DATA : SAP_INBOX_V_LINE TYPE I.

DESCRIBE TABLE S_RECNAM LINES SAP_INBOX_V_LINE.

LOOP AT S_RECNAM.

WS_SAP_INBOX-RECEIVER = S_RECNAM-LOW . "SY-UNAME. sap_inbox.

WS_SAP_INBOX-EXPRESS = 'X'.

WS_SAP_INBOX-REC_TYPE = 'B'.

APPEND WS_SAP_INBOX.

ENDLOOP.

LOOP AT S_RECNM1.

WS_SAP_INBOX-RECEIVER = S_RECNM1-LOW . "SY-UNAME. sap_inbox.

WS_SAP_INBOX-EXPRESS = 'X'.

WS_SAP_INBOX-REC_TYPE = 'U'.

APPEND WS_SAP_INBOX.

ENDLOOP.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = WS_DOC_CHNG

PUT_IN_OUTBOX = 'X'

SENT_TO_ALL = SEND "'X'

TABLES

PACKING_LIST = WS_OBJPACK

OBJECT_HEADER = WS_OBJHEAD

CONTENTS_BIN = WS_OBJBIN

CONTENTS_TXT = WS_OBJTXT

RECEIVERS = WS_SAP_INBOX

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 = 99.

CASE SY-SUBRC.

WHEN '1'.

RAISE TOO_MANY_RECEIVERS.

WHEN '2'.

RAISE DOCUMENT_NOT_SENT.

WHEN '4'.

RAISE OPERATION_NO_AUTHORIZATION.

  • WHEN OTHERS.

  • RAISE OTHERS.

ENDCASE.

  • ENDDO.

ENDFORM. " SEND_OBJECT

-SID

Read only

Juwin
Active Contributor
0 Likes
2,902

Hi,

Create a report to do the following select, to get the job failure.

Select * from V_OP where STATUS = 'F' "(For failure).

If anything gets selected, then send the details using the function module mentioned in the previous post.

Thanks,

Juwin.

Read only

Former Member
0 Likes
2,901

Hi Juwin,

Thanks for your reply... I am checking V_OP in prodcution system... & I wanted to know what the various values of the feild STATUS ... but I could not find them...

Above all just now a job finished which creats a session in SM35 ... so I was closely monitoring this job from SM37, SM35 & table V_OP...

SM37 & SM35 shows job as completed & session created & processed... but in V_OP (STATUS feild) is now showing "F" ... previously it was showing "S" ... also a new entry in V_OP got created with tomorrows date for the job & currently it's status feild is "S"... What I understand with this is "F" = Finished & "S" = Scheduled...

So how will I know from this table which all jobs failed??

Thank You,

SB.

Read only

Former Member
0 Likes
2,901

Hi,

I am looking into view V_OP ... & I am unable to get what are the different values to the field "STATUS".... there isno check table for this field so how do I know which job completed successfully & which failed...I also found the value "P" for this which I have no idea to what it stands for...

My requirement is that I have to check for successful & failed jobs that are related to all the interfaces running in the system ... My approach is to write a generic program with parameters having job names & then cross check against V_OP & alert or download a file giving the job status...

Is my approach correct ??

Read only

Former Member
0 Likes
2,901

Any Suggestion for the "STATUS" field in V_OP ??

Any help would be greatly appreciated.

Thank You,

SB.

Read only

Former Member
0 Likes
2,901

A - Cancelled

F - Completed

P - Scheduled

R - Active

S - Released

Read only

Former Member
0 Likes
2,901

Thank Michael... could you also tell me what is the purpose of NEWFLAG & how does this value get populated in the table.... I see various combinations like

Status = S Newflag = C

Status = F Newflag = C

Status = A Newflag = C

Status = P Newflag = S

Status = F Newflag = ' '(blank)

Status = S Newflag = ' '(blank)

Thank You,

SB

Read only

Former Member
0 Likes
2,901

I'm sorry I don't know what the newflag values represent. In the past, I've only concerned myself with the status field when writing monitoring routines.

Read only

sridhar_k1
Active Contributor
0 Likes
2,901

You can receive e-mails about failed jobs by using Tx: RZ21 and RZ20.

Refer to the following links:

RZ21: <a href="http://help.sap.com/saphelp_nw04/helpdata/en/2c/abb2e7ff6311d194c000a0c93033f7/frameset.htm">Define Automatic Alert Notification</a>

RZ20: <a href="http://help.sap.com/saphelp_nw04/helpdata/en/20/df2270043c11d294c300a0c93033f7/frameset.htm">Monitor Alerts for Background Processing</a>

Regards

Sridhar

Read only

Former Member
0 Likes
2,901

SB,

I use the following code to create a job and check on the status of that job. You could replace my error message with code to send an e-mail.

Bruce

*

report zfglr027 no standard page heading

line-size 132

message-id zf.

----


  • END-OF-SELECTION.

*

  • >>>>>>>> s e l e c t i o n s c r e e n o p t i o n s <<<<<<<

  • P_PRTR printer

  • P_PGM report painter program

  • P_VAR report painter variant

  • P_JOBNAM job name

  • P_WAIT seconds to wait in loop when checking if

  • program finished

*

----


*>>>>>>>>> T A B L E S <<<<<<<

tables: tsp01, " Spool Requests

tbtcp, " Background Job Step Overview

tbtcjob. " Structure for Passing Job Header Data (BI-API)

*>>>>>>>>> S E L E C T I O N S C R E E N O P T I O N S <<<<<<<

*

selection-screen begin of block b1 with frame title text-001.

parameter: p_prtr(4) default 'L9B' obligatory.

parameter: p_pgm like sy-repid obligatory

default 'ZMYSHOW'.

parameter: p_var like rsvar-variantt default 'XX' obligatory.

parameter: p_jobnam like tbtcjob-jobname default 'Budgeted_I_Stmnt'.

*

selection-screen end of block b1.

*

selection-screen begin of block b5 with frame title text-004.

selection-screen comment 1(55) text-005.

parameters: p_wait(3) type n default 010.

selection-screen end of block b5.

*

*>>>>>>>>> D A T A D E F I N I T I O N S <<<<<<<

data w_jobcount like tbtcjob-jobcount.

data: w_btcchar1(1).

data: w_jobhead like tbtco.

data: int_job_read_steplist like tbtcstep occurs 0 with header line.

data: w_rqident like tsp01-rqident.

data: wf_while_check(1).

data: e_receiver like zereport-receiver occurs 0 with header line.

data: e_sent like zereport-receiver occurs 0 with header line.

data w_start like sy-uzeit. " start time of Report Painter pgm

data w_code(40).

*

*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

*

start-of-selection.

perform 1000_run_program.

end-of-selection.

*

*

&----


*& Form 1000_run_program

&----


form 1000_run_program.

*

call function 'JOB_OPEN'

exporting

jobname = p_jobnam

importing

jobcount = w_jobcount

exceptions

cant_create_job = 1

invalid_job_data = 2

jobname_missing = 3

others = 4.

if sy-subrc <> 0.

case sy-subrc.

when 1.

w_code = 'cant_create_job'.

when 2.

w_code = 'invalid_job_data'.

when 3.

w_code = 'jobname_missing'.

when 4.

w_code = 'others'.

endcase.

message i000 with 'JOB_OPEN Error ' w_code ' Program aborted'.

format color col_negative.

skip 2.

write: / 'Program aborted.'.

write: / 'Function JOB_OPEN Error ', w_code.

stop.

endif.

format color col_normal.

skip 2.

write: / ' JOB_OPEN values after call:'.

write: /4 'jobname ', p_jobnam.

write: /4 'jobcount ', w_jobcount.

*

translate p_pgm to upper case.

get time field w_start .

  • submit ZMYSHOW

submit (p_pgm)

to sap-spool

destination p_prtr

immediately ' '

keep in spool 'X'

without spool dynpro

user sy-uname via job p_jobnam number w_jobcount

using selection-set p_var

using selection-sets of program p_pgm

and return.

*

skip 2.

write: / ' SUBMIT parameters after submit:'.

write: /4 'user ', sy-uname.

write: /4 'job ', p_jobnam.

write: /4 'jobcount ', w_jobcount.

write: /4 'program ', p_pgm.

write: /4 'variant ', p_var.

*

call function 'JOB_CLOSE'

exporting jobname = p_jobnam

jobcount = w_jobcount

strtimmed = 'X'

exceptions

cant_start_immediate = 1

invalid_startdate = 2

jobname_missing = 3

job_close_failed = 4

job_nosteps = 5

job_notex = 6

lock_failed = 7

others = 8.

if sy-subrc <> 0.

case sy-subrc.

when 1.

w_code = 'cant_start_immediate'.

when 2.

w_code = 'invalid_startdate'.

when 3.

w_code = 'jobname_missing'.

when 4.

w_code = 'job_close_failed'.

when 5.

w_code = 'job_nosteps'.

when 6.

w_code = 'job_notex'.

when 7.

w_code = 'lock_failed'.

when 8.

w_code = 'others'.

endcase.

message i000 with 'JOB_CLOSE Error ' w_code ' Program aborted'.

skip 2.

format color col_negative.

write: / 'Program aborted.'.

write: / 'Function JOB_CLOSE Error ', w_code.

stop.

endif.

format color col_normal.

skip 2.

write: / ' JOB_CLOSE values after call:'.

write: /4 'jobname ', p_jobnam.

write: /4 'jobcount ', w_jobcount.

*

  • w_jobhead-status possible values

  • btc_running like tbtco-status value 'R',

  • btc_ready like tbtco-status value 'Y',

  • btc_scheduled like tbtco-status value 'P',

  • btc_released like tbtco-status value 'S',

  • btc_aborted like tbtco-status value 'A',

  • btc_finished like tbtco-status value 'F',

  • btc_put_active like tbtco-status value 'Z',

  • btc_unknown_state like tbtco-status value 'X'.

*

  • Wait for a while so jobs can run

*

while ( not w_jobhead-status = 'F' ) and

( not w_jobhead-status = 'A' ).

call function 'BP_JOB_READ'

exporting

job_read_jobcount = w_jobcount

job_read_jobname = p_jobnam

job_read_opcode = '20'

importing

job_read_jobhead = w_jobhead

tables

job_read_steplist = int_job_read_steplist

exceptions

invalid_opcode = 1

job_doesnt_exist = 2

job_doesnt_have_steps = 3

others = 4.

if w_jobhead-status = 'F'. " F = Finished

exit.

elseif w_jobhead-status = 'A'. " A = Aborted

message e935 with 'BP_JOB_READ function Aborted.'

'Status is '

w_jobhead-status

'"'.

else.

  • wait up to 300 seconds.

wait up to p_wait seconds.

endif.

endwhile.

if w_jobhead-status <> 'F'.

write: / 'status', w_jobhead-status.

message e935 with

'BP_JOB_READ function did not complete successfully'

w_jobhead-status.

else.

*

endif.

*

*

endform. " 1000_run_program

*