Different types of files in cobol
In fixed length file, size of all records must be same but in variable length file record length can be vary upon some fields which are not common. Files are further classified into 3 types. Sequential files: The records are stored in the file in the same order in which they are entered.
Here, the records can be accessed only sequentially. To process any record, one has to read all its preceding records. Further, records cannot be inserted or deleted. Sequential files are simplest to handle, they are highly inflexible as they do not facilitate insertion and deletion of records.
File opened with Extend Mode appends the writing records at the end of the file. An index sequential file is concep- tually made up of two files, a data file and an index file. Though the records are stored in the order in which they are entered, a sorted index is maintained which relates the key value to the position of the record in the file and hence provides a way to access the records both sequentially and randomly.
When the access mode is sequential, the method of record retrieval changes as per the selected file organization. For indexed files , records are accessed according to the value placed in a key field which can be primary or alternate key. There can be one or more alternate indexes. Dynamic access supports both sequential and random access in the same program. With dynamic access, one file definition is used to perform both sequential and random processing like accessing some records in sequential order and other records by their keys.
A new record is always inserted at the end of the file. After placing a record into a sequential file, it is not possible to delete, shorten, or lengthen a record. Updation of record is possible. A record can be overwritten, if the new record length is same as the old record length. An indexed sequential file consists of records that can be accessed sequentially. Direct access is also possible. Records can be accessed randomly if the primary key is known. Index file is used to get the address of a record and then the record is fetched from the data file.
Sorted index is maintained in this file system which relates the key value to the position of the record in the file.
0コメント