File Organizations and Types
- Sequential - begin processing at
beginning until the very end. Searching the file for a particular
record results in the exhaustive read of a file. Large files become
extremely burdensome and time consuming. Impractical in a online
environment.
- Direct Access -
requires the use of a key to retrieve a record.
- Relative file Processing
- records are directly addressed using RELATIVE KEYS. The
key allows for direct location of a record.
- Records are retrieved by a record number, the record number
is the location number in the file. The keys are a serial set
of locations, 1 to N, each record is accessed according tp its
location number. In order for this to work, the record number
must be of some significance to the corresponding record in order
for it to be useful. If you want to update inventory item number
250 from your inventory file, then the inventory item number must
match the record number. Any problems with this?
- If there is no direct relationship between the record number,
the RELATIVE KEY, and the record then you must keep track of the
relationship between them. One way might be to use a table where
RECORD NUMBER N is associated with INVENTORY ITEM NUMBER E6-445,
row 6 of electronics bin number 45.
- Indirect Addressed
- Records are retrieved by their location which is computed
using an algorithm to convert to data value to a record location.
Basically you find the number records per track on a disk, calculate
the total number of tracks needed for you file, using the closest
prime number to the total number of tracks needed. Sometimes
called Hashing. Here's an example.
- Assume an employee database of no more than 500 employees.
Their id number is PIC 9(3). This would have a maximum of 999
directly addressed records of which 499 are wasted! If we Hash
the key with a prime number close to 500 but not over it we will
obtain a remainder that is from 0 to 498. If we then add 1 to
the remainder we can use this as the relative address. Assume
id number 855. 855//499 gives you a remainder of 356. So it's
record would be located at 356+1, or 357. As you may have noticed
there will be times when the more than 1 key hashes to the same
answer. These collisions are names synonyms. Id number 500 and
999 both result in a remainder of 1 yielding relative record 2.
So how do I store 2 records in one location? You can't. Your logic
has failed and you must seek a new career. Just kidding. One method
is to search sequentially until you hit a record that is unused
and write the record there. This requires the search process to
try a direct read and if failed start searching sequentially
until you find it.
- Indexed - we
will study ISAM, briefly, and VSAM in detail for sequential and
indexed processing.
- Relational - This organization
refers to relational database tables. We will cover basic SQL
and the processing of tables as a group of files that are "Magically"
linked together by common keys (Foreign Keys). Access from one
table can yield to direct access to other tables by field values
from the first table

FILE TYPES
File Types are classify by their usage.
- Master - primary
file for a system
- one record per employee, account, student, customer
- usually a direct access, or more recently, relational
- Transaction - records with new
data, changes to existing data
- three basic types of transactions with variations: add, change,
delete
- created from data entry or by a program reading another file.
- used to update master file
- processed by a file maintenance program
- Table
- for lookups to get corresponding data values
- for data validation
- Control - also
called control card(s)
- one or several records
- contains several key data values which determine what a program
will do: date, date range, switch, etc.
- History - all processed transactions
- may contain one year's worth or since implementation of system
- new records are appended to file
- Journal - before
and after images of master file records
- records created every time master record is updated
- primary use would be to reconstruct the master file
- also used for auditing purposes to show master file activity
- Backup - copy of a file, especially
for master files
- usually backups are done at some regular intervals and each
file is saved for a period of time
- used to restore the master file
COBOL Specifics for Relative Files
ACCESS IS RANDOM
ORGANIZATION IS RELATIVE or SEQUENTIAL or DYNAMIC
RELATIVE KEY IS data-field
- Data Division -
The Relative Key field must be a numeric integer,
.. PIC
9(5) for example.
- Procedure Division
- For Random access Reading
- READ file-name INVALID KEY imperative statements.
- For Sequential Access Reading
- READ file-name AT END imperative statements.
- START file-name INVALID KEY imperative statements
- For Sequential access Writing
- For Random access writing
- WRITE OUTPUT-RECORD INVALID KEY imperative statements.
- The OPEN verb can now be used with I-O for DYNAMIC
access. Meaning you will process the file as INPUT and
OUTPUT without closing and reopening the file.
- For DYNAMIC the sequential read must have the NEXT
RECORD keyword
- For an existing record to update REWRITE record-name.
For DYNAMIC writes of a new master record you must use
the REWRITE verb because COBOL has formatted the
file with dummy records.
- To remove a record DELETE record-name RECORD.