Wolmer’s Trust High School for Girls

INFORMATION TECHNOLOGY (GENERAL PROFICIENCY)

 

Grade: 11                                                              Teacher:  Mrs. McCallum-Rodney

 

File Organization for Sequential and Direct Access Files

 

Files can be manipulated by:

  • Adding records
  • Deleting records
  • Modifying records

 

SEQUENTIAL FILE ORGANIZATION

·         In this file organization, the records of the file are stored one after another both physically and logically. That is, record with sequence number 16 is located just after the 15th record.

·         A record of a sequential file can only be accessed by reading all the previous records.

·         The records are discriminated from one another using the record length declared. For example, if the record structure that the programmer has declared is 52 bytes, blocks of 52 byte data (records) are assumed to be placed one after another in the file. If the programmer is reading the data in a sequential file, every READ statement brings 52 bytes into the memory. 

·         If the file contains, say, 52 byte records; but the programmer tries to read this file with a program which has declared 40 byte records (i.e the total length of the structure is 40 bytes), the program will certainly read some pieces of information into the memory but after the first READ statement, some meaningless pieces of records will be brought into memory and the program will start processing some physical records which contain logically meaningless data.

·         It is the programmer's responsibility to take care of the record sizes in files. You must be careful when declaring record structures for files. Any mistake you make in record sizes will cause your program to read/write erroneous information. This is especially dangerous if the file contents are being altered (changed, updated).

·         Like all files, sequential and line sequential files must be OPENed before they can be processed and CLOSEd when they are not needed anymore.

Sequential and Line Sequential files can be opened for:

1.      OUTPUT

2.      INPUT

3.      EXTEND

4.      I-O (Input-Output)

 

Opening a sequential file for OUTPUT means that the program will only issue WRITE statements to a NON-EXISTING and JUST CREATED file. Therefore, when you open a file for OUTPUT, COBOL assumes that the file does not exist and try to create a new one. IF THE FILE EXISTS, ITS CONTENTS WILL BE CLEARED WHEN OPENED AND ASSUMED TO BE A BRAND NEW FILE INTO WHICH RECORDS WILL BE ADDED. You should be very careful when opening a file for OUTPUT. One small mistake and all your valuable records are lost forever.

Opening a sequential file for INPUT means that the program will only issue READ statements to an EXISTING file. Therefore, when you open a file for INPUT, COBOL assumes that the file exists and tries to access it. IF THE FILE DOES NOT EXIST, AN ERROR MESSAGE WILL BE ISSUED INDICATING THAT THE MENTIONED FILE COULD NOT BE FOUND.

Opening a sequential file for EXTEND means that the program will add NEW RECORDS to an EXISTING file. Therefore, when you open a file for EXTEND, COBOL assumes that the file exists and subsequent WRITE statements will try to ADD NEW RECORDS at the end of the existing file (in other words; the append mode). Records can only be added to the END of a sequential file.

DELETING RECORDS OF A SEQUENTIAL FILE

It is NOT possible to delete records of a sequential file. If you do not want a specific record to be kept in a sequential file any more, all you can do is to modify the contents of the record so that it contains some special values that your program will recognize as deleted (remember to open the file in I-O mode and REWRITE a new record).

ADVANTAGES of SEQUENTIAL FILES

  1. Very easy to process,
  2. Can be easily shared with other applications developed using different programming languages,

DISADVANTAGE of SEQUENTIAL FILES

Sequential files can be only processed sequentially. If you need to read record number N, you must first read the previous N-1 records; especially no good for programs that make frequent searches in the file.

 

DIRECT ACCESS FILE ORGANIZATION

·         The alternative access method is direct-access which allows records to be read and written in any order.

·         Most systems only permit this for files stored on random-access devices such as discs; it is sometimes also permitted on tapes.

·         All records in a direct-access file must be the same length so that the system can compute the location of a record from its record number. The record length has to be chosen when the file is created and (on most systems) is then fixed for the life of the file.

·         In Fortran, direct-access records are numbered from one upwards; each READ or WRITE statement specifies the record number at which the transfer starts.

·         Records may be written to a direct-access file in any order. Any record can be read provided that it exists, i.e. it has been written at some time since the file was created. Once a record has been written there is no way of deleting it, but its contents can be updated, i.e. replaced, at any time.

·         A few primitive operating systems require the maximum length of a direct-access file to be specified when the file is created; this is not necessary in systems which comply fully with the Fortran Standard.

 

Make a Free Website with Yola.