Guardian Programmer's Guide

Table Of Contents
Using the Sequential Input/Output Procedures
Guardian Programmer’s Guide 421922-014
15 - 72
Using the SIO Procedures: An Example
You can create the data file using the FUP program. If the data file does not exist
when you run the program, the program will create it as an EDIT file.
Once you start the program, you can perform read and write operations against the
data file. The initial read operation always returns the first record in the file. Writes are
always appended to the file.
The program is made up of the following procedures:
The main procedure calls the INITIALIZE^FILES procedure and displays a menu
for the user to select a function from. The program responds depending on the
function selected:
For reading records, it calls the READ^RECORDS procedure.
For appending records, it calls the WRITE^RECORDS procedure.
For exiting the program, it calls the EXIT^PROGRAM procedure.
For an invalid selection, it calls the INVALID^SELECTION procedure.
The INITIALIZE^FILES procedure is called by the main procedure when the
program starts up. It uses the INITIALIZER procedure to initialize FCBs for the
input and output files and checks that the input file is a terminal and that the output
file is a disk file.
This procedure opens the input file and also opens the output file. It opens the
output file to obtain the file type (used by the OPEN^OUTPUT procedure) and to
create the file in EDIT format if it does not exist. The procedure closes the output
file before returning.
The GET^COMMAND procedure prompts the user for the function to perform and
then returns the function to the main procedure.
The OPEN^OUTPUT procedure is called by the READ^RECORDS or
WRITE^RECORDS procedure to open the output file. This procedure opens the
file for reading or for writing, and in some cases it provides a block buffer.
The OPEN^OUTPUT procedure receives the mode of access in its formal
parameter and then opens the output file accordingly. Remember that to append
to an SIO file, you must open the file in write-only mode. Therefore the file is
opened in write-only mode for writing or read-only mode for reading. For that
reason, opening the file is delayed until the user has selected a function.
The OPEN^OUTPUT procedure provides a block buffer for relative, entry-
sequenced, or key-sequenced files as well as for EDIT files. No block buffer is
provided for an unstructured file.
The READ^RECORDS procedure is called by the main program when the user
selects reading from the main menu. This procedure calls the OPEN^OUTPUT
procedure to open the disk file for read-only access and then reads the first record
from the file and displays it on the terminal. It goes on to prompt the user to read