Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 36
Entry-Sequenced File Programming Example
Entry-Sequenced File Programming Example
This example again uses the log-file program. Here, the program is shown modified to
use an entry-sequenced file. The entry-sequenced file is suitable for this kind of
application because:
File entries are chronological.
Variable-length entries are permitted. Unlike for relative files, you do not allocate
512 bytes for each record; you use only as much disk space as there are data
characters entered in the record. This feature also enables entries up to a
complete block in length.
Record addresses permit random access.
Entry-sequenced files do, however, have the following drawbacks for this type of
application:
You cannot update a record with a record of arbitrary length (record updates must
be exactly the same size).
The record address is difficult to use because it is made up of the sum of the block
address and the record number relative to the start of the block.
You can programmatically create the entry-sequenced file required by this program by
using the FILE_CREATE_ procedure as described in Creating Entry-Sequenced Files
earlier in this subsection, or you can simply use FUP commands as shown below:
1> FUP
-SET TYPE E
-SET BLOCK 4096
-SET REC 4072
-SHOW
TYPE E
EXT ( 1 PAGES, 1 PAGES )
REC 4072
BLOCK 4096
MAXEXTENTS 16
-CREATE $ADMIN.OPERATOR.ESFILE
CREATED - $ADMIN.OPERATOR.ESFILE
-EXIT
2>
Notice that the maximum record length has been set to 4072 bytes. This is the
maximum allowed in a block of 4096 bytes; the remaining 24 bytes are overhead.
There is no need to restrict the record size further than this, because the only disk
space used is the actual size of the data written.
The sample program shown below differs from the relative-file example as follows:
There is no UPDATE^RECORD procedure and no corresponding option. Entry-
sequenced files do not support this feature.