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

39
4 Opening and Closing the File
Some application programming languages offer commands for opening and closing KSAM
files (for example, the ORGANIZATION IS INDEXED clause in COBOL). If not, use the
HPFOPEN or FOPEN intrinsic to open the file, and the FCLOSE intrinsic to close the file. See
the appropriate application language reference manual for details on how to call intrinsics.
Opening an Existing KSAM File
The HPFOPEN and FOPEN intrinsics both open KSAM files, as well as other file types.
HPFOPEN is designed to be more flexible and offers more options than the FOPEN intrinsic.
HPFOPEN, however, can be used only in an MPE/iX environment. If the program is to be
used in both MPE/iX and MPE V/E environments, use the FOPEN intrinsic.
Using the HPFOPEN Intrinsic
The HPFOPEN intrinsic uses pairs of item numbers and items for optional parameter
passing. An
itemnum
parameter passes an integer by value to define the parameter and
expected data type of the value passed in its corresponding
item
parameter.
To open an existing permanent file, file characteristics do not have to be specified. This
information is obtained by the file management system from the file's label.
Most often, the item number pairs that are needed to open an existing KSAM file include
the file designator, its domain, and access options. The domain identifies the location of the
file to be opened. The access option defines the method of access allowable for the file. In
some cases, the dynamic locking option and exclusive option need to be specified if more
than one process is to access the file.
Figure 4-1. provides a portion of a Pascal program that calls the HPFOPEN intrinsic to open
the accounts receivable KSAM file. It presents the
itemnum
and
item
definitions and
declarations as well as the HPFOPEN intrinsic call. In the example, the file is opened for
update access, allowing all intrinsic usage. It also allows dynamic locking and shared
access for concurrent use with other processes.