Guardian Programmer's Guide

Table Of Contents
Using the Sequential Input/Output Procedures
Guardian Programmer’s Guide 421922-014
15 - 28
Handling Basic I/O With SIO Files
Refer to Handling Nowait I/O, later in this section, for information about reading and
writing to SIO files opened for nowait I/O.
Refer to Handling Interprocess Messages for information on how to read and write to
the $RECEIVE file using SIO procedures.
Handling Basic I/O With SIO Files
The SIO routines permit only sequential access to files (except when reading files in
EDIT format). There is no support for positioning within a file to achieve random
access. The initial position for sequential access therefore depends on how the file
pointers are set up when the file is opened. The access mode determines the first
record accessed as follows:
For read-only access, the initial position for sequential access is the first record in
the file. Successive read operations then step through the file one record at a
time. For key-sequenced files, record retrieval is in key sequence. For all other
file types, record retrieval is in physical-record order.
For write-only access, the initial position is the end of the file. Each write operation
therefore appends a record to the file.
For read/write access, the initial position is the first record in the file. If the first
access is a read operation, then the first record is read and the file pointers move
on to the second record for the next read or write operation. If the first access is a
write operation, then the first record gets overwritten and the file pointers move on
to the next record.
The following paragraphs describe how to use the READ^FILE and WRITE^FILE
procedures to perform I/O operations.
Reading Records With SIO Procedures
To read a record from a file, you must supply the READ^FILE procedure with the
names of the FCB of the file you wish to read from and of the buffer to receive the
record.
The following example reads one record from the input file. In addition to placing the
record into the read buffer, this call also returns the number of bytes read in the third
parameter:
CALL READ^FILE(INFILE,
READ^BUFFER,
BYTES^READ);