Enscribe Programmer's Guide

FILE_READ64_, FILE_READLOCK64_, FILE_READUPDATE64_,
FILE_READUPDATELOCK64_, READ[X], READLOCK[X], READUPDATE[X],
READUPDATELOCK[X]
FILE_WRITE64_, FILE_WRITEUPDATE64_, FILE_WRITEUPDATEUNLOCK64_,
WRITE[X], WRITEUPDATE[X], WRITEUPDATEUNLOCK[X]
FILE_GETINFO_, FILE_GETINFOLIST_, FILE_GETINFOBYNAME_,
FILE_GETINFOLISTBYNAME_
SETMODE, CONTROL, FILE_CONTROL64_
Types of Access
Key-sequenced files can be accessed either sequentially or randomly. Sequential access is
preferable, for example, when generating a report of the quantity on hand of all parts in an
inventory file. Random access is preferable when you want to identify the vendor of a particular
part.
When you read from a key-sequenced file by primary key, each FILE_READ64_/READ operation
retrieves the record containing the next sequentially higher primary-key value. Similarly, when you
read by an alternate key, each FILE_READ64_/READ operation retrieves the record containing
the next sequentially higher value in the specified alternate-key field.
The FILE_SETKEY_ or KEYPOSITION system procedure specifies which access path (primary key
or a particular alternate-key field) you want to use and the field value at which you want to start.
If you do not use FILE_SETKEY_ or KEYPOSITION, access is by primary key and begins with the
first record in the file.
You can use FILE_SETKEY_ or KEYPOSITION during program execution to dynamically change
the access path and the current-record pointer.
Key-Sequenced Tree Structure
Key-sequenced files are physically organized as one or more bit-map blocks and a B-tree structure
of index blocks and data blocks. Figure 14 (page 70) illustrates a sample key-sequenced file tree
structure. Bit-map blocks within the file organize the free space of a structured file.
Each data block contains a header plus one or more data records, depending on the record size
and data-block size. For each data block there is an entry in an index block containing the value
of the key field for the first record in the data block and the address of that data block.
The position of a new record inserted into a key-sequenced file is determined by the value of its
primary-key field. If the block where a new record is to be inserted into a file is full, a block split
occurs. This means that the disk process allocates a new data block, moves part of the data from
the old block into the new block, and gives the index block a pointer to the new data block.
When an index block fills up, it is split in a similar manner: a new index block is allocated and
some of the pointers are moved from the old index block to the new one. The first time this occurs
in a file, the disk process must generate a new level of indexes. The disk process does this by
allocating a higher-level index block containing the low key and pointer to the two lower-level
index blocks, which in turn point to many data blocks. The disk process must do this again each
time the highest-level block is split.
The disk process sometimes performs a three-way block split, creating two new blocks and
distributing the original block's data or pointers (plus the new record or pointer) among all three.
If your record size is large, you should also use a large block size. If the block size is too small to
hold more than a few records, block splits occur more frequently, disk space usage is less efficient,
and performance is degraded.
Types of Access 69