CHAPTER 6
RELATIVE FILES
THE VALUE OF RELATIVE ACCESS
Sequential files are very useful when
you're
just
working with a continuous stream
of
data - i.
e.,
information that can be read or written all at once. However, sequential files
are not useful in some situations. For example, after writing a large list
of
mail labels, you
wouldn't
want to have to reread the entire list each time you need a person's record.
Instead, you need some kind
of
random access, a way to get to a particular label in your
file without having to read through all those preceding it.
As an example, compare a record turntable with a cassette recorder. You have to
listen to a cassette from beginning to end, but a turntable needle can be picked up at any
time, and instantly moved to any spot on the record. Your disk drive works like a turntable
in that respect.
In
this chapter you will learn about a type
of
file that reflects this
flexibility.
Actually, two different types
of
random access files may be used on Commodore
disk drives: relative files and random files. Relative files are much more convenient for
most data handling operations, but true random access file commands are also available to
advanced users, and will be discussed
in
the next chapter.
FILES, RECORDS, AND FIELDS
When learning about sequential files, you did not worry about the organization
of
data within a file, so long as the variables used to write the file matched up properly with
those which read it back into the computer. But
in
order for relative access to work, you
need a more structured and predictable environment for our data.
The structure you will use is similar to that used
in
the traditional filing cabinet. In a
traditional office, all customer records might be kept
in
a single file cabinet. Within this
file, each customer has a personal record
in
a file folder with their name on it, that
contains everything the office knows about that person. Likewise, within each file folder,
there may be many small slips
of
paper. each containing one bit
of
information about that
customer, such as a home phone number
or
the date
of
the most recent purchase.
In a computerized office, the file cabinet is gone, but the concept
of
a file containing
all the information about a group or topic remains. The file folders are gone too. but the
notion
of
subdividing the file into individual records remains. The slips
of
paper within
the personal records are gone too, replaced by subdivisions within the records. called
fields. Each field is large enough to hold one piece
of
information about one record
in
the
file. Thus, within each file there are many records. and within each record there are
typically many fields.
A relative file takes care
of
organizing the records for you, numbering them from I to
the highest record number, by ones. but the fields are up to you to organize. Each record
will be
of
the same size, but the
1571
won't
insist that they all be divided the same way.
On
the other hand. they normally will be subdivided the same way, and if it can be known
in
advance exactly where each field starts within each record, there are even fast ways to
access a desired field within a record without reading through the other fields.
As
all
of
this implies, access speed is a primary reason for putting information into a relative disk
53