OPENPATH statement

Syntax

OPENPATH pathname [TO file.variable] [ON ERROR statements]
{THEN statements [ELSE statements] | ELSE statements}

Description

The OPENPATH statement is similar to the OPEN statement, except that the path name of the file is specified. This file is opened without reference to the VOC file. The file must be a hashed InfoSphere® DataStage® file or a directory (types 1 and 19).

pathname specifies the relative or absolute path name of the file to be opened. If the file exists, it is opened and the THEN statements are executed; the ELSE statements are ignored. If pathname evaluates to the null value, the OPENPATH statement fails and the program terminates with a run-time error message.

If the file cannot be accessed or does not exist, the ELSE statements are executed; any THEN statements are ignored.

Use the TO clause to assign the file to a file.variable. All statements used to read, write, delete, or clear that file must refer to it by the assigned file.variable name. If you do not assign the file to a file.variable, an internal default file variable is used. File references that do not specify file.variable access the most recently opened default file. The file opened to the default file variable is assigned to the system variable @STDFIL.

The ON ERROR Clause

The ON ERROR clause is optional in the OPENPATH statement. Its syntax is the same as that of the ELSE clause. The ON ERROR clause lets you specify an alternative for program termination when a fatal error is encountered during processing of the OPENPATH statement.

If a fatal error occurs, and the ON ERROR clause was not specified, or was ignored (as in the case of an active transaction), the following occurs:

  • An error message appears.
  • Any uncommitted transactions begun within the current execution environment roll back.
  • The current program terminates.
  • Processing continues with the next statement of the previous execution environment, or the program returns to the command prompt.

A fatal error can occur if any of the following occur:

  • A file is not open.
  • file.variable is the null value.
  • A distributed file contains a part file that cannot be accessed.

If the ON ERROR clause is used, the value returned by the STATUS function is the error number.

The STATUS Function

You can use the STATUS function after an OPENPATH statement to find the cause of a file open failure (that is, for an OPENPATH statement in which the ELSE clause is used). The following values can be returned if the OPENPATH statement is unsuccessful:

Value
Description
-1
Filename not found in the VOC file.
-21
Null filename or file.
-3
Operating system access error that occurs when you do not have permission to access an InfoSphere DataStage file in a directory. For example, this might occur when trying to access a type 1 or type 30 file.
-41
Access error when you do not have operating system permissions or if DATA.30 is missing for a type 30 file.
-5
Read error detected by the operating system.
-6
Unable to lock file header.
-7
Invalid file revision or wrong byte-ordering for the platform.
-81
Invalid part file information.
-91
Invalid type 30 file information in a distributed file.
-10
A problem occurred while the file was being rolled forward during warm-start recovery. Therefore, the file is marked "inconsistent."
-11
The file is a view, therefore it cannot be opened by a BASIC program.
-12
No SQL privileges to open the table.
-131
Index problem.
-14
Cannot open the NFS file.

1A generic error that can occur for various reasons.

Example

The following example opens the file SUN.MEMBER. The path name specifies the file.

OPENPATH '/user/members/SUN.MEMBER' ELSE ABORT