OPEN |
![]() ![]() ![]() |
The OPEN statement opens a directory file or dynamic file, associating it with a file variable.
Format
OPEN {dict.expr,} filename.expr {READONLY} TO file.var {ON ERROR statement(s)} {THEN statement(s)} {ELSE statement(s)}
where
At least one of the THEN and ELSE clauses must be present.
A file opened by the OPEN statement may be referenced using the file variable in subsequent statements that operate on the file.
The optional READONLY clause opens the file for read only access. Any attempt to write will fail.
If the file is opened successfully, the THEN clause is executed. If the open fails the ELSE clause is executed and the STATUS() function may be used to determine the cause of the failure.
The ON ERROR clause is taken only in the case of serious errors such as damage to the file's internal control structures. The STATUS() function will contain an error number. If no ON ERROR clause is present, a fatal error results in an abort.
QM allows more files to be open than the underlying operating system limit. This is achieved by automatically closing files at the operating system level if the limit is reached, retaining information to reopen them automatically when the next access to the file occurs. This process allows greater freedom of application design but has a performance penalty if a large number of files are used frequently.
For dynamic files, the INMAT() function used immediately after the OPEN returns the modulus of the file.
Example
OPEN "STOCK.FILE" TO STOCK ELSE ABORT "Cannot open file"
This statement opens a file with VOC name STOCK.FILE. If the open fails, the program aborts with an error message.
See also: |