VMS Help
PASCAL, Input Output, General, OPEN
*Conan The Librarian (sorry for the slow response - running on an old VAX)
|
|
The OPEN procedure opens a file and allows you to specify file
characteristics.
Syntax:
OPEN( file_variable
,[[file_name]]
,[[history]]
,[[record_length]]
,[[access_method]]
,[[record_type]]
,[[carriage_control]]
,[[organization]]
,[[disposition]]
,[[file_sharing]]
,[[user_action]]
,[[default_file_name]]
,[[ERROR := error_recovery]] )
OPEN( FILE_VARIABLE := file_variable
[[,FILE_NAME := file_name]]
[[,HISTORY := history]]
[[,RECORD_LENGTH := record_length]]
[[,ACCESS_METHOD := access_method]]
[[,RECORD_TYPE := record_type]]
[[,CARRIAGE_CONTROL := carriage_control]]
[[,ORGANIZATION := organization]]
[[,DISPOSITION := disposition]]
[[,SHARING := file_sharing]]
[[,USER_ACTION := user_action]]
[[,DEFAULT := default_file_name]]
[[,ERROR := error_recovery]] )
Before the OPEN procedure is called, the file is in undefined
mode; its mode does not change after OPEN has been executed.
You cannot use OPEN on a file variable that is already open.
If you use INPUT, OUTPUT, or ERR, Compaq Pascal implicitly opens
them just before their first use. Compaq Pascal implicitly
opens INPUT with a history of READONLY. If you choose, you can
explicitly open INPUT, OUTPUT, or ERR; to do this, call the OPEN
procedure at any point in your compilation unit before you use
the first I/O routine on that file.
Because the RESET, REWRITE, and EXTEND procedures implicitly
open files, you need not always use the OPEN procedure. RESET,
REWRITE, and EXTEND impose the same defaults as OPEN, except
where noted (in the HISTORY parameter).
You must use the OPEN procedure to create a TEXT file with
fixed-length components, to create a file with relative or
indexed organization, to open a file for direct or keyed access,
or to specify a line length other than the default for a line in
a TEXT file.
See the "Compaq Pascal Language Reference Manual" for the
complete description of the OPEN procedure.
The 'file_variable' is the only required parameter. It is the
name of the file variable associated with the file that Compaq
Pascal is to open.
The 'file_name' is a character-string expression containing the
external file name. Compaq Pascal determines the default file
name according to the environment in which you are programming.
The 'history' is a value that indicates whether the file exists
or if Compaq Pascal must create the file. If you specify OLD
and if Compaq Pascal cannot find the file, an error occurs. If
you specify READONLY, you can only read from the file; if you
attempt to write to the file, an error occurs. If you specify
UNKNOWN, Compaq Pascal looks for an existing file but creates a
new file if there is no existing file. If you specify OLD or
UNKNOWN and if the attempt to open the file generates a file
protection error, Compaq Pascal tries again using READONLY.
NEW is the default for OPEN/REWRITE openings, while OLD is the
default for EXTEND/RESET openings.
The 'record-length' is a positive integer that specifies the
maximum size in bytes for a line in a TEXT file or a file of
type FILE OF VARYING. ("Record" length is equivalent to
"component" length.) The default is 255 bytes. For all other
types of files, Compaq Pascal ignores this parameter.
If you do not specify a length for an existing file, Compaq
Pascal uses the length specified at the file's creation.
If you use OPEN to create a sequentially organized file with
variable-length components, Compaq Pascal records the maximum
length of each component in the file only if you specify a value
for the record_type field.
The 'access_method' is a value that specifies the component
access method to use. The possible values include SEQUENTIAL,
DIRECT, and KEYED. The DIRECT access method is equivalent to
random access by relative component number. The KEYED access
method is equivalent to random access by key. The default is
SEQUENTIAL.
The 'record_type' is a value that indicates the component
format. ("Record" format and "component" format are
equivalent.) The available values are FIXED (fixed-length
components), VARIABLE (variable-length components), STREAM
(stream component format with either carriage return,
combination carriage return and line feed, or form feed
delimiters), STREAM_CR (stream component format with carriage
return delimiters), and STREAM_LF (stream component format with
line feed delimiters).
VARIABLE is the default for new TEXT and VARYING OF CHAR, while
FIXED is the default for other new files.
The 'carriage_control' is a value that indicates the carriage
control format for the file. The value LIST indicates single
spacing between components. The values CARRIAGE and FORTRAN are
equivalent and indicate that the first character of every output
line is a carriage control character. The values NONE and
NOCARRIAGE indicate that the file has no carriage control.
LIST id the default for TEXT and VARYING OF CHAR files, while
NONE is the default for all other file types.
The 'organization' is a value that specifies the file
organization. If you are accessing an existing file, the
specified organization must match the organization of the
existing file; if it does not, an error occurs. The choices for
this parameter are SEQUENTIAL, RELATIVE, and INDEXED. The
default is SEQUENTIAL. The parameter choices are as follows:
o SEQUENTIAL file organization specifies that file components
are stored one after the other, in the order in which they
were entered into the file. Compaq Pascal supports this
organization for files on disk. This is the only
organization supported for files on magnetic tape, on
terminals, on card readers, and on line printers.
o RELATIVE file organization consists of a series of
fixed-length component positions (cells) numbered
consecutively from 1 to n. The numbered, fixed-length cells
enable Compaq Pascal to calculate the component's physical
position in the file. The cell numbers are called relative
component numbers. Compaq Pascal supports this organization
on disk files only.
o INDEXED file organization specifies that, in addition to the
stored components, there exists at least a primary key and
possibly alternate keys (first alternate key, second
alternate key, and so forth). Compaq Pascal uses the
primary key to store components and uses a program-specified
key or keys to retrieve data. Compaq Pascal supports this
organization on disk files only.
The 'disposition' is a value that indicates what Compaq Pascal
should do with the file after you close the file.
If SAVE is specified, the file is retained. If DELETE is
specified, the file is deleted. If PRINT is specified, the file
is printed on a line printer and is retained. If PRINT_DELETE
is specified, the file is deleted after it is printed. If
SUBMIT is specified, the file is submitted to a queue or placed
in a background process and is retained. If SUBMIT_DELETE is
specified, the file is deleted after being processed.
SAVE is the default for external files. DELETE is the default
for internal files.
The 'sharing' is a value that specifies whether other programs
can access the file while it is open. A value of READONLY
indicates that other programs can read but not write to the
file. This is the default value for files with HISTORY :=
READONLY. READWRITE indicates that other programs can read and
write to the file when it is open. A value of NONE denies any
access to the file while it is open. This is the default value
for all other histories.
The 'user_action' is the name of a user-written routine that
Compaq Pascal calls to open the file (instead of allowing Compaq
Pascal to open the file with the OPEN procedure). You can use a
user-action routine to open the file using environment-specific
capabilities of the I/O system underlying Compaq Pascal.
The 'default' is a string expression containing default file
specification information. For instance, you can use this value
to set a default directory specification.
The 'error_recovery' specifies the action the program should
take if an error occurs during execution of the routine. By
default, after the first error, the error message is printed and
execution is stopped.
[legal]
[privacy]
[GNU]
[policy]
[netiquette]
[sponsors]
[FAQ]
Polarhome, production since 1999.
Member of Polarhome portal.