Q: An RPG application that I am working on must be able to capture a locked record and display the name of the user who has the record. The File Information Data Structure doesn't contain this information, and I would appreciate help with writing a CL routine to determine which user has the record locked.
- Michael Gordon Pilot Information Systems This email address is being protected from spambots. You need JavaScript enabled to view it. A: You can get that information from your RPG program by using the Program Status Data Structure (PSDS). When a record lock occurs, the text for the error message is in positions 91 through 170 of the PSDS. The full job name of the user who has the record locked is embedded within the message text. You can easily substring out the user name from the message.
The RPG program must have an error indicator in the "Lo" position of the input calculation. The error text will read something like "Record 5 in use by job 047237/SOMEUSER/QPADEV0010." Sample code is in Figure 1.
- Mark McCall This email address is being protected from spambots. You need JavaScript enabled to view it. A: In our shop, we integrate a utility to handle locked records into our interactive programs. Figures 2 and 3 show CL program SHWLCKCL and the source code for display file SHWLCKDF. When an I/O error occurs in an RPG program, as in Figure 4, we call SHWLCKCL. The user is presented with a display identifying who has the lock on the record and asking him to wait until the lock is released.
- Richard Clark
This email address is being protected from spambots. You need JavaScript enabled to view it.
Figure 1: Who locked the record?
FCUSTMAS UF E K DISK
FQSYSPRT O F 132 OF PRINTER UC
ISDS
I 91 170 ERRMSG
...
C* HiLoEq
C CUSNO CHAINCUSTMASR 9110
C *IN10 IFEQ *ON
C OPEN QSYSPRT
C EXCPTERRLN
C ELSE
... (record was not locked)
C ENDIF
CSETONLR
OQSYSPRT E 1 ERRLN
O + 1 'ERROR'
O ERRMSG + 1 /*==================================================================*/
/* Display the name of the job holding a record lock. */
/*==================================================================*/
/* To compile: */
/* */
/* CRTCLPGM PGM(XXX/SHWLCKCL) SRCFILE(XXX/QCLSRC) */
/* */
/*==================================================================*/
PGM
DCL VAR(&MSGTXT) TYPE(*CHAR) LEN(75)
DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)
DCLF FILE(SHWLCKDF)
RCVMSG PGMQ(*PRV) MSGTYPE(*LAST) RMV(*KEEPEXCP) +
MSG(&MSGTXT) MSGID(&MSGID)
IF COND(&MSGID *EQ CPF5027) THEN(DO)
SNDF RCDFMT(SCN1)
DLYJOB DLY(20)
ENDDO
ELSE CMD(DO)
LOOP: SNDRCVF RCDFMT(SCN2)
IF COND(&IN24 *EQ '0') THEN(GOTO CMDLBL(LOOP))
ENDDO
ENDPGM *===============================================================
* Display the name of the job holding a record lock.
*===============================================================
* To compile:
*
* CRTDSPF FILE(XXX/SHWLCKDF) SRCFILE(XXX/QDDSSRC)
*
*===============================================================
A R SCN1 FRCDTA LOCK
A 1 25'UNABLE TO ALLOCATE RECORD'
A COLOR(WHT)
A 3 2'CAUTION: Please'
A DSPATR(BL)
A +1'do not press any keys.'
A DSPATR(BL)
A +2'Thank you.'
A DSPATR(BL)
A 8 2'The patient record you'
A COLOR(YLW)
A +1'requested is currently'
Figure 2: CL program SHWLCKCL
Figure 3: Display file SHWLCKDF
A COLOR(YLW)
A +1'being used by:'
A COLOR(YLW)
A MSGTXT 75 9 2
A COLOR(RED)
A 11 2'Please contact the above'
A COLOR(TRQ)
A +1'user asking them to'
A COLOR(TRQ)
A +1'return to their main'
A COLOR(TRQ)
A +1'menu.'
A COLOR(TRQ)
A 12 2'The computer will'
A COLOR(TRQ)
A +1'automatically retry'
A COLOR(TRQ)
A +1'if you continue to'
A COLOR(TRQ)
A +1'receive this message'
A COLOR(TRQ)
A 13 2'ask the above user to'
A COLOR(TRQ)
A +1'SIGNOFF.'
A COLOR(TRQ)
A 18 2'CAUTION: Please'
A DSPATR(BL)
A +1'do not press any keys.'
A DSPATR(BL)
A +2'Thank you.'
A DSPATR(BL)
A 22 2'1'This screen will stay'
A COLOR(PNK)
A +1'active for 20 seconds.'
A COLOR(PNK)
A R SCN2 FRCDTA CF24(24)
A*CF24 will not be shown to the user. You can use CF24 to try
A*chain or read again.
A 1 25'DATA BASE RETRIEVAL ERROR'
A COLOR(WHT)
A 10 7'Could not retrieve the'
A DSPATR(BL)
A +1'data record.'
A DSPATR(BL)
A +1'Please call Data'
A COLOR(YLW)
A +1'Processing.'
A COLOR(YLW)
C CUSNO CHAINCUSTMAS 9998
C *IN98 IFEQ *ON
C CALL 'SHWLCKCL'
CELSE
LATEST COMMENTS
MC Press Online