CLEARFILE Statement

Clears the dictionary or data section of a specified file.

Syntax

CLEARFILE {file-var} {SETTING setting-var} {ON ERROR statements}

Syntax Elements

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 a variable that is set to a value corresponding to a file I/O error code by the SETTING clause if a network error occurs. The file I/O error codes are described in File I/O and IPC Error Codes. If no error occurs, setting-var is set to 0.

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

When a CLEARFILE statement is executed, the dictionary or data section of the file that was previously assigned to the specified file-variable (via an OPEN statement) is emptied. All the items in the file are deleted. If the specified file has not been opened prior to the execution of the CLEARFILE statement, the program aborts with an error message. File definition items (D-pointers) are not deleted when a dictionary is cleared. The MD and the SYSTEM dictionary are protected against being cleared. ON ERROR operates exactly the same as an ELSE clause.

The CLEARFILE statement must be run from an account that has SYS(2) privileges.

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

OPEN 'DICT INV' TO D.INV ELSE GOTO 100
CLEARFILE D.INV SETTING ERR ON ERROR GOTO 100

Clears the dictionary section of the remote file called INV. If the CLEARFILE operation failed, the ERR variable contains a file I/O error code, and the program transfers to statement 100.

OPEN 'FN1' ELSE PRINT "NO FN1"; STOP
READ I FROM 'I1' ELSE STOP
CLEARFILE

Opens file FN1, reads item I1 and assigns a value to variable I, then clears FN1.