Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 18
Locking, Renaming, Caching, Closing, Purging, and
Altering Relative Files
Locking, Renaming, Caching, Closing, Purging, and Altering
Relative Files
The operations of locking, renaming, closing, and purging relative files, altering
relative-file attributes, and avoiding unnecessary cache flushes of relative files are the
same as for any disk file. See Using Unstructured Filesearlier in this section.
Relative-File Programming Example
This example is an extension of the log-file program described near the end of
Section 2, Using the File System. It is modified to use a relative file instead of an
unstructured file. A relative file is suitable for this kind of application because:
Entries in the file are chronological and therefore suitable for referencing by record
number.
The record number gives the user a key to access records randomly.
You can create the relative file required by this program using the FILE_CREATE_
procedure as described under Creating Relative Files, or you can simply use FUP
commands as shown below:
1> FUP
-SET TYPE R
-SET BLOCK 4096
-SET REC 512
-SHOW
TYPE R
EXT ( 1 PAGES, 1 PAGES )
REC 512
BLOCK 4096
MAXEXTENTS 16
-CREATE $ADMIN.OPERATOR.RELFILE
CREATED - $ADMIN.OPERATOR.RELFILE
-EXIT
2>
The record length is set by a FUP command to 512 bytes. Each record’s data can
therefore be any length up to 512 bytes.
In addition to code modified to use a relative file instead of an unstructured file, this
program contains a function that updates an existing record.
To make the code use a relative file instead of an unstructured file, the code has been
modified in the following ways:
The UPDATE^RECORD procedure has been added. This procedure allows the
user to replace an existing record. It prompts the user for the record number to
update, then prompts for the new comments and writes the new contents over the
original contents in the file. Finally, the procedure returns control to the LOGGER
procedure.