OPENPATH

Top  Previous  Next

 

The OPENPATH statement opens a directory file or dynamic file by pathname, associating it with a file variable.

 

 

Format

 

OPENPATH pathname {READONLY} TO file.var {ON ERROR statement(s)}

{THEN statement(s)}

{ELSE statement(s)}

 

where

 

pathnameevaluates to the VOC name of the file to be opened.

 

file.varis the name of the variable to hold the file reference for use in later operations on this file.

 

statement(s)are statements to be executed depending on the outcome of the OPENPATH operation.

 

At least one of the THEN and ELSE clauses must be present.

 

A file opened by the OPENPATH 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 to the file 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 OPENPATH returns the modulus of the file.

 

 

Example

 

OPEN "\QMSYS\NEWVOC" TO NEWVOC ELSE ABORT "Cannot open NEWVOC"

 

This statement opens the skeleton NEWVOC file in the QMSYS directory using Windows pathname syntax. If the open fails, the program aborts with an error message.

 

 

See also:

OPEN, OPENSEQ