DELETE FILE


The CICS DELETE FILE statement is used to permanently remove a record from a VSAM dataset or a CICS-maintained file. Delete a record from a file - VSAM KSDS and VSAM RRDS only.

The DELETE command deletes a record from a file on a KSDS or a path over a KSDS or an RRDS. Record can't be deleted from a VSAM ESDS or a BDAM file. The file can be on a local or a remote system.

Key Features -

  • Deletes a record from a VSAM dataset (KSDS, RRDS, or an alternate index).
  • Requires a unique key to locate the record before deletion (KSDS files).

Syntax -

EXEC CICS DELETE
     FILE('file-name')
	 [TOKEN(data-area)]
     [RIDFLD(record-id)]
     [KEYLENGTH(key-length)]
	 [GENERIC]
	 [NUMREC(data-value)]
	 [SYSID(system-name)]
	 [RBA|RRN]
     [RESP(response-field)]
     [RESP2(response-field2)]
     END-EXEC.
  • FILE('file-name') - Specifies the name of the VSAM file or dataset from which the record is to be deleted.
  • RIDFLD(record-id) - Specifies the record identification field, which can contain a key, a relative record number (for VSAM data sets), a block reference, a physical key, or a deblocking argument (for BDAM data sets).
  • KEYLENGTH(key-length) - Defines the key length. KEYLENGTH is not valid when RRN is coded. KEYLENGTH must be coded if using SYSID.
  • GENERIC - Specifies the search key is a generic key with a length specified in the KEYLENGTH option. Group of records can be deleted by using the GENERIC option with generic key and the option is available to KSDS only.
  • NUMREC(data-value) - Specifies that CICS sets to the number of deleted records.
  • SYSID(system-name) - Specifies the system name to which the request is directed. If SYSID coded and omit RBA, XRBA and RRN, LENGTH and KEYLENGTH must be coded.
  • RBA|RRN|XRBA - Specifies the type of the file and data in the RIDFLD.
  • RESP(response-variable) - Optional. It captures the response code of the DELETE operation and used to check if the command executed successfully or encountered an error.
  • RESP2(response2-variable) - Optional. It captures the response2 code of the DELETE operation when the error occured.

Short Examples -


Scenario - Deleting a Record by Key in a KSDS File.

...
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-CUSTOMER-RECORD.
   05 WS-CUST-ID        PIC X(10).
   05 WS-CUST-NAME      PIC X(30).
   05 WS-CUST-ADDRESS   PIC X(50).
   05 WS-CUST-PHONE     PIC X(15).
   
...
PROCEDURE DIVISION.

    MOVE "12345" TO WS-CUST-ID.

    EXEC CICS DELETE
         FILE('CUSTFILE')
         RIDFLD(WS-CUST-ID)
         RESP(WS-RESP)
         END-EXEC.

    IF WS-RESP NOT = THEN
       ...
	END-IF.
	
    ...

The record key (WS-CUST-ID) is provided in the RIDFLD parameter. The DELETE command attempts to remove the record from the CUSTOMER-FILE dataset.

Error Conditions -


Eror Condition RESP RESP2 Reason
FILENOTFOUND 12 1 A file name in the FILE option is not defined to CICS.
NOTFND 13 80 An attempt to delete a record based on the search argument provided is unsuccessful.
DUPKEY 15 140 A record is accessed by way of an alternate index with the NONUNIQUEKEY attribute and another alternate index record with the same key follows.
INVREQ 16 20 Delete operations are not allowed according to the resource definition.
16 21 Command is issued for a file referring to a VSAM ESDS.
16 22 A GENERIC DELETE is issued for a file that is not a VSAM KSDS.
16 25 The KEYLENGTH and GENERIC options specified and the length value in the KEYLENGTH option is greater than or equal to the length of a full key.
16 26 The KEYLENGTH option is specified and the length does not equal the length defined for the data set.
16 27 Command is issued for a file referring to a BDAM data set.
16 31 Command without the RIDFLD option is issued for a file where no previous READ UPDATE command has been issued.
16 42 The KEYLENGTH and GENERIC options are specified, and the length in the KEYLENGTH option is less than zero.
16 47 Command includes a token whose value can’t be matched against any token in use for an existing READ with UPDATE request.
16 51 Command specifying the RBA or XRBA keyword is issued against a KSDS file that is being accessed in RLS mode.
16 55 NOSUSPEND is specified for a non-RLS file.
16 59 XRBA was specified, but the data set is not an extended ESDS.
IOERR 17 120 There is an I/O error during the file control operation.
NOTOPEN 19 60 Below are the reasons for NOTOPEN
  • The requested file is CLOSED and UNENABLED.
  • The requested file is OPEN and in use by other transactions, but a CLOSE request against the file has been received.
  • The requested file is CLOSED and ENABLED, so CICS has tried to open the file as part of executing the request.
ILLOGIC 21 110 VSAM error occurs that is not in one of the other CICS response categories.
SYSIDERR 53 130 The SYSID name specified is neither the local region nor a remote system or the link to the remote system is closed.
ISCINVREQ 54 70 The remote system indicates a failure that does not correspond to a known condition.
NOTAUTH 70 101 A resource security check has failed on FILE (filename).
DISABLED 84 50 A file is disabled.
Note! This condition cannot occur when the DELETE command follows any read with the UPDATE option.
LOCKED 100 An attempt has been made to delete a record, but lock exists against the key. AEX8.
RECORDBUSY 101 107 The NOSUSPEND keyword is specified for the deletion of a record that is locked by a VSAM active lock. AEX9