COBOL-Master file-Transaction file. Many interviews these questions are asked in COBOL, transaction file and master file. Easy ideas I have given for your sure success in your interviews.
Master files contain the entire data of a particular application. For example, a master file may contain the entire data about the employees, payroll, or other applications of a company.
Although the data stored in master files is permanent to some extent, there may be some random changes in this data.
These changes are grouped together and stored in a file called the transaction file.
The transaction file contains information about all the transactions that have to be applied on the data stored in the master file.
For example, the Employee file containing information about all the employees of a company is a master file.
When new employees join the company or some employees leave the company, the information in the Employee file needs to be updated.
Instead of applying these changes on the master file, they can be grouped together in a transaction file and applied on the master file together as a batch.
A transaction file is also a sequential file, which can be ordered or unordered. This file can contain three types of operations that can be applied to the master file:
- Inserting records
- Modifying records
- Deleting records
- If both the master and transaction files are unordered, inserting records at the end of the file is the only operation that can be performed on the master file. This is done by opening the master file in EXTEND mode, reading the records from the transaction file, and writing the records to the master file.
- If both the master and transaction files are ordered, the operations can either be applied in the master file or a master file can be created.
- If all the operations in the transaction file are related to modifying existing data in the records in the master file, there is no need to create a master file. In this case, the master file is opened in I/O mode, the record to be modified is read, the operations are performed, and the record is rewritten in place.
- It is not possible to add or delete records from the file because insertion or deletion cannot take place between an ordered set of records. To solve this problem, the concept of a new master file is used. In this case, any operation from the transaction file requires three files: the old master file, the transaction file, and the new master file. The old master file and the transaction file are opened in input mode. After all the operations are performed, the new master file is generated.
- If the master file is ordered and the transaction file is unordered, the transaction file also has to be sorted in the order of the key field of the master file. Then, the sorted transaction file can be read and the operations can be performed on the master file.
- If the master file is unordered and the transaction file is ordered, the master file can be sorted on the key field, which is unique for each record. Then, the operations can be performed and the updated file can be obtained.
Comments are closed.