14.8.11 USEROPEN Clause
The USEROPEN clause specifies an external long func-
tion that BASIC executes when you open or create a file.
(You do not need to declare the USEROPEN routine with an
EXTERNAL FUNCTION statement.) This procedure can
then specify additional OPEN parameters for the file. For
example:
OPEN "FILE.DAT" FOR INPUT AS FILE #2%, &
ORGANIZATION INDEXED, USEROPEN Myopen, MAP ABC
The code in Myopen determines how the file FILE.DAT
is opened. The Run-Time Library sets up six RMS con-
trol structures before calling the USEROPEN procedure.
Table 14-4 defines these structures and their meanings.
A USEROPEN procedure should not alter the allocation
of these structures, although it can modify the contents of
many of the fields. You should not modify fields set by other
OPEN statement keywords. For example, you should use the
RECORDSIZE clause, not a USEROPEN routine, to set the
record length.
The allocation of the RMS control structures (except for the
RAB) lasts only for the duration of the OPEN statement.
Therefore, your USEROPEN can retain only the RAB ad-
dress for use after the OPEN operation is complete. Note
that any additional structures that you allocate and link
into the RMS structures must be unlinked before exiting the
USEROPEN.
The following steps describe the execution of the USEROPEN
routine:
1. BASIC performs normal OPEN statement processing up
to the point where it would call the RMS OPEN/CREATE
and CONNECT routines. BASIC then passes control to
the USEROPEN routine.
2. BASIC passes the address of the FAB as the first param-
eter, the address of the RAB as the second parameter, and
the address of the user-specified channel number as the
third parameter to the routine.
3. The USEROPEN routine can modify the contents of the
RMS control structures, and it must call the RMS OPEN
or RMS CREATE routine and the RMS CONNECT
routine and return the status in R0.
Example 14-1 shows how to create a USEROPEN routine to
obtain a RAB address.
Note