DELETE

DELETE, DELETEU

Top  Previous  Next

 

The DELETE statement deletes a record from an open file. The DELETEU statement is similar but it preserves locks.

 

 

Format

 

DELETE file.var, record.id {ON ERROR statement(s)}

DELETEU file.var, record.id {ON ERROR statement(s)}

 

where

 

file.varis a file variable for an open file.

 

record.idevaluates to the id of the record to be deleted.

 

statement(s)are statements to be executed if the delete fails.

 

 

The specified record is deleted from the file. No error occurs if the record does not exist.

 

If the process performing the DELETE had a read or update lock on the record, the lock is released. The DELETEU statement preserves any lock. Within a transaction, the lock is retained until the transaction terminates and then released regardless of which statement is used. Attempting to delete a record in a transaction will fail if the process does not hold an update lock on the record or the file.

 

The ON ERROR clause is executed for serious fault conditions such as errors in a file's internal control structures. It is also executed if the delete operation is disallowed by a pre-delete trigger function associated with the file. The STATUS() function will return an error number. If no ON ERROR clause is present, an abort would occur.

 

 

Use of a THEN/ELSE Clause

 

For compatibility with the way in which triggers operate in some other multivalue products, the DELETE statement has an optional THEN/ELSE clause. Because this would otherwise lead to a syntactic ambiguity, compilation of programs that use this clause requires the WRITE.DELETE.THEN.ELSE option of the $MODE compiler directive to be enabled. Once this is done, the optional THEN/ELSE clauses can be included in their usual position, after the ON ERROR clause.

 

When a DELETE statement has a THEN/ELSE clause, a failure returned from a trigger function, typically as a result of a pre-delete data validation error, will cause the ELSE clause to be executed instead of the ON ERROR clause.

 

Example

 

DELETE STOCK, ITEM.ID

 

This statement deletes the record whose id is in ITEM.ID from the file associated with file variable STOCK.