SORT/DIRECT Files
A keyed file is a sequence of fixed length records that are accessed
by name (key) rather than number (index). When a keyed file is created,
a key size, record size, and record count are specified. Keyed files do
not grow dynamically. A key table is initialized by PRO/5 at creation
time. A key may be any string of characters up to 64 bytes. Keys are internally
kept padded with nulls. Each key within a given keyed file must be unique.
The records in a keyed file may be accessed directly by a key or alphabetically
forward or backward. Also, the program may provide a "partial key"
causing positioning to a specific point within the file. This is useful,
for example, for locating the first invoice with a specific date. Records
may also be accessed by record number, but this should never be done by
an application program since PRO/5 does not guarantee any relationship
between a record number and a key at any given time. This is provided
only for emergency reconstruction of a keyed file whose key area has been
damaged.
In PRO/5, keyed files are called DIRECT and SORT files. A SORT file contains
only keys. A DIRECT file contains keys and data records. The DIRECT and
SORT verbs are used to create keyed files.
To create a SORT file with a key size of 6 bytes and 2500 record capacity:
>SORT "ABC",6,2500
The keys in a SORT file are maintained in constant sorted order.
An attempt to use a key longer than that specified for the file will result
in an !ERROR=46. Keys shorter than
the specified length will be filled out to the maximum length using $00$
(NULL) characters. Also, when PRO/5 returns a key using one of the KEY()
functions, trailing $00$ characters will be stripped. This has the effect
of making the keys $00$, $0000$, and so on, identical.
The DIRECT file is a combination of SORT and INDEXED files. The creation
is actually a combination of the SORT file followed by an INDEXED file.
The position of the key in the key area is matched to the position of
the data record in the INDEXED portion of the file. The definition of
a DIRECT file is similar to that of a SORT file:
>DIRECT "ABC",6,2500,128
This would define a DIRECT file using 6-byte keys, 2500 records each
with 128 bytes.
A key in a keyed file may be removed using the REMOVE command:
>REMOVE (1,KEY=K$)
A DIRECT file will allow a key up to 64 bytes in length, records up
to 32767 bytes and as many as (2^31)-1 records. The total file size may
not exceed (2^31)-1 bytes.
The FIN() of a SORT/DIRECT contains the following information:
Bytes |
Contents |
65,4 |
Index of the last key removed (Base 1) |
69,4 |
Index of the lowest available key (Base 1) |
73,4 |
Index of the lowest logical key (Base 1) |
77,4 |
Number of active keys in the file |
81,4 |
Index of the highest logical key (Base 1) |
All of the fields marked Base 1 are indices into the file plus 1. To use one of these indices, simply subtract 1 from the value before using in an "IND=" option.