Progress0 of 0 lessons

CICS UNLOCK - Record Unlocking

CICS UNLOCK provides record unlocking capabilities in CICS environments. It enables programs to unlock records, manage file operations, and handle record unlocking for proper resource management and concurrent access control.

Command Syntax

cobol
1
2
3
4
5
6
7
EXEC CICS UNLOCK [FILE(file-name)] [RIDFLD(record-id)] [KEYLENGTH(key-length)] [RESP(response-code)] [RESP2(response-code-2)] END-EXEC.

Parameters

FILE(file-name)

Specifies the name of the file from which the record will be unlocked. This parameter identifies the target file for unlock operations.

RIDFLD(record-id)

Specifies the record identifier field containing the key of the record to be unlocked. This parameter identifies the specific record for unlocking.

KEYLENGTH(key-length)

Specifies the length of the key field used to identify the record. This parameter controls the key matching for record identification.

RESP(response-code)

Specifies the response code variable to receive the operation result. This parameter provides error handling and status information.

RESP2(response-code-2)

Specifies the secondary response code variable for additional error information. This parameter provides extended error details when available.

Unlocking Types

Explicit Unlocking

UNLOCK explicitly releases record locks, enabling programs to free locked records for access by other programs and transactions.

Current Record Unlocking

The command supports current record unlocking for releasing locks on records currently positioned by browse operations.

Conditional Unlocking

Conditional unlocking enables record lock release based on specific business rules and data conditions for flexible resource management.

Resource Management

Resource management ensures proper lock release and prevents deadlocks and resource contention in multi-program environments.

Programming Examples

Basic Record Unlocking

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
WORKING-STORAGE SECTION. 01 FILE-NAME PIC X(8) VALUE 'CUSTOMER'. 01 RECORD-KEY PIC X(10) VALUE 'CUST001'. 01 KEY-LENGTH PIC S9(8) COMP VALUE 10. 01 RESPONSE-CODE PIC S9(8) COMP. 01 RESPONSE-CODE-2 PIC S9(8) COMP. PROCEDURE DIVISION. EXEC CICS UNLOCK FILE(FILE-NAME) RIDFLD(RECORD-KEY) KEYLENGTH(KEY-LENGTH) RESP(RESPONSE-CODE) RESP2(RESPONSE-CODE-2) END-EXEC IF RESPONSE-CODE = 0 DISPLAY 'Record unlocked successfully' DISPLAY 'File: ' FILE-NAME DISPLAY 'Key: ' RECORD-KEY ELSE DISPLAY 'Error unlocking record: ' RESPONSE-CODE END-IF.

Multiple Record Unlocking

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
WORKING-STORAGE SECTION. 01 FILE-NAME PIC X(8) VALUE 'CUSTOMER'. 01 RECORD-KEY PIC X(10). 01 KEY-LENGTH PIC S9(8) COMP VALUE 10. 01 RESPONSE-CODE PIC S9(8) COMP. 01 RESPONSE-CODE-2 PIC S9(8) COMP. 01 UNLOCK-COUNT PIC S9(8) COMP VALUE 0. PROCEDURE DIVISION. PERFORM UNLOCK-CUSTOMER-001 PERFORM UNLOCK-CUSTOMER-002 PERFORM UNLOCK-CUSTOMER-003. UNLOCK-CUSTOMER-001. MOVE 'CUST001' TO RECORD-KEY EXEC CICS UNLOCK FILE(FILE-NAME) RIDFLD(RECORD-KEY) KEYLENGTH(KEY-LENGTH) RESP(RESPONSE-CODE) RESP2(RESPONSE-CODE-2) END-EXEC IF RESPONSE-CODE = 0 ADD 1 TO UNLOCK-COUNT DISPLAY 'Customer 001 unlocked' END-IF. UNLOCK-CUSTOMER-002. MOVE 'CUST002' TO RECORD-KEY EXEC CICS UNLOCK FILE(FILE-NAME) RIDFLD(RECORD-KEY) KEYLENGTH(KEY-LENGTH) RESP(RESPONSE-CODE) RESP2(RESPONSE-CODE-2) END-EXEC IF RESPONSE-CODE = 0 ADD 1 TO UNLOCK-COUNT DISPLAY 'Customer 002 unlocked' END-IF. UNLOCK-CUSTOMER-003. MOVE 'CUST003' TO RECORD-KEY EXEC CICS UNLOCK FILE(FILE-NAME) RIDFLD(RECORD-KEY) KEYLENGTH(KEY-LENGTH) RESP(RESPONSE-CODE) RESP2(RESPONSE-CODE-2) END-EXEC IF RESPONSE-CODE = 0 ADD 1 TO UNLOCK-COUNT DISPLAY 'Customer 003 unlocked' END-IF.

