LOCKMSG Tool for COBOL

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

The LOCKMSG tool from the QUSRTOOL library offers programmers a very useful and consistent method for handling record locks. LOCKMSG can sense a locked record condition and then send a message to the workstation operator describing the problem. What really makes the tool effective is that it allows the user to respond to the locked condition three different ways.

o "R" to retry the read operation. o "J" to send a message to the job that holds the lock and request the operator to release the transaction. o "S" to send a message to the system operator describing the problem.

The documentation for the tool describes a technique for using the LOCKMSG in RPG. Unfortunately for COBOL programmers, it doesn't describe how to use the tool in COBOL. In fact, it states "The same technique cannot be used in COBOL."

I was convinced that it could be made to work with COBOL. As a result, I simulated the same technique in COBOL with a few lines of code and one CL program. Operationally, it functions exactly the same way as it does in RPG.

Here's how it can be done.

Create CL program GETPGMMSG, shown in 3.

Create CL program GETPGMMSG, shown in Figure 3.

Simulate the RPG data structure in COBOL that is passed to TAADBFFC (see 4).

Simulate the RPG data structure in COBOL that is passed to TAADBFFC (see Figure 4).

The loop in 5 is performed once and repeated if the file status is equal to "9D" (record locked).

The loop in Figure 5 is performed once and repeated if the file status is equal to "9D" (record locked).

The system sends a CPF5027 message to the COBOL program on a locked-record timeout condition. A call to GETPGMMSG retrieves the text for the message and places it in position 91 of the WS-STATUS area. The error status value can be hard-coded to simulate the RPG error status equivalent because COBOL can monitor directly for a locked-record condition.

The QUSRTOOL CL program, TAADBFFC, receives the working storage area (data structure) as a parameter. It checks to ensure that the specific error status is 01218, which indicates a locked record.

The tool will not fail when called from COBOL, but it may fail in RPG if the error status in the program status data structure is not 01218.


LOCKMSG Tool for COBOL

Figure 3 CL Program GETPGMMSG

 PGM PARM(&MSGTXT) DCL VAR(&MSGTXT) TYPE(*CHAR) LEN(80) RCVMSG PGMQ(*PRV) MSGTYPE(*LAST) MSG(&MSGTXT) ENDPGM 
LOCKMSG Tool for COBOL

Figure 4 WS-STATUS Data Structure

 ..... *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 01 WS-STATUS. 05 FILLER PIC X(90). 05 MSG-TXT PIC X(80). 05 FILLER PIC X(38). 05 STATUS-CODE PIC X(05) VALUE "01218". 05 FILLER PIC X(120). 
LOCKMSG Tool for COBOL

Figure 5 Checking for Record Lock

 ..... *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 PERFORM WITH TEST AFTER UNTIL FILE-STATUS NOT EQUAL "9D" READ PDMOPT IF FILE-STATUS = "9D" CALL "GETPGMMSG" USING MSG-TXT CALL "TAADBFFC" USING WS-STATUS END-IF END-PERFORM. 
BLOG COMMENTS POWERED BY DISQUS