COBOL – Tricky Interview Question

This question you may come across in many interviews. This scenario usually comes in Banking projects/Insurance/Finance projects. You can learn domain knowledge in an easy way.

Question:

How to process 2 files by comparing key field in COBOL?

Also Read | The complete Python Boot camp for all levels

Solution – 1 :

First file you need to read, also read second file. If both key field matches, we can ignore it. Let us say T,M files.
T < M means this is new account so we need to update in the master file
T > M means an account is missing in the Master file, so we need to update it

Solution – 2:

If both files are same number of records. It is good, our work is reduced
If T file comes to AT END we need to move HIGH VALUES into key field
If M files comes to  AT END we need to move HIGH VALUES into key field
So we need to process till both key fields are  equal to HIGH VALUES.

Note: Key fields must be in PIC (X) not numeric

Solution 3:

To avoid lot of I/Os, we can read data into local array table, and we can process the records.

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.