The DELETE command is used to delete(s) a record from a VSAM file - KSDS and RRDS.
Below is the syntax for DELETE command.
EXEC CICS DELETE FILE('filename') RIDFLD(data-area) [RBA|RRN] KEYLENGTH(data-value) [GENERIC|NUMERIC(rec-number)] END-EXEC. |
Records from VSAM KSDS and RRDS files can be deleted, but not from VSAM ESDS files.
The NUMREC option will return the number of records deleted on a GENERIC delete.
KEYLENGTH must be specified for a GENERIC delete.
The DELETE command may be issued to delete record(s) from a data set in two ways.
Issued after a READ command with the UPDATE option to delete the record that is read.
EXEC CICS DELETE FILE('filename') END-EXEC. |
Issued with the RIDFLD option when there is no prior READ with UPDATE option. This will delete the record whose key matches with the RIDFLD.
EXEC CICS DELETE FILE('filename') RIDFLD(data-area) KEYLENGTH(data-value) END-EXEC. |
Let us see the parameters used in the DELETE command.
FILE(filename)
Specifies the name of the file to be accessed.
Specifies the record identification field.
It has the name of the data area containing the key of the record which we want to delete.
Specifies the length (halfword binary) of the key that has been specified in the RIDFLD option
Let us see an example of CICS program for DELETE command.
IDENTIFICATION DIVISION. PROGRAM-ID. IBMMF. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-REC-LEN PIC S9(4) COMP. 01 WS-KEY-LEN PIC S9(4) COMP. 01 WS-REC-KEY PIC 9(6). 01 WS-REC-DATA PIC X(80). 01 WS-DEL-REC PIC S9(4). PROCEDURE DIVISION. MOVE '502258' TO WS-REC-KEY. MOVE 6 TO WS-KEY-LEN. EXEC CICS DELETE FILE('STDLST') RIDFLD(WS-REC-KEY) KEYLENGTH(WS-KEY-LEN) GENERIC NUMREC(WS-DEL-REC) END-EXEC. |
This example to delete more than 1 record. This can be done using Generic option in Delete command, 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 halfword binary(S9(4) comp).
Exception | Description |
---|---|
DISABLED | A file is disabled |
NOTOPEN | File is not open. |
NOTAUTH | A resource security check has failed on FILE(filename).(i.e. User does not have enough permissions to access the file). |
FILENOTFOUND | File name is not available in FCT. |
INVREQ | Delete command executed without prior READ command with UPDATE option. |
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!