OPENPATH

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 {options} TO file.var

{ON ERROR statement(s)}

{THEN statement(s)}

{ELSE statement(s)}

 

where

 

pathnameevaluates to the pathname of the file to be opened.

 

optionscontrol the manner in which the file is opened and may be any combination of:
ENCODING nameSpecifies the default encoding mode for directory files. Ignored for other file types.
NON.TRANSACTIONALIgnore transaction boundaries
NO.MAPSuppress id character translations
READONLYDisable file updates
SYNCForce write all file updates.

 

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 file remains open so long as the file variable remains intact. Overwriting this variable or discard of the variable on return from a subroutine will implicitly close the file. QM has limited support for the concept of a default file variable as found in some other multivalue products.

 

The ENCODING option, applicable only to directory files, sets the default character encoding to be used. The name may be a quoted literal string or an expression that evaluates to the encoding name.

 

The optional NON.TRANSACTIONAL clause indicates that updates to the file are not to be treated as part of any transaction within which they occur.

 

The NO.MAP option is relevant only to directory files and suppresses the normal translation of restricted characters in record ids. See directory files for more information.

 

The optional READONLY clause opens the file for read only access. Any attempt to write to the file will fail.

 

The SYNC option causes updates to the file to be flushed to disk after every write. This will have a severe impact on performance if the file is updated frequently. See synchronous (forced write) mode in the section that discusses dynamic files for more details.

 

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 default action is to set the file variable as unassigned. Use of the OPEN.FAIL.ZERO.FVAR setting of the $MODE compiler directive changes this to set the file variable to zero.

 

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

 

OPENPATH "\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, OPENTEMP