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

244 AppendixB
BASIC/V Intrinsics
BKOPEN
the
access
parameter.)
When access is shared, it is good practice to allow dynamic locking so that individual users
can dynamically lock the file while performing any updates to the file. The file can be
unlocked as soon as the update is complete. An update to a file is when you write a new
record, delete a record, or rewrite an existing record. When access is exclusive or
semi-exclusive, there is no need for dynamic locking since only the user who has opened
the file can update the file.
Dynamic locking should also be allowed if access is shared and you plan to read the file
sequentially. This is because the sequential read procedure (BKREAD) is dependent on the
position of the logical record pointer and, in a shared environment, this pointer can be
changed by other users unless the file is locked. (Refer to Table B-2. for a list of the
pointer-dependent procedures.)
When sequence checking is specified, you must write records to the file in primary key
sequence. An attempt to write a record out of sequence causes the write to fail and the
value 21 is returned to
status
following a call to BKWRITE. As a result of sequence
checking, the physical and the primary key sequence of records in your file is the same.
Since the BASIC KSAM procedures have no provision to read the file in physical sequence,
you may want to specify sequence checking for any file that you will want to read in that
order. With sequence checking, a file read in logical order by primary key (the default for
BKREAD) is also read in physical order.
The example in Figure B-4. shows how to use BKOPEN to open a KSAM file for input and
output (default
access
), with dynamic locking (
lock
=1), for shared access (
exclusive
=3),
and without sequence checking (default
sequence
).
Figure B-4. Opening KSAM File with BKOPEN
10 DIM S$[4] <--------
status
\
20 DIM N$[26] <-------------
filename
|-
variable dimensions
30 DIM M$[72] <--------
message
/
40 INTEGER A[10]
50 DIM B$[12]
55 INTEGER J
60 DIM B1$[1]
65 DIM B2$[2]
70 INTEGER A2[2],A3[3],A5[5]
Table B-3. Relationship of Exclusive Parameter to Access Parameter
exclusive
=0
exclusive
=1
exclusive
=2
(default)
exclusive
=3
access
=0
(read only)
shared exclusive semi-exclusive shared
access
0
(write only,
read/write, or
update)
exclusive exclusive semi-exclusive shared