|
| 1 | +/* REXX */ |
| 2 | + /*----------------------------------------------------------*/ |
| 3 | + /* This Rexx is given a JCL dataset and member name in its */ |
| 4 | + /* parameter. */ |
| 5 | + /* The REXX: */ |
| 6 | + /* o submits the JCL */ |
| 7 | + /* o watches and waits for it to complete its execution*/ |
| 8 | + /* o returns to caller */ |
| 9 | + /* */ |
| 10 | + /*----------------------------------------------------------*/ |
| 11 | + CALL BPXWDYN 'INFO DD(SUBMITST)' |
| 12 | + If RESULT = 0 Then Trace ?R |
| 13 | + Arg SubmitJCL WaitLoops LoopSeconds; |
| 14 | + |
| 15 | + /* Set the value for Phase that indicates job is done */ |
| 16 | + FinalExpectedPhase = "AWAITING OUTPUT" |
| 17 | + |
| 18 | + /*----------------------------------------------------------*/ |
| 19 | + /* Get my jobname.... Cannot wait for myself */ |
| 20 | + /* Ensure the job we submit does not have the same jobname */ |
| 21 | + /* as my own. */ |
| 22 | + /*----------------------------------------------------------*/ |
| 23 | + myJobName = MVSVAR('SYMDEF',JOBNAME ) /*Returns JOBNAME */ |
| 24 | + |
| 25 | + /* Submit the JCL named in the parameter */ |
| 26 | + Call Submit_n_save_jobInfo; |
| 27 | + If SelectJobName = myJobName then, |
| 28 | + Do |
| 29 | + Say 'The job to be monitored is mine. Invalid request' |
| 30 | + Exit(8) |
| 31 | + End; |
| 32 | + |
| 33 | + /* Wait for the submitted job to finish */ |
| 34 | + jobnum = SelectJobNumber |
| 35 | + jobid = SelectJobName |
| 36 | + ownerid = USERID() |
| 37 | + retcode. = ' ' |
| 38 | + daten. = ' ' |
| 39 | + Timen.= ' ' |
| 40 | + PhaseName. = ' ' |
| 41 | + Call Monitor_Job_Status; |
| 42 | + |
| 43 | + exit |
| 44 | + |
| 45 | +Submit_n_save_jobInfo: /* submit SubmitJCL job and save job info */ |
| 46 | + |
| 47 | + Address TSO "PROFILE NOINTERCOM" /* turn off msg notific */ |
| 48 | + CALL MSG "ON" |
| 49 | + CALL OUTTRAP "out." |
| 50 | + ADDRESS TSO "SUBMIT '"SubmitJCL"'" ; |
| 51 | + CALL OUTTRAP "OFF" |
| 52 | + JobData = Strip(out.1); |
| 53 | + jobinfo = Word(JobData,2) ; |
| 54 | + If jobinfo = 'JOB' then, |
| 55 | + jobinfo = Word(JobData,3) ; |
| 56 | + SelectJobName = Word(Translate(jobinfo,' ',')('),1) ; |
| 57 | + SelectJobNumber = Word(Translate(jobinfo,' ',')('),2) ; |
| 58 | + |
| 59 | + Return; |
| 60 | + |
| 61 | +Monitor_Job_Status: |
| 62 | + |
| 63 | + IsfRC = isfcalls( "ON" ) |
| 64 | + if IsfRC <> 0 then Exit(8) |
| 65 | + |
| 66 | + myMessage = ' '; |
| 67 | + isfprefix = SelectJobname |
| 68 | + isfowner = USERID() |
| 69 | + isfcols = "jname jobid ownerid queue jclass prtdest retcode", |
| 70 | + " daten TIMEN PHASENAME " |
| 71 | + |
| 72 | + seconds = LoopSeconds /* Number of Seconds to wait if needed */ |
| 73 | + |
| 74 | + /*********************************************/ |
| 75 | + /* Wait until the submitted job is completed */ |
| 76 | + /*********************************************/ |
| 77 | + Do loop# = 1 to WaitLoops |
| 78 | + /* call exec_sdsf "0 ISFEXEC ST" opts_sdsf */ |
| 79 | + Address SDSF "isfexec ST (VERBOSE ALTERNATE DELAYED)" |
| 80 | + |
| 81 | + if RC <> 0 then, |
| 82 | + Do |
| 83 | + say "RC" RC "returned from ISFEXEC ST" ; |
| 84 | + Exit(12); |
| 85 | + end; |
| 86 | + |
| 87 | + Sa= 'isfcols=' isfcols |
| 88 | + StRows = isfrows |
| 89 | + If StRows = 0 then, |
| 90 | + Do |
| 91 | + say "No rows returned from ISFEXEC" |
| 92 | + Call WaitAwhile |
| 93 | + Iterate ; |
| 94 | + end; |
| 95 | + |
| 96 | + SubmittedJobPhase = 'Submitted' |
| 97 | + Call EvaluateSubmittedJob |
| 98 | + If SubmittedJobPhase = FinalExpectedPhase then Leave; |
| 99 | + |
| 100 | + Call WaitAwhile |
| 101 | + |
| 102 | + End; /* Do loop# = 1 to WaitLoops */ |
| 103 | + |
| 104 | + If SubmittedJobPhase /= FinalExpectedPhase then, |
| 105 | + Do |
| 106 | + Say 'Job' SelectJobname SelectJobNumber, |
| 107 | + ' not completed within Wait arguments', |
| 108 | + WaitLoops LoopSeconds |
| 109 | + exit(8) |
| 110 | + End |
| 111 | + |
| 112 | + Say 'Job' SelectJobname SelectJobNumber 'is completed', |
| 113 | + ' at ' DATE(S) TIME() |
| 114 | + |
| 115 | + Return; |
| 116 | + |
| 117 | +EvaluateSubmittedJob: |
| 118 | + |
| 119 | + Do row# = 1 to StRows |
| 120 | + Sa= 'Finding' jname.row# jobid.row# ownerid.row#, |
| 121 | + jclass.row# PhaseName.row# Timen.row# |
| 122 | + if jobid.row# /= SelectJobNumber then iterate; |
| 123 | + |
| 124 | + SubmittedJobPhase = PhaseName.row# |
| 125 | + Sa= 'Status:' SelectJobname SelectJobNumber , |
| 126 | + 'retcode.row#=' retcode.row# SubmittedJobPhase , |
| 127 | + ' on ' row# 'wait loop' |
| 128 | + Leave; |
| 129 | + End; /*Do row# = 1 to StRows */ |
| 130 | + |
| 131 | + Return; |
| 132 | + |
| 133 | +WaitAwhile: |
| 134 | + /* */ |
| 135 | + /* A resource is unavailable. Wait awhile and try */ |
| 136 | + /* accessing the resource again. */ |
| 137 | + /* */ |
| 138 | + /* The length of the wait is designated in the parameter */ |
| 139 | + /* value which specifies a number of seconds. */ |
| 140 | + /* A parameter value of '000003' causes a wait for 3 seconds. */ |
| 141 | + /* */ |
| 142 | + /*seconds = Abs(seconds) */ |
| 143 | + /*seconds = Trunc(seconds,0) */ |
| 144 | + Say "Waiting for" seconds "seconds at " DATE(S) TIME() |
| 145 | + /* AOPBATCH and BPXWDYN are IBM programs */ |
| 146 | + CALL BPXWDYN "ALLOC DD(STDOUT) DUMMY SHR REUSE" |
| 147 | + CALL BPXWDYN "ALLOC DD(STDERR) DUMMY SHR REUSE" |
| 148 | + CALL BPXWDYN "ALLOC DD(STDIN) DUMMY SHR REUSE" |
| 149 | + |
| 150 | + /* AOPBATCH and BPXWDYN are IBM programs */ |
| 151 | + parm = "sleep "seconds |
| 152 | + Address LINKMVS "AOPBATCH parm" |
| 153 | + |
| 154 | + Return |
| 155 | + |
0 commit comments