Introduction MTB Statements File System Compiler Applications Reference Guide Index

Language Structure Data Division I/O Format Division Procedure Division Mnemonics

OPEN statement

Syntax: OPEN (lun) filename|device-name [,DIR=directory] [,EXCP=statement-label]
Discussion: The OPEN statement opens a file or a peripheral device using a specified logical unit number.

The lun parameter is the numeric value that is assigned to the specified data file or device. The lun may be a numeric constant, numeric variable, or a symbolic constant. Its value may be from 0 through 49. The logical unit number assigned to a file or device remains in effect until the program is terminated, or until that logical unit number is closed. More than one logical unit number can be assigned to the same file or device.

The directory parameter is optional, and is the name of the Comet directory to be searched for the specified file. It can be a string constant or a string variable, with a maximum length of three characters. If a directory is specified, only that directory is searched for the file.

Also see CLOSE.

Example 1:
OPEN (1) "LP1",EXCP=9999    ! Open printer LP1
.
.
.
CLOSE (1)
Example 2:
OPEN (2) "CUSTFILE",DIR="DSK",EXCP=5000    ! Open data file
.
.
.
CLOSE (2)
Example 3:
CLOSE (6) & OPEN (6) "WORKFILE"
In this example, logical unit number 6 is first closed, then opened and assigned to a data file named "WORKFILE." This technique guarantees that the logical unit number is available before the OPEN statement is executed.