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

42 Chapter4
Opening and Closing the File
Opening a New File
binary 0001 or 1 To write to the file for the first time.
binary 0010 or 2 To append records to the file.
binary 0100 or 4 To allow both read and write access.
binary 0101 or 5 To update records in the file.
If your file requires shared access and you are accessing records using pointer-dependent
procedures, you must allow dynamic locking in the file opening procedure and use the
FLOCK and FUNLOCK intrinsics to protect your transactions from access by another process.
This ensures that no other user changes or deletes the record after you have positioned the
pointer to it. In this case, the
aoption
parameter must be set to allow both shared access
and dynamic locking, as well as to specify the access method. Note that the
aoption
parameter can be entered in octal notation listing "%" instead of "binary". This allows
setting the shared and dynamic locking bits.
FILENUM:=FOPEN(FILNAME,3,OCTAL ('340')
The preceding example allows shared access (bits 8:2 = binary 11) and dynamic locking
(bits 10:3=1) with read only access (bits 12:4=0) .
Opening a New File
As discussed in Chapter 2, a file can be created when it is opened using the HPFOPEN or
FOPEN intrinsics. The file characteristics must be specified, as well as the formal file
designator, the domain, and the access method. The most common item numbers used to
create and open KSAM files with the HPFOPEN intrinsic include:
2 The file designator.
10 A file type of 3 for KSAM XL files. A file type of 7 for KSAM64 files.
11 An access option of 1 for writing records to a new file.
19 The record length.
35 The maximum file length.
50 Either a disposition of 2 for a temporary file or 1 for a permanent file.
53 ASCII or binary record data.
54 The KSAM key parameter defining primary and alternate key
descriptions.
Figure 4-2. presents a portion of a program that builds and opens a KSAM file.