# 12.3 DELETE Statement

The DELETE statement deletes a record from a relative or indexed organization file. It takes one of the following forms:

  Keyed Access:
  DELETE ([UNIT=]io-unit [, ERR=label] [, IOSTAT=i-var])
  Direct Access:
  DELETE ([UNIT=]io-unit [, REC=r] [, ERR=label] [, IOSTAT=i-var])
  io-unit
  Is an external unit specifier.
  r
  Is a scalar numeric expression indicating the record number to be deleted.
  label
  Is the label of the branch target statement that receives control if an error occurs.
  i-var
  Is a scalar integer variable that is defined as a positive integer if an error occurs and zero if no error occurs.

Rules and Behavior

In files with keyed access, the DELETE statement deletes the current record. The current record is the last record that is accessed by a READ statement on the specified external unit.

In files with direct access, the DELETE statement deletes the direct access record specified by r. If REC=r is omitted, the current record is deleted. When the direct access record is deleted, any associated variable is set to the next record number.

The DELETE statement logically removes the appropriate record from the specified file by locating the record and marking it as a deleted record. It then frees the position formerly occupied by the deleted record so that a new record can be written into that position.

Examples

The following statement deletes the fifth record in the file connected to I/O unit 10:

      DELETE (10, REC=5)

In the next example, the current record is deleted from the file connected to I/O unit 11:

      DELETE (11)

For More Information:

- On an alternative form for the DELETE statement, see Section B.9.
- On the UNIT control specifier, see Section 10.2.1.1.
- On the ERR control specifier, see Section 10.2.1.8.
- On the IOSTAT control specifier, see Section 10.2.1.7.
- On the REC control specifier, see Section 10.2.1.4.

Previous Page Next Page Table of Contents