TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

CICS DELETE Command


The DELETE command is used to delete(s) a record from a VSAM file - KSDS and RRDS.

Syntax:

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.

  1. Issued after a READ command with the UPDATE option to delete the record that is read.

    Syntax:

    EXEC CICS DELETE
       FILE('filename')
    END-EXEC.
  2. 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.

    Syntax:

    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.

  • RIDFLD(data-area)

    Specifies the record identification field.

    It has the name of the data area containing the key of the record which we want to delete.

  • KEYLENGTH(data-value)

    Specifies the length (halfword binary) of the key that has been specified in the RIDFLD option


Example:

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.

Description:

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).


Delete Command Exception Conditions:


ExceptionDescription
DISABLEDA file is disabled
NOTOPENFile is not open.
NOTAUTHA resource security check has failed on FILE(filename).(i.e. User does not have enough permissions to access the file).
FILENOTFOUNDFile name is not available in FCT.
INVREQDelete 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!

Are you looking for Job Change? Job Portal