Está en la página 1de 12

H Option( *SrcStmt: *NoDebugIo ) BndDir( 'QC2LE' ) DFTACTGRP(*No) ********************************************************************** * Project ID * * * * ********************************************************************** * * CrtUsrSpc: Create User Space for OS/400

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

** monitors for error in wrkactjob

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

10i 0 dim( 100 )

pr 2000A 15P 5

extpgm( 'QCMDEXC' ) options( *varsize ) const const

****************************************************************** dQUSA0100 DS

d QUsrSpcOffset... d d QUsrSpcEntries... d d QUsrSpcEntrieSize... d 13 16B 0 9 12B 0 1 4B 0

dLJOBINPUT d JobName d UserName d JobNumber d Status d UserSpace

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

d Reserved02 d NumberOfFieldsReturned... d d ReturnedData * dLJOB200KEY d KeyNumber01... d d NumberOfKeys... d * dLJOBKEYINFO ds ds

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 ErrorBytesProvided... d d ErrorBytesAvailble... d d ErrorExceptionId... d d ErrorReserved 7 1 10i 0 10i 0

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('alert@abcdomain.com')

d size d SleepMinutes d SleepSeconds d UsrSpcName

s s s s

10I 0 10i 0 inz(2) 10i 0 inz(25) 20 inz( 'DSPJOB QTEMP' )

*--------------------------------------------------------------* * work fields *

*--------------------------------------------------------------* 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('''')

15 0 inz 15 0 inz 15 0 inz 4 20 1 8 inz inz inz inz

10i 0 inz 10i 0 inz dim(100)

d d d d d d

ReceiverVariable... 32048 OS400_Cmd CmdLength True False 2000 inz( ' ' )

15P 5 inz( %size( OS400_Cmd ) ) 1 1 inz( *on ) inz( *off )

*-----------------------------------------------------------* 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);

reset JobInError; exsr CheckStatusOfJob;

// Delay job for a number of seconds then start

// the process all over again. sleep(SleepSeconds);

enddo;

*inlr = *on;

// ************************************************************* // check status of an job // -------------------------------------------------------------

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 :

LengthOfData : ReceiverVariable : APIError );

LJOB200 = ReceiverVariable; if APIErrorMessageID <> ' '; dump; ReturnCode = True; leavesr; endif;

// check status of job JobbStatus = ' '; Subsystem = ' '; LJobKeyInfo = LJob200.ReturnedData; KeyStartingPosition = 1; KeyLengthOfData = LJobKeyInfo.LengthOfInformation;

for keycount = 1 to LJob200.NumberOfFieldsReturned; LJobKeyInfo = %subst( LJob200.ReturnedData : KeyStartingPosition : KeyLengthOfData );

KeyLengthOfData = LJobKeyInfo.LengthOfInformation;

LJobKeyInfo = %subst( LJob200.ReturnedData : KeyStartingPosition : KeyLengthOfData ); Endpos = LJobKeyInfo.LengthOfData;

if LJobKeyInfo.KeyField = 0101; JobbStatus = %subst( LJobKeyInfo.KeyData : 1 : Endpos ); elseif LJobKeyInfo.KeyField = 1906; Subsystem = %subst( LJobKeyInfo.KeyData : 1 : Endpos ); endif;

KeyStartingPosition = KeyStartingPosition + KeyLengthOfData; endfor;

//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' + +

Q + ') longmsg(' + Q + 'Job (' + %trim( LJob200.JobName ) + '/' +

%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;

StartingPosition = StartingPosition + LengthOfData; endfor;

endsr; /end-free