/*----------------------------------------------------------------------------*/ /* Program : RTVACTJOB */ /* Description : Using the QUSLJOB API to retrieve active jobs by user. */ /* Written by : Paul Pritchard */ /* */ /* This program is free software: you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation, either version 3 of the License, or */ /* (at your option) any later version. */ /* */ /* This program is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* */ /* You should have received a copy of the GNU General Public License */ /* along with this program. If not, see . */ /*----------------------------------------------------------------------------*/ PGM DCL &USRJOB *CHAR 26 /* Job Name for User */ DCL &JOBNBR *CHAR 6 /* Job number for this job */ DCl &JOBUSRSPC *CHAR 20 VALUE('CHGA QTEMP ') /* API User Space */ DCL &CMDUSRSPC *CHAR 10 /* User space name for commands */ DCL &WRKBIN4 *CHAR 4 /* Work field - binary 4 format */ DCL &WRKDEC8 *DEC (8 0) /* Work field - decimal 8 format */ DCL &ENTRYLENB4 *CHAR 4 /* Job list entry length - binary 4 format */ DCL &ENTRYLEN *DEC (8 0) /* Job list entry length - decimal format */ DCL &JOBLSTENT *CHAR 56 /* Job list entry */ DCL &LOOP *DEC (8 0) /* Loop counter */ DCLF USERTABLE /* Application users - used to drive processing */ /* Retrieve job details and determine local user space name */ RTVJOBA NBR(&JOBNBR) CHGVAR VAR(%SST(&JOBUSRSPC 5 6)) VALUE(&JOBNBR) CHGVAR VAR(&CMDUSRSPC) VALUE(%SST(&JOBUSRSPC 1 10)) /* Main Program Loop */ STEP01: RCVF MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(STEP02)) /* An additional step can be included here if you have a field in your */ /* USERTABLE that determines whether a user should be allowed in or not. */ /* If they are allowed in and you want to take no further action, GOTO STEP01 */ /* Delete user space if it already exists */ DLTUSRSPC USRSPC(QTEMP/&CMDUSRSPC) MONMSG CPF0000 /* Create the user space */ CALL QUSCRTUS (&JOBUSRSPC 'CHGACTJOB ' X'00000100' ' ' + '*ALL ' 'CKE001 TEMPORARY USER SPACE') /* Set up job name for list jobs */ /* Field &USERID isn't explictly declared as it is a field in USERTABLE */ CHGVAR VAR(%SST(&USRJOB 1 10)) VALUE('*ALL ') CHGVAR VAR(%SST(&USRJOB 11 10)) VALUE(&USERID) CHGVAR VAR(%SST(&USRJOB 21 6)) VALUE('*ALL ') /* List active jobs with job name specified */ CALL QUSLJOB (&JOBUSRSPC 'JOBL0100' &USRJOB '*ACTIVE ') /* Retrieve number of entries returned. Convert to decimal and, if zero, loop */ CALL QUSRTVUS (&JOBUSRSPC X'00000085' X'00000004' &WRKBIN4) CHGVAR &LOOP %BINARY(&WRKBIN4) IF COND(&LOOP = 0) THEN(GOTO CMDLBL(STEP01)) /* Retrieve list entry length, convert to decimal. */ /* Retrieve list entry offset, convert to decimal, and add one to set position*/ CALL QUSRTVUS (&JOBUSRSPC X'00000089' X'00000004' &ENTRYLENB4) CHGVAR &ENTRYLEN %BINARY(&ENTRYLENB4) CALL QUSRTVUS (&JOBUSRSPC X'0000007D' X'00000004' &WRKBIN4) CHGVAR &WRKDEC8 %BINARY(&WRKBIN4) CHGVAR VAR(&WRKDEC8) VALUE(&WRKDEC8 + 1) /* Loop for each job found */ STEP01A: IF (&LOOP = 0) THEN(GOTO STEP01) /* Convert decimal position to binary 4 and retrieve list job entry */ CHGVAR %BINARY(&WRKBIN4) &WRKDEC8 CALL QUSRTVUS (&JOBUSRSPC &WRKBIN4 &ENTRYLENB4 &JOBLSTENT) /* The job information is held in the &JOBLSTENT field */ /* Since this is just a proof of concept, I'm not doing anything with the */ /* captured information, but the possibilities are endless. */ /* Point to next entry, decrement loop counter, and loop */ CHGVAR VAR(&WRKDEC8) VALUE(&WRKDEC8 + &ENTRYLEN) CHGVAR VAR(&LOOP) VALUE(&LOOP - 1) GOTO CMDLBL(STEP01A) /* Next Step */ STEP02: /* Clean up and exit */ STEP99: DLTUSRSPC USRSPC(QTEMP/&CMDUSRSPC) MONMSG CPF0000 ENDPGM