Direct Access to Files in Cobol

Only available on StudyMode
  • Topic: File system, Computer file, NTFS
  • Pages : 9 (2969 words )
  • Download(s) : 355
  • Published : February 27, 2013
Open Document
Text Preview
|
| | |
 | | |
 | | |
 | | |
 | | |

Introduction|
Aims| The aim of this unit is to provide a gentle introduction to COBOL's direct access file organizations and to equip you with a knowledge of the advantages and disadvantages of each type of organization.| Objectives| By the end of this unit you should: 1. Have a good understanding of the drawbacks of inserting, deleting and amending records in an ordered Sequential file.  2. Have a basic knowledge of how Relative and Indexed files are organized.  3. Understand the advantages and disadvantages of the different file organizations.  4. Be able to choose the appropriate file organization for a particular set of circumstances .| Prerequisites| You should be familiar with the material covered in the unit; * Sequential Files  |

|

Sequential files|
Introduction| Access to records in a Sequential file is serial. To reach a particular record, all the preceding records must be read.As we observed when the topic was introduced earlier in the course, the organization of an unordered Sequential file means it is only practical to read records from the file and add records to the end of the file (OPEN..EXTEND). It is not practical to delete or update records.While it is possible to delete, update and insert records in an ordered Sequential file, these operations have some drawbacks.| Problems accessing ordered Sequential files.| Records in an ordered Sequential file are arranged, in order, on some key field or fields. When we want to insert,delete or amend a record we must preserve the ordering. The only way to do this is to create a new file. In the case of an insertion or update, the new file will contain the inserted or updated record. In the case of a deletion, the deleted record will be missing from the new file.The main drawback to inserting, deleting or amending records in an ordered Sequential file is that the entire file must be read and then the records written to a new file. Since disk access is one of the slowest things we can do in computing this is very wasteful of computer time when only a few records are involved.For instance, if 10 records are to be inserted into a 10,000 record file, then 10,000 records will have to be read from the old file and 10,010 written to the new file. The average time to insert a new record will thus be very great. | Contrast with direct access files| While Sequential files have a number of advantages over other types of file organization (and these are discussed fully in the final section) the fact that a new file must be created when we delete, update or insert a records causes problems.These problems are addressed by direct access files. Direct access files allow us to read, update, delete and insert individual records, in situ, using a key.| Inserting records in an ordered Sequential file| To insert a record in an ordered Sequential file: 1. All the records with a key value less than the record to be inserted must be read and then written to the new file. 2. Then the record to be inserted must be written to the new file. 3. Finally, the remaining records must be written to the new file.| Deleting records from an ordered Sequential file| To delete a record in an ordered Sequential file: 1. All the records with a key value less than the record to be deleted must be written to the new file. 2. When the record to be deleted is encountered it is not written to the new file. 3. Finally, all the remaining records must be written to the new file.| Amending records in an ordered Sequential file| To amend a record in an ordered Sequential file: 1. All the records with a key value less than the record to be amended must be read and then written to the new file. 2. Then the record to be amended must be read the amendments applied to it and the amended record must then be written to the new file. 3. Finally, all the remaining records must be written to the...
tracking img