Data Files
In this section we are going to discuss what a flat file looks like. Later sections will show specific program functions that will let you open and close flat data files and write data to the files you create. First, we will examine how files are built up. Then we will look at details of creating files and writing data to files in some popular programs. In order to manipulate data as described earlier you will need to understand some basic facts about how files can be constructed.
In particular, you'll need to know the following.
Data files stored as text files (a txt extension in DOS/Windows systems) are stored as a sequence of characters. Every character is stored as a single byte of data. You know that a byte can store a number from 0 to 255. Every character on the keyboard has a numerical representation. There is a standard code for character representations. That code is the American Standard Code for Information Interchange, that is ASCII, and that is pronounced "Ask-ee". When you strike a key on the keyboard, the ASCII code for that key is what is transmitted to your computer. Maybe the most important item on the list above is that every character is stored in a byte in a file. If you have that concept, then you can compute.
how much information can be stored on a disk.
- Let's just take a single megabyte (1MB). That's one million (1,000,000) bytes.
- Disks can store more than that. Floppies can store 1.44 MB and hard drives can store many gigabytes (A gigabyte is one billion bytes.)
- If we can figure out how much you can get in a megabyte you can figure out how much you can get on a floppy or a hard disk.
As this is written, I'm reading a book.
- By my count it had about 2500 characters on a random page I picked.
- That means it would take 2500 bytes to store the text on a single page.
- By that count, one megabyte could store 400 pages (2500 bytes/page x 400 pages = 1,000,000 bytes)
- The particular book I was reading has only 267 pages, so the entire book could fit on a single floppy disk.
You can store a large amount of data even on a single floppy disk. Now, there are higher density disks that hold 100 megabytes or 250 megabytes, so consider these problems.
Example - How many 267-page books will fit on a 100-megabyte disk?
- Assume 2500 characters per page, or 2500 bytes per page.
- 2500 x 267 = 667,500 bytes/book 0r .6675 megabytes/book
- Therefore, the number of books is 100/.6675 = 149.8. Let's call it 149 books, or even 150.
- That's a lot easier than carrying the hard copy version in a backpack.
Data Type and Organization
- Identify different data types:
- logical / Boolean
- alphanumeric / text
- numeric (real and integer)
- date
- Select appropriate data types for a given set of data: logical/Boolean, alphanumeric/text, numeric and date;
- Describe what is meant by the terms
- file
- record
- field
- key field
- Describe different database structures such as
- flat files
- relational tables
- relationships
- primary keys
- foreign keys;
- State the difference between analogue data and digital data;
- Explain the need for conversion between analogue and digital data.
Define Master and Transaction file
Master File
A master file is a file used as a reference for a particular computer application. It may be updated when necessary. E.g. a file holds details of the goods stored by a chain of food shops. Each record consists of product code, name of goods, price minimum number to be held in stock. This file is the master file. Master file holds descriptive data; the actual data that is supposed to be processed and holds the resultant data after the process is completed (ex. names, addresses, sales, etc.). The data can be organized using keys.
- Permanent collection of data against which transactions are usually processed.
- Will contain REFERENCE and DYNAMIC data. Reference data tends to be relatively permanent (occasional or infrequent changes are made: insertion of new records, deletions or alterations) and is processed by AMENDING. Dynamic data is data which changes frequently and is processed by UPDATING.
- Usually have some order to the way records are stored: use the RECORD KEY.
For example, a HOTEL FILE will contain both reference and dynamic data:
- Reference Data - Items of data describing the rooms: type, size, number of beds, sea view…, which will rarely change.
- Dynamic Data - Items of data describing the guest: name, length of stay, special requirements…. Which will change frequently, perhaps every day?
Transaction File
A transaction file is a file of temporary data, which has been prepared in order to carry out a processing operation with the data on a master file. Usually, the transaction file is being used to update the master file e.g. the file is prepared containing product code and new price for some of the goods on the master file. This is the transaction file and it is used to update the prices on the master file. Transaction file Contains the transactions; changes that are supposed to be made to the data in the master file. In batch processing all transactions are collected in the transaction file and the changes are applied to the master file sequentially in a single pass. For this to be possible, both the master and transaction file have to be sorted first. In an online system the changes are applied to the master file the moment the transactions occur or are recorded.
Key - Unique identifier for a record.
- Temporary collection of data used to change information on a master file.
- Contains only that information which is needed to identify a record in the master file and make the necessary changes.
- The records may not be in any order at all: either SERIAL or SEQUENTIAL ordering is normal.
- Once used the transaction file may be deleted.
For example,
- A company will hold a PAYROLL file. Each week information about employees will need to be processed. What data would the transaction file contain?
- Employee number (to identify the employee’s record in the master file), weekly pay, days off sick, new employee, employee left the company….
Algorithm to update the Master file
- Order transaction file by key.
- Create new master file.
- Compare first keys in master file to first key in transaction file.
- Continue this until end of both master and transaction file.
- Apply any changes defined by the transaction file to the record.
- Write the record with the lowest key to the new master file.
- Go to the next record in the original master file and the transaction file.
- Compare keys as in step 3.
- Close all files.



0 Comments