Dynamic Record Unlocking

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
WORKING-STORAGE SECTION. 01 FILE-NAME PIC X(8) VALUE 'CUSTOMER'. 01 RECORD-KEY PIC X(10). 01 KEY-LENGTH PIC S9(8) COMP VALUE 10. 01 RESPONSE-CODE PIC S9(8) COMP. 01 RESPONSE-CODE-2 PIC S9(8) COMP. 01 PROCESSING-COUNT PIC S9(8) COMP VALUE 0. PROCEDURE DIVISION. PERFORM VARYING PROCESSING-COUNT FROM 1 BY 1 UNTIL PROCESSING-COUNT > 5 PERFORM BUILD-RECORD-KEY PERFORM UNLOCK-RECORD END-PERFORM. BUILD-RECORD-KEY. STRING 'CUST' DELIMITED BY SIZE PROCESSING-COUNT DELIMITED BY SIZE INTO RECORD-KEY. UNLOCK-RECORD. EXEC CICS UNLOCK FILE(FILE-NAME) RIDFLD(RECORD-KEY) KEYLENGTH(KEY-LENGTH) RESP(RESPONSE-CODE) RESP2(RESPONSE-CODE-2) END-EXEC IF RESPONSE-CODE = 0 DISPLAY 'Record ' RECORD-KEY ' unlocked successfully' ELSE DISPLAY 'Error unlocking record ' RECORD-KEY ': ' RESPONSE-CODE END-IF.

Error Handling

Response Code 0

Successful record unlocking. The record has been successfully unlocked and is available for access by other programs.

Response Code 8

Invalid file name. The specified file name is invalid or not supported.

Response Code 12

Record not locked. The specified record is not currently locked by this program.

Response Code 16

Invalid key length. The specified key length is invalid or incompatible with the file structure.

Response Code 20

Unlock operation failed. The record unlocking operation failed due to system conditions.

Performance Considerations

Lock Management

UNLOCK efficiently manages record locks, but delayed unlocking may impact system performance and concurrent access.

Resource Management

Proper resource management ensures efficient lock operations and prevents deadlocks and resource contention issues.

Concurrent Access

Concurrent access optimization ensures proper lock release and maximizes system throughput in multi-program environments.

Best Practices

Error Handling

Always check response codes and handle errors appropriately, especially for lock validation and record existence.

Lock Management

Implement proper lock management by ensuring records are unlocked promptly to prevent deadlocks and improve system performance.

Resource Cleanup

Ensure proper resource cleanup by unlocking all records before program termination to prevent resource leaks.

Concurrent Access

Optimize concurrent access by implementing appropriate locking strategies and ensuring timely lock release.

Explain It Like I's 5 Years Old

Imagine you have a toy that you were playing with and you put a lock on it so no one else could play with it. CICS UNLOCK is like taking the lock off the toy so other kids can play with it too.

The file name is like the name of the toy box, and the record key is like the name of the specific toy you want to unlock. When you unlock it, other programs can use that toy.

Just like you need to unlock toys when you're done playing with them so other kids can use them, the program needs to unlock records when it's done with them so other programs can use them.

Exercises

Exercise 1: Basic Record Unlocking

Write a program that uses UNLOCK to release a record lock and verify the unlocking was successful.

Exercise 2: Multiple Record Management

Create a program that manages multiple record locks and unlocks them appropriately.

Exercise 3: Resource Cleanup

Implement a resource management system that ensures all records are properly unlocked before program termination.