Progress0 of 0 lessons

CICS DELETE - Record Deletion

CICS DELETE provides record deletion capabilities in CICS environments. It enables programs to delete records, manage file operations, and handle record deletion for data management and maintenance purposes.

Command Syntax

cobol
1
2
3
4
5
6
7
EXEC CICS DELETE [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 deleted. This parameter identifies the target file for deletion operations.

RIDFLD(record-id)

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

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.

Deletion Types

Key-Based Deletion

DELETE removes records based on key values, enabling programs to delete specific records identified by their primary or alternate keys.

Current Record Deletion

The command supports current record deletion for removing the record currently positioned by a browse operation.

Conditional Deletion

Conditional deletion enables record removal based on specific business rules and data conditions for automated cleanup.

Batch Deletion

Batch deletion supports removal of multiple records efficiently in maintenance procedures and data cleanup operations.

Programming Examples

Basic Record Deletion

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 DELETE FILE(FILE-NAME) RIDFLD(RECORD-KEY) KEYLENGTH(KEY-LENGTH) RESP(RESPONSE-CODE) RESP2(RESPONSE-CODE-2) END-EXEC IF RESPONSE-CODE = 0 DISPLAY 'Record deleted successfully' DISPLAY 'File: ' FILE-NAME DISPLAY 'Key: ' RECORD-KEY ELSE DISPLAY 'Error deleting record: ' RESPONSE-CODE END-IF.

Multiple Record Deletion

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 DELETE-COUNT PIC S9(8) COMP VALUE 0. PROCEDURE DIVISION. PERFORM DELETE-CUSTOMER-001 PERFORM DELETE-CUSTOMER-002 PERFORM DELETE-CUSTOMER-003. DELETE-CUSTOMER-001. MOVE 'CUST001' TO RECORD-KEY EXEC CICS DELETE 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 DELETE-COUNT DISPLAY 'Customer 001 deleted' END-IF. DELETE-CUSTOMER-002. MOVE 'CUST002' TO RECORD-KEY EXEC CICS DELETE 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 DELETE-COUNT DISPLAY 'Customer 002 deleted' END-IF. DELETE-CUSTOMER-003. MOVE 'CUST003' TO RECORD-KEY EXEC CICS DELETE 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 DELETE-COUNT DISPLAY 'Customer 003 deleted' END-IF.

Dynamic Record Deletion

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 DELETE-RECORD END-PERFORM. BUILD-RECORD-KEY. STRING 'CUST' DELIMITED BY SIZE PROCESSING-COUNT DELIMITED BY SIZE INTO RECORD-KEY. DELETE-RECORD. EXEC CICS DELETE 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 ' deleted successfully' ELSE DISPLAY 'Error deleting record ' RECORD-KEY ': ' RESPONSE-CODE END-IF.

Error Handling

Response Code 0

Successful record deletion. The record has been successfully deleted from the file.

Response Code 8

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

Response Code 12

Record not found. The specified record does not exist in the file.

Response Code 16

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

Response Code 20

Deletion failed. The record deletion operation failed due to system conditions.

Performance Considerations

Deletion Efficiency

DELETE efficiently removes records, but large deletion operations may impact system performance temporarily.

File Management

Proper file management ensures efficient deletion operations and prevents file corruption and resource issues.

Key Validation

Key validation ensures that deletion operations target the correct records and maintain data integrity.

Best Practices

Error Handling

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

Record Validation

Validate record keys before deletion to ensure that the correct records are targeted for removal.

Deletion Confirmation

Implement proper deletion confirmation mechanisms to prevent accidental deletion of important records.

Data Integrity

Ensure data integrity by implementing proper deletion strategies and maintaining referential integrity.

Explain It Like I's 5 Years Old

Imagine you have a box of cards with names on them, and you want to throw away a specific card. CICS DELETE is like finding the card with the name you want and throwing it away.

The file name is like the name of your box of cards, and the record key is like the name on the card you want to throw away. When you delete it, the card is gone forever.

Just like you need to make sure you're throwing away the right card, the program needs to make sure it's deleting the right record.

Exercises

Exercise 1: Basic Record Deletion

Write a program that uses DELETE to remove a record with a specific key and verify the deletion was successful.

Exercise 2: Multiple Record Cleanup

Create a program that deletes multiple records based on specific criteria such as status or date.

Exercise 3: Conditional Deletion Logic

Implement a record deletion system that only deletes records when specific business conditions are met.