Tuesday, May 19, 2009

features/advantages/disadvantages of various file organisations in COBOL

Compare and contrast the features/advantages/disadvantages of various file organisations in COBOL? Suggest an application for each file organisation. Create a Relative file for the following input records (Write the Program. Make suitable assumptions, if needed).

Input File:

File Name: client_details
Organisation: Relative
File Format:
1-10 Client Code
11-35 Client name
36-50 Client Phone
51-70 Business Volume
71-72 Status (Project is On, Project is over, Negotiation for project is on, Clients having bad track record etc.)
73-80 Not used

The created relative file should be used for the following searching:
To ascertain the status of a client, prior to a project negotiation.
To display the contact phone of a client.

Write the COBOL program for the above.




There are three types of file organizations in COBOL:
(i) Sequential file organisation
(ii) Index Sequential file organization
(iii) Relative file organization


Sequential file organization
In sequential file organization, records are arranged sequentially. A sequential file is a file whose records can be accessed on the order of their appearance in the file. The order in which the records are stored is determined by the order in which they are written when the file was prepared. This order does not charge. Records may be added at the end of file only. The records may be accessed in the order on which they were originally written into a file. A magnetic tape file, such as printer, can only have a sequential organization. A sequentially organized file may be stored on either a serial –access or direct access storage medium. The task of file handling is the responsibility of the system software known as Input-output Control System (IOCS). Block is used to group a number of consecutive records. IOCS takes care of blocking. IOCS reserves a memory space equal to the size of a block of the file.

Advantages of sequential file organization: -
(i) Simple to implement
(ii) Requires very low software support
(iii) Efficiency of blocking is good
(iv) Blocking results in saving in terms of input-output time required handling a file.
(v) A substantial amount of storage space on the disk can be saved.

Disadvantages of sequential file organization: -
(i) Updates are not easily accommodated
(ii) Random access is not possible
(iii) All records must be structurally identical, if a new field has to be added, and then every record must be rewritten to provide space for the new field.
(iv) Continuous areas may not be possible because both the primary data file and the transaction file must be looked during merging.

Area of Use: -
Sequential files are most frequently used in commercial batch oriented data processing applications where there is the concept of a master file to which details are added periodically. Example: - Payroll applications.

Index Sequential file organization: -
When there is need to access records sequentially by some key value and also to access records directly by the same key value, the collection of records may be organized in an effective manner called index sequential file organization. In index sequential file organization, the records are stored in the key sequence order usually in ascending order. Some index tables are also created and maintained with the file. Index table provide to identify the groups of records in the file. When an indexed file is accessed randomly, the programmers control the sequence on which the records are accessed by specifying the value of a data item called record key. When the new records are inserted in the data file, the sequence of records needs to be preserved and also the index is accordingly updated.

Advantage of index sequential file organization:
1. In indexed sequential file organization, the item in the table can be examined sequentially if all the records in the file must be accessed.
2. Indexed sequential file organization is very useful when a random access or records by specifying the key is required.
3. Updating is easily accommodated.
4. Random access is possible.

Area of use: -
Index sequential file organization support applications that selectively access individual records rather than searching thru the entire collection in sequence.
Example- Train Enquiry System, Reservation Enquiry System.

Relative file Organization: -
A relative file is organized in such a way that a relative record number identifies each record. The relative record number specifies the position of the record from the beginning of the file. A relative file may be accessed sequentially. randomly and dynamically . In sequential access, records are accessed in order of ascending relative record numbers. In random access, the programmer must specify relative record number. In dynamic, both random and sequential access modes may be intermixed.

Advantages of Relative File Organization: -
(i) A relative file may be accessed sequentially randomly or dynamically.
(ii) It organizes data when there is a need to access individual records directly.
(iii) Updating is easily accommodated.
(iv) Processing efficiency is high.

Disadvantages of relative file organization: -
(i) In most applications it may be difficult to specify the relative record position. For example if we wish to read the record corresponding to the employee number sw1073 in the personnel file. If the file has a relative organization, knowledge of the employee number sw1073 is not good enough to read the desired record.
(ii) In the case when have to access the records randomly and want to identify them by the value of the key, rather than the relative record number, then relative file organization is not suitable.

Area of Use: - Relative file organization is used where the records of a file are updated for a number of times during a working day. Price list can be a file, which is to be constantly interrogated during a billing run.

*THIS PROGRAM IS USED TO CREATE A RELATIVE TO INPUT RECORDS.
IDENTIFICATION DIVISION.
PROGRAM-ID. QUESTION-1 PART-1.
AUTHOR GYAN AND CHANDRA.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT CL-FILE ASSIGN TO DISK
ORGANIZATION IS RELATIVE
ACCESS MODE IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD CL-FILE
LABEL RECORDS ARE STANDARD
VALUE OF FILE ID “CLIENT.TXT”.
01 CLIENT-DETAILS.
02 CLIENT-CODE PIC Z(10).
02 CNAME PIC X(25).
02 CPHONE PIC Z(15).
02 BUS-VOL PIC X(20).
02 STAT PIC X(2).
02 FILLER PIC X(8).
PROCEDURE DIVISION.
MAIN-PARA.
OPEN OUTPUT CL-FILE.
DISPLAY “ ENTER CLIENT DETAILS”.
DISPLAY “ ----------------------------------”.
PERFORM PROCESS-PARA 5 TIMES.
CLOSE CL-FILE.
STOP RUN.
PROCESS PARA.
DISPLAY “CLIENT CODE:”.
ACCEPT CLIENT-CODE.
DISPLAY “CLIENT NAME:”.
ACCEPT CNAME.
DISPLAY “CLIENT CONTACT PHONE NUMBER:”.
ACCEPT CPHONE.
DISPLAY “CLIENT BUSINESS VOLUME:”.
ACCEPT BUS-VOL.
DISPLAY “CLIENT PROJECT STATUS:”.
ACCEPT STAT.
WRITE CLIENT-DETAILS.

5 comments: