MKEYED
PURPOSE:
To define a MKEYED file.
STATEMENT SYNTAX:
{stno} MKEYED fname,keysize,records,recsize,disk#{,ERR=stno}
{stno} MKEYED fname,keydef1,keydef2,keydef3,...,keydefn,
records,recsize,disk#{,ERR=stno}
where:
fname = Any valid filename
keysize = maximum size of the key (max is 120).
records = aproximate(see File I/O)
number of records to be contained in this file.
recsize = the size of each record in the file(max 8192).
disk# = a # associated with a SETDISK.
keydef = segment{+segment} where:
segment = [fieldnum:offset:len{ :flags}] {+segment ...} where:
flags = "U" | "D" where:
U = Indicates this keydef is Unique (must appear in the 1st segment of a keydef
D = Indicate this segment is sorted in Descending order
The 1st form is identical to a DIRECT command.
The 2nd form generates multiple keys from portions of the Data Record. A fieldnum of 0
refers to the whole record. A fieldnum of 0 would be used with files that are accessed
using READ RECORD and WRITE RECORD or READ ARCHIVE and
WRITE ARCHIVE. fieldnum 1->X are used with files that are accessed with READ
and WRITE where fields are delimitted by $0A$. The offset is the byte offset
into the field where the 1st byte is 1.
The 1st keydef is called the Primary key it always contains unique keys.
The primary key is referenced as KNUM=0. Other keydef's
are allowed duplicate keys unless the "U" flag appears in the 1st segment of the keydef.
Other keydefs are referenced by KNUM=1 ->
KNUM=X.
Any segment that has a "D" has the string NOT function applied to it as the key is being
created. This causes a descending order.
EXAMPLE:
0100 MKEYED "MTEST",[1:1:10],[3:1:4]+[2:1:3:"D"],1000,100,3,ERR=9000
The example creates a file called MTEST that contains 2 keys. On a WRITE
the keys are created as follows:
The Primary key has a
single segment composed of the 1st 10 characters of the 1st field. If
the 1st field is less than 10 characters long it is padded with $00$.
The 2nd key is
created from 2 segments. The 1st segment is the 1st 4 characters of the 3rd field.
If the 3rd field is less than 4 characters long it is padded with $00$. The 2nd segment
of the 2nd key is the first 3 characters of the 2nd field. If the 2nd field is less than 3
characters long it is padded with $00$. A string NOT function is then applied to these
3 characters. The 2nd segment is the added to the 1st segment to form the 2nd key
It should be noted that the KEY functions will apply a string NOT against descending segments
to return them to there original value. The key functions only strip trailing $00$'s not the
$00$'s added in the middle of a key.
Check the output of this program:
10 BEGIN
20 ERASE "MTEST",ERR=.+1
30 MKEYED "MTEST",[1:1:10],[3:1:4]+[2:1:3:"D"],1000,100,-1
40 OPEN (1)"MTEST"
50 WRITE (1)"123","45","6"
60 READ (1,KNUM=1,KEY="",DOM=.+1)
70 LET K$=KEY(1)
80 PRINT K$
90 PRINT HTA(K$)
RUN
645
360000003435