Upload 42
Upload 42
Upload 42
API's * d QUSCRTUS d d d d d d d d * * --- Prototype for API Retrive User Space * d QUSRTVUS d d d d d d QRtvLengthOfData... 10i 0 QRtvStartingPosition... 10i 0 pr extpgm( 'QUSRTVUS' ) UsrSpc ExtAttr InitialSize InitialVal PublicAuth Text Replace ErrorCode pr 20A 10A extpgm('QUSCRTUS') const const 11/22/11 JJF 00 program written Date Pgmr ID Rev Description
10I 0 const 1A 10A 50A 10A 32766A const const const const options(*nopass: *varsize)
QRtvUserSpace... 20
d d d d
QRtvReceiverVariable... 32048 QRtvError... 256 * --- Prototype for API Retrive List Job *
d QUSLJOB d d d d d d d d d d d d d d d d * d qcmdexc d d * os400_cmd cmdlength QKeyFldRtn... QNbrFldRtn... QJobType... QFldError... QFldStatus... QJobJobName...
pr
extpgm( 'QUSLJOB' )
QJobUserSpace... 20 QJobFormatName... 8
26
10
256
10i 0
pr 2000A 15P 5
****************************************************************** dQUSA0100 DS
ds 10 10 6 10 10
qualified
d UserSpaceLibrary... d d Format d JobType d Reserved01 d Reserved02 * dLJOB200 d JobName d UserName d JobNumber d InternalJobId d Status d JobType d JobSubType d Reserved01 d JobInfoStatus ds 10 10 6 16 10 1 1 2 1 qualified 10 8 1 3 10i 0
10i 0 1000
qualified
10i 0
10i 0
qualified
d LengthOfInformation... d d KeyField d TypeOfData d Reserved01 d LengthOfData d KeyData * * APIErrDef * dQUSEC DS Standard API error handling structure. * 10i 0 10i 0 1 3 10i 0 1000
d * dAPIError DS
d APIErrorProvied... d d d APIErrorAvailble... d d APIErrorMessageID... d d APIErrorReserved... d d APIErrorInformation... d 240A *----------------------------------------------------------------* program status dataarea *----------------------------------------------------------------d PgmSts d d P1User W1Program SDS 254 *PROC 263 LIKE( ErrorReserved ) LIKE( ErrorExceptionId ) LIKE( ErrorBytesAvailble ) LIKE( ErrorBytesProvided ) INZ( %LEN( APIError ) )
*--------------------------------------------------------------* * * Defined variables * d dlr d emailaddress d foundit d jobinerror d KeepLooping d sendmessage s s s s s s 9 0 24 4 0 n n n inz('1') inz('1') inz('[email protected]')
s s s s
*--------------------------------------------------------------* d Variables d d d d d d d d d d d d d d d d d d d d d KeyLengthOfData... 10i 0 inz LengthOfData KeyStartingPosition... 10i 0 inz JobStatus JobType NbrOfFldRtn KeyFldRtn StartingPosition... 10i 0 inz 10i 0 inz Q Count KeyCount EndPos JobbStatus Subsystem ReturnCode FormatName QualifedJobName... 26 10 1 inz inz inz ds 1 inz('''')
d d d d d d
ReceiverVariable... 32048 OS400_Cmd CmdLength True False 2000 inz( ' ' )
*-----------------------------------------------------------* Delay - sleep function *-----------------------------------------------------------d sleep d seconds * d DSLastRun d LastRunArray d d Jobname Stamp /free 10A Z ds Dim(50) Overlay(LastRunArray) Overlay(LastRunArray:*Next) Qualified pr 10i 0 ExtProc( 'sleep' ) 10u 0 Value
// program will loop until outside force // stops it. dow KeepLooping;
size = 10000; QUSCRTUS(UsrSpcName: 'USRSPC': size: x'00': '*ALL': 'Temp User Space for QUSLJOB API': '*YES': APIError);
enddo;
*inlr = *on;
begsr CheckStatusOfJob;
// run API to fill user space with information about all iSeries job FormatName = 'JOBL0200'; QualifedJobName = '*ALL JobStatus = '*ACTIVE'; JobType = '*'; NbrOfFldRtn = 2; KeyFldRtn( 1 ) = 0101; KeyFldRtn( 2 ) = 1906; QUSLJOB( UsrSpcName : FormatName : QualifedJobName : JobStatus : APIError JobType : ); ' + '*ALL ' + '*ALL ';
: NbrOfFldRtn : KeyFldRtn
// if error message from the retrieve job API then dump program if APIErrorMessageID <> ' '; dump; ReturnCode = True; leavesr; endif;
// run API to get user space attribute StartingPosition = 125; LengthOfData = 16; callp QUSRTVUS( UsrSpcName : StartingPosition :
LengthOfData : ReceiverVariable : APIError QUSA0100 = ReceiverVariable; // error message from the retrieve user space API then dump program if APIErrorMessageID <> ' '; dump; ReturnCode = True; leavesr; endif; );
// preperation to read from user space StartingPosition = QUsrSpcOffset + 1; LengthOfData = QUsrSpcEntrieSize; // read from user space for count = 1 to QUsrSpcEntries; QUSRTVUS( UsrSpcName : StartingPosition :
LJOB200 = ReceiverVariable; if APIErrorMessageID <> ' '; dump; ReturnCode = True; leavesr; endif;
// check status of job JobbStatus = ' '; Subsystem = ' '; LJobKeyInfo = LJob200.ReturnedData; KeyStartingPosition = 1; KeyLengthOfData = LJobKeyInfo.LengthOfInformation;
KeyLengthOfData = LJobKeyInfo.LengthOfInformation;
if LJobKeyInfo.KeyField = 0101; JobbStatus = %subst( LJobKeyInfo.KeyData : 1 : Endpos ); elseif LJobKeyInfo.KeyField = 1906; Subsystem = %subst( LJobKeyInfo.KeyData : 1 : Endpos ); endif;
//only want to send a message ever ???? minutes //this code will help do that
reset sendmessage;
if Jobbstatus = 'MSGW' and Ljob200.Jobname <> 'EDH_JRNCLN'; Foundit = %lookup(LJob200.JobName :DsLastRun.Jobname); if Foundit > *zeros; if %diff(%timestamp():DsLastRun.Stamp(Foundit):*minutes) < sleepMinutes; SendMessage = *off; JobInError = *on; else; DsLastRun.Stamp(Foundit) = %timestamp(); endif; else; dlr +=1; DsLastRun.Jobname(dlr) = LJob200.JobName; DsLastRun.Stamp(dlr) = %timestamp(); JobInError = *on; endif;
if SendMessage = *on; Subsystem = %trim( %subst( Subsystem : 11 : 10 ) ) + '/' + %trim( %subst( Subsystem : 1 : 10 ) ); os400_cmd = 'snddst type(*lmsg) ' + 'tointnet((' + Q + %trim(EmailAddress) + Q + ')) dstd(' + Q 'Job is in *MSGW' + +
%trim( LJob200.UserName ) + '/' + %trim( LJob200.JobNumber ) + ') subsystem ' + %trim( Subsystem ) + ' in status *MSGW' + Q + ')'; monitor; qcmdexc ( os400_cmd : %size ( os400_cmd ) ); on-error; dump; endmon; endif;
endif;
endsr; /end-free