DELETE command is used to delete a record that is present in a file. Prior to this command, the record must be read with a READ UPDATE command. The parameters are same as described before. The syntax of Delete command is as follows −
EXEC CICS DELETE FILE('name') END-EXEC.
Following is the syntax to delete a record directly without reading it with Update option −
EXEC CICS DELETE FILE('name') RIDFLD(data-value) END-EXEC.
Following is the example for Group Delete. This can be done using Generic option, where all the records that satisfy the generic criteria will be deleted. NUMREC will hold the number of records deleted. The field mentioned here should be a S9(4) comp.
IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-STD-REC-LEN PIC S9(4) COMP. 01 WS-STD-KEY-LEN PIC S9(4) COMP. 01 WS-STD-REC-KEY PIC 9(3). 01 WS-STD-REC PIC X(70). 01 WS-NUM-REC-DEL PIC S9(4). PROCEDURE DIVISION. MOVE '11' TO WS-STD-REC-KEY. MOVE 2 TO WS-STD-KEY-LEN. EXEC CICS READ FILE ('FL001') RIDFLD (WS-STD-REC-KEY) KEYLENGTH (WS-STD-KEY-LEN) GENERIC NUMREC (WS-NUM-REC-DEL) END-EXEC.
The following table shows the list of exceptions that arise during a DELETE statement −
|Sr.No||Exception & Description|
File is not open.
Record that is being searched doesn't exist in the dataset (DELETE with RIDFLD).
If the user does not have enough permissions to use the file.
Rewrite without prior READ with UPDATE.
File entry is not made in FCT.