DELETE Statement

Deletes a file item.

Syntax

DELETE {file-var,}item-id {SETTING setting-var} {ON ERROR statement(s)}

Syntax Elements

item-id is the name of the item to be deleted.

The item-id can be the item-id in quotes, a numerical value, or the name of a variable that evaluates to the item-id.

file-var is the name of a variable containing a file reference (assigned via an OPEN statement). If file-var is not specified, the internal default file variable is used; that is, the file used is that most recently opened without a file variable.

setting-var is the name of the variable that is set to a value corresponding to a file I/O error code by the SETTING clause if the item cannot be deleted and the ON ERROR clauses is taken. The file I/O error codes are described in File I/O and IPC Error Codes.

If the ON ERROR clause is not taken, setting-var is set to 0.

ON ERROR operates exactly the same as an ELSE clause.

Note

It is recommended that you always include an ON ERROR clause. If you do not and an error occurs at run time, your program will abort. This is particularly important if the file has a PRE-DELETE trigger that may cancel the DELETE operation.

statement(s) is a sequence of one or more valid DataBasic statements, either separated by semicolons or contained on separate lines and followed by an END statement.

Operation

If the item does not exist, no action is taken.

If the specified file has not been opened prior to the execution of the DELETE statement, the program aborts with an error message.

Caution

When calling this statement, you need to be aware of the effects of any file triggers that might run as a consequence. See File Triggers for more information.

Examples

DELETE X,"XYZ"

Deletes item XYZ in the file opened and assigned to variable X.

Q="JOB"
DELETE Q

Deletes item JOB in the last file opened without a file variable.