File Access Managing Data When records in a file need to be accessed there are three ways of doing it; a) Serial Access This means...start at the beginning of the file and access each record in turn until the one needed is found. If files are stored on magnetic tape then serial access is the only method of access. b) Direct Access The computer can calculate (from the key field) where the record is stored in the file, and can then access the record directly from that position. Direct access of records will generally be much faster than serial access. Direct access can only be used if files are stored on media such as disk, CD, DVD... Direct access is also known as random access c) Sequential Access Sequential file is a file where records are physically stored in a specified order one after the other (according to the key) and they have to be read in that order (in the order in which they are stored on the medium). To read record 10, for example, you would first need to read records 1 through 9. This differs from random access, in which you can read and write records in any order. Tip: Access means Exercise 1: File Access read or write a) of records involves accessing each record in turn. b) is used if the computer can calculate where a record is stored and directly accesses only that record. c) Applications which need fast access to data will need to use File Types Master File A collection of records related to one of the main subjects of an information system, such as customers, employees, products and vendors. Master files contain descriptive data, such as name and address, as well as summary information, such as amount due and year-to-date sales. Transaction File Transaction processing systems are the backbone of an organization because they update constantly. At any given moment, someone may need an inventory balance, an account balance or the total current value of a financial portfolio. Page 1
The data in transaction files is used to update the master files, which contain the data about the subjects of the organization (customers, employees, vendors, etc.). Backup File Duplicate of a file, program, or disk that can be used if the original is lost, damaged, or destroyed Archive File A file that has been saved in a different location than the original for backup purposes. An archive is a collection of files packaged together as a sort of final backup into one compressed file. Do not confuse archiving with regular backups. File Generations When a transaction file is used to update a master file, the process creates a new master file. Sometimes the old master file is referred to as the father file and the new master file as the son file. When the update is next run... the son file becomes the father file, the father file becomes the grandfather file..etc... This is a method for storing previous generations of master file data that are continuously updated. The son is the current file, the father is a copy of the file from the previous cycle, and the grandfather is a copy of the file from the cycle before that one. In practice companies will keep several generations of files. This is because there may be a problem (eg disk crash, fire or theft) and the update runs may have to be done again to re-create the current master file. Old files should therefore be stored away from the computer installation, preferably in a fireproof strong room. The diagram below illustrates how a master file is updated using a transaction file, which has been previously sorted. Page 2
Exercise 2: When a master file is updated, the new master file created is known as the file and the old master file is archived as the file. At each update...the son becomes the father, the father becomes the grandfather etc... Several of master files may be kept for disaster recovery purposes. File Update The data on a transaction file is used to update some of the fields on a master file. The transaction file must be sorted in the same order as the master file. This is generally done in a batch processing system where the transactions are recorded on the transaction file and later used to update the master file. How it works (in words) : 1. A new master file is created. 2. For each transaction record, the records of the master file are read and written onto the new master file until a matching record is found. 3. The data is updated and the record written onto the new master file. 4. When the last transaction record has been processed, the remaining records on the master file are read and written onto the new master file. How it works (System flowchart) : Here, the transaction and master files are stored on magnetic tape and used as input for the update process. All updated (and unaltered) records are stored on the new master file. Example : A master file of stock is kept for a clothes shop. Some of Page 3
the records are shown in this table : ID Garment Price No Sold this year 305 Sweater (Red) 25.00 12 308 Sweater (Blue) 25.00 8 309 Shorts (Size 12) 12.00 14 315 Shorts (Size 14) 12.00 9 316 Socks(Grey) 1.99 34 317 Socks(Black) 1.99 28 Todays transactions are shown in the transaction file below... ID No Sold today 305 3 309 1 316 2 317 1 The key field is the ID field. The master file in practice would have many more fields than this...and many more records! The transaction file must be sorted in the same order as the master file (using the key field) The resulting new master file is shown in the next table : ID Garment Price No Sold this year 305 Sweater (Red) 25.00 15 308 Sweater (Blue) 25.00 8 309 Shorts (Size 12) 12.00 15 315 Shorts (Size 14) 12.00 9 316 Socks(Grey) 1.99 36 317 Socks(Black) 1.99 29 The updated data is shown in this table. Note that some records will have remained unchanged. Exercise 3: The contains all the main data for a system. A contains recent data which is used to update the master file. A is created onto which the updated or unchanged records are written. The old master file can then be archived. The transaction file must be before the update process takes place. Page 4
Common File Operations Sorting Files may be sorted into order of a field. The records are arranged in ascending or descending order (numerically or alphabetically). If records are sorted it is much easier and quicker to find a record. Searching Queries are used to find records which match certain conditions. Simple query - Using one field. Eg (NAME = 'Smith') Complex query - using two or more fields with OR, AND or NOT. Egs (NAME='Smith') AND (BALANCE > 100) (PET='Dog') OR (PET = 'Cat') (PET = 'Dog') AND NOT (Type='Spaniel') Wildcard query - In alphabetical fields * may stand for anything. Eg (NAME = 'Sm*') will include all names starting with Sm - Smith, Smithers, Smedling and so on... Adding new data A new record may be added to a file. Eg A business may start to sell a new brand of item. Deleting data A record may be removed from a file. Eg A business discontinues the selling of an item. Editing data A record in a file may be changed. Eg If the price of an item changes. Page 5