Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 85
Adding Keys to an Alternate-Key File
ERROR := FILE_CREATE_(KEYSFILE:ZSYS^VAL^LEN^FILENAME,
LENGTH,
!file^code!,
!primary^extent^size!,
!secondary^extent^size!,
!max^extents!,
!file^type!,
!options!,
REC^LEN,
BLOCK^LEN,
KEY^LEN,
KEY^OFFSET);
END;
Adding Keys to an Alternate-Key File
Usually, you do not add keys to an alternate-key file directly. The file system inserts
the alternate keys automatically whenever a new key is added to the primary-key file.
However, you can create an alternate-key file and specify that updates will not be done
automatically. For example, in an application where a specific alternate key will not be
used until some time after the primary file is updated, your application can choose to
batch updates to an alternate-key file and then have the updates performed later.
Such an approach means that you have to access the alternate-key file directly.
If you do need to access the alternate-key file directly, then the file system is unable to
provide the same protection as when you access alternate keys using the file number
of the primary file. Here, you must protect your alternate-key files from duplicate
insertions when concurrent insertions take place on the primary file. To do this, you
must set the alternate-key insertion locking mode, using SETMODE function 149, as
follows:
LITERAL ALT^KEY^INSERTION^LOCKING = 149,
AUTO^LOCK = 1;
.
.
CALL SETMODE(F^NUM,
ALT^KEY^INERTION^LOCKING,
AUTO^LOCK);
This procedure call provides record-level locks while a record is being inserted in the
primary data file. The lock is released as soon as the insert is complete.