Here is a useful utility I wrote to have the system let me know when a file is not being used by anyone. It comes in handy when you have to replace a physical or logical file that's in production with the one that's been in testing. Since recompiling the file entails actually deleting the existing one, this cannot be done while someone is using it.
The Work With Object Locks (WRKOBJLCK) command will tell you who is using the file. My utility, Wait for File (WAITF), will run in the background and check every 30 seconds for you. WAITF will notify you with a break message when the file is available.
The utility ensures that the object exists and, if it does, attempts to allocate the object with a lock of *EXCL. Using the Monitor Message (MONMSG) command to determine if the allocation was successful or not is the key to how this utility works. (1 contains the WAITF command source code and 2 contains the source code for the CPP, F003CL.)
The utility ensures that the object exists and, if it does, attempts to allocate the object with a lock of *EXCL. Using the Monitor Message (MONMSG) command to determine if the allocation was successful or not is the key to how this utility works. (Figure 1 contains the WAITF command source code and Figure 2 contains the source code for the CPP, F003CL.)
If the allocation is successful, a break message is sent to the message queue from which the job was submitted. It is important to deallocate any object allocated. I do so as part of the utility, although you may wish to deallocate the object from the command line after you are done replacing or reorganizing the object.
- Andrew Longo
Accessory to WRKOBJLCK
Figure 1 The WAITF Command Source
/*==================================================================*/ /* To compile: */ /* */ /* CRTCMD CMD(XXX/WAITF) PGM(XXX/F003CL) + */ /* SRCFILE(XXX/QCMDSRC) */ /* */ /*==================================================================*/ WAITF: CMD PROMPT('Wait for File') PARM KWD(FILE) TYPE(QUAL) PROMPT('File') QUAL: QUAL TYPE(*NAME) LEN(10) MIN(1) QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) + SPCVAL((*LIBL)) PROMPT('Library')
Accessory to WRKOBJLCK
Figure 2 CPP F003CL
/*==================================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/F003CL) SRCFILE(XXX/QCLSRC) */ /* */ /*==================================================================*/ F003CL: PGM PARM(&QUALFILE) DCL VAR(&QUALFILE) TYPE(*CHAR) LEN(20) DCL VAR(&FILE) TYPE(*CHAR) LEN(10) DCL VAR(&LIB) TYPE(*CHAR) LEN(10) DCL VAR(&TYPE) TYPE(*CHAR) LEN(1) DCL VAR(&MSGQ) TYPE(*CHAR) LEN(10) DCL VAR(&MSGQLIB) TYPE(*CHAR) LEN(10) DCL VAR(&MSG) TYPE(*CHAR) LEN(40) RTVJOBA JOB(&MSGQ) TYPE(&TYPE) IF (&TYPE *EQ '1') THEN(DO) SBMJOB CMD(CALL PGM(F003CL) PARM(&QUALFILE)) + MSGQ(&MSGQ) GOTO CMDLBL(ENDPGM) ENDDO RTVJOBA SBMMSGQ(&MSGQ) SBMMSGQLIB(&MSGQLIB) CHGVAR VAR(&FILE) VALUE(%SST(&QUALFILE 1 10)) CHGVAR VAR(&LIB) VALUE(%SST(&QUALFILE 11 10)) CHKOBJ OBJ(&LIB/&FILE) OBJTYPE(*FILE) MONMSG MSGID(CPF9801) EXEC(DO) CHGVAR VAR(&MSG) VALUE('File' *BCAT &LIB *TCAT + '/' *CAT &FILE *BCAT 'was not found.') SNDBRKMSG MSG(&MSG) TOMSGQ(&MSGQLIB/&MSGQ) GOTO CMDLBL(ENDPGM) ENDDO TOP: ALCOBJ OBJ((&LIB/&FILE *FILE *EXCL)) WAIT(0) MONMSG MSGID(CPF1085 CPF1002) EXEC(DO) DLYJOB DLY(30) GOTO CMDLBL(TOP) ENDDO DLCOBJ OBJ((&LIB/&FILE *FILE *EXCL)) CHGVAR VAR(&MSG) VALUE('File' *BCAT &LIB *TCAT '/' + *CAT &FILE *BCAT 'is now available.') SNDBRKMSG MSG(&MSG) TOMSGQ(&MSGQLIB/&MSGQ) ENDPGM: ENDPGM
LATEST COMMENTS
MC Press Online