Using KSAM/XL and KSAM 64 (32650-90886)

Chapter 4 41
Opening and Closing the File
Opening an Existing KSAM File
The
file_num
parameter is used to return a file number to the calling program. This file
number is used to identify the file in subsequent intrinsic calls. The
status
parameter
returns a numeric code identifying the success or failure of the file opening process.
For clarity, the
itemnum
parameters in the previous example have been defined as
constants. This is not necessary for intrinsic use. The following HPFOPEN intrinsic call
provides the same options as the preceding example, but the
itemnum
parameters are
identified by number. Note that the corresponding
item
parameters are variables that
contain the appropriate selections. These variables would have to be defined and declared
as in the previous sample.
HPFOPEN(file_num, status,
2, file_name,
3, permanent,
11, update,
12, lockable,
13, shared,
53, ascii
)
Using the FOPEN Intrinsic
Only the file designator and the domain need to be specified to open an existing file with
the FOPEN intrinsic. Rather than the
itemnum/item
pairs in HPFOPEN, the FOPEN intrinsic
parameters are specified as bit groupings. The domain must be specified in the
foption
parameter (bits 14:2). The
aoption
parameter must be set if an access other than read
needs to be specified.
The FOPEN intrinsic uses positional parameters to specify options. This means that the
sequence of parameter data defines the parameter to which it refers. For example, in an
FOPEN intrinsic call, the file designator is followed by the
foption
parameter, which is
followed by the
aoption
parameter. The following example shows the FOPEN intrinsic call
to open an existing KSAM file for read only access:
file_num:=FOPEN(file_name,3)
The variable
file_num
returns the file number for use in subsequent intrinsic calls. The
foption
value 3 specifies that an existing user file is to be opened (bits 14:2= (binary) 11).
Because no
aoption
parameter was specified, the file is opened with read only access, the
default.
To open an existing file with update access, specify the access mode in the
aoption
parameter. The other parameters remain the same. The following example opens the file
with update access.
file_num:=FOPEN(file_name,3,5)
In this example, the
aoption
value 5 specifies update access for the file (bits 12:4 =
(binary) 0101). This level of access allows all other intrinsic calls for this file. Other binary
access selections include:
binary 0000 or 0 To read the file.