ASSIGN [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation
HP Business BASIC/XL Reference Manual
ASSIGN
The ASSIGN statement opens a file (makes it accessible) or closes a file
(makes it inaccessible) in the program executing the statement. The file
is opened by HP Business BASIC/XL when the program assigns the file a
file number. HP Business BASIC/XL uses the file number to identify the
file for reading and writing information. The ASSIGN statement
disassociates a file from its file number and closes the file. When HP
Business BASIC/XL closes a file, it releases the buffer space that was
allocated to it.
Syntax
To open a file:
{fname TO #fnum} [,RESTRICT[=]ioaccess]
ASSIGN {#fnum TO fname} [,STATUS[=]num_var] [[,useraccess] ]
[,MASK[=]str_expr]
To close a file:
{* TO #fnum}
ASSIGN {#fnum TO *}
Parameters
fname A string literal or string expression that contains the
file name. It must include the lockword used when the
file was created, if any. This parameter can be back
referenced to a file equation.
fnum The file number that HP Business BASIC/XL uses to
identify the file. It evaluates to a positive short
integer. If fnum is associated with another open file,
the ASSIGN statement opening the file first closes the
open file before opening the one specified by fname.
If you attempt to close an already closed fnum, the
ASSIGN statement does nothing.
num_var A variable that returns the status of the ASSIGN
statement. The ASSIGN statement sets the value of this
variable to zero if it opens the file successfully;
otherwise, it sets it to a nonzero value.
A nonzero value represents the file error code returned
by the file subsystem of the MPE XL operating system.
The error number can be translated to an MPE XL file
system error message by looking up the table of file
system error codes in the MPE XL Intrinsics Reference
Manual under the FCHECK intrinsic.
ioaccess If a file is opened by a program, the ioaccess
specification determines how the program can access the
file. The value of ioaccess is one of the following
keywords:
READ The program can read from the file, but
cannot write to it.
WRITE The program can write to the file, but
cannot read from it.
APPEND The program can perform sequential
writes to the file starting after the
last record. It cannot read from the
file or perform direct writes to the
file.
READWRITE The program can read from and write to
the file. This is the default I/O
access if the RESTRICT option is not
specified.
useraccess If a file is open to one program, useraccess determines
how other programs can access the file. It also
determines whether the program that opened the file can
open it again without closing it first. The value of
useraccess is one of the following keywords:
EXCLUSIVE Other programs cannot access the file.
The program that opened it must close
it before opening it again. The
sequence:
ASSIGN fname TO #fnum1,RESTRICT=READ,
EXCLUSIVE
ASSIGN fname TO #fnum2
is illegal. The sequence must be:
ASSIGN fname TO #fnum1,RESTRICT=READ,
EXCLUSIVE
ASSIGN * TO fnum1
ASSIGN fname TO #fnum2
SINGLEUSER Other programs cannot write to the
file, but the program that opened it
can open it again without closing it
first. The sequence:
ASSIGN fname TO #fnum1,RESTRICT=READ,
SINGLEUSER
ASSIGN fname TO #fnum2
is legal; it opens the file fname twice
in the same program, at the same time.
SINGLEUSER is the default if this
parameter is not specified.
You must have LOCK capabilities at both
the account and group level in order to
open the file multiple times. If you
do not have those capabilities, then
the default access is EXCLUSIVE.
SHARED Other programs can access the file.
SHAREREAD Other programs can read the file, but
cannot write to it.
str_expr A string expression that evaluates to a string with a
length of six characters. The string serves as a mask
used to scramble and unscramble file data, excluding
format words, EOR marks, and EOF marks. If a mask is
specified the first time a file is assigned, the same
mask must be specified each time the file is assigned;
otherwise, the data cannot be properly unscrambled.
Examples
The following examples show the use of the ASSIGN statement to open and
close files. Line 30 assigns a file with read access, allowing other
programs to use it. File1 also has a mask. Line 40 assigns a file with
append access. Line 50 assigns a file with readwrite access (default).
Line 60 assigns a file with write access, allowing other programs to read
it, and has a mask. Line 70 assigns the file with readwrite access and
line 80 assigns the file for read access, allowing no one else to access
the program. Line 90 assigns the file using a back referenced file
equation.
10 ASSIGN * TO #1 !Closes file designated as #1
20 ASSIGN #2 TO * !Closes file designated as #2
30 ASSIGN "File1" TO #3,STATUS=S,RESTRICT=READ,SHARED,MASK="ScRmBL"
40 ASSIGN #4 TO "File2",STATUS X,RESTRICT APPEND,SINGLEUSER
50 ASSIGN "File3.lab" TO #5,STATUS Open
60 ASSIGN "F4.mktg.hp" TO #6,RESTRICT=WRITE,SHAREREAD,MASK="zzypdq"
70 ASSIGN #7 TO "File5",RESTRICT READWRITE
80 ASSIGN #8 TO "File6",RESTRICT=READ,EXCLUSIVE
90 ASSIGN "*file3" to #9
MPE/iX 5.0 Documentation