COBOL Module 7
Sequential files and the classic batch patterns interview questions
Interview questions on sequential files and the classic batch patterns: warm-ups, then what each harder question tests and how a good answer starts.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
Why do COBOL programs read a sequential file with a priming READ?
Answered in the lesson Sequential files, records and FILE STATUS
-
Fresher to mid
What do WRITE ... AFTER ADVANCING 2 LINES and WRITE ... AFTER ADVANCING PAGE do?
Answered in the lesson Printed reports: headings, pages and Report Writer
-
Fresher to mid
What is a control break, and why does a control-break program need sorted input?
Answered in the lesson Control-break processing with subtotals
-
Fresher to mid
What does WITH DUPLICATES IN ORDER do in a COBOL SORT, and when does it matter?
Answered in the lesson SORT and MERGE: input and output procedures
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Fresher to mid
A nightly program checks FILE STATUS only after its OPEN. One night an upstream change made some transaction lines longer than the 32-byte record. The run ended with return code 0 and its totals were wrong. What happened, and how should the program check its statuses?
- What it tests
- Knowing that every statement sets FILE STATUS, that a 0x code such as 06 is not plain success for a reader, and writing a rule for every status a READ can return.
- First step
- Work out what each READ returned for a long line. In the lesson, GnuCOBOL 3.2 gave status 06 for the first 32 bytes and returned the rest of the line as another record with status 00, which a program that never looks at the status adds up as one more transaction.
- Follow-ups
-
- Why did the run end with return code 0?
- Which statuses should end the run, and with which return code?
- How would a test have caught it before production?
From the lesson Sequential files, records and FILE STATUS
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A team copies a fixed-length extract with packed decimal balances from z/OS to a Linux server and reads it in GnuCOBOL as a LINE SEQUENTIAL file. Some READs return odd statuses and others give wrong balances. Explain what is going on and how you would read the file correctly.
- What it tests
- Telling text files from record files, seeing why packed bytes break a newline-delimited file, and choosing the organization, the record length and the transfer for a binary extract.
- First step
- Look at the bytes, not the text: dump one record with xxd and compare it with the copybook. A packed balance is binary data, so a line sequential reader can take one of its bytes for the end of a record, and GnuCOBOL also checks such data: in the lesson, writing a packed balance to a line sequential file failed with status 71.
- Follow-ups
-
- Which ORGANIZATION and record length would you use?
- What does a text-mode transfer do to the packed fields?
- How do you prove the file was read correctly?
From the lesson Sequential files, records and FILE STATUS
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A listing prints every detail line correctly, but its record count and amount total at the end are far too small. Each detail line is written by a WRITE with an AT END-OF-PAGE phrase that writes the next page's title. Nobody changed the totalling code. Where do you look, and how do you prove the cause?
- What it tests
- Reading the scope of conditional phrases and scope terminators in nested statements, and proving which statements run for which records.
- First step
- Compare the count the program printed with the number of detail lines in the report, then with the number of page breaks. If the count matches the page breaks, the totalling statements run only when a page ends, so read which statement each terminator and period of that paragraph really closes.
- Follow-ups
-
- Why did the compiler not warn?
- How do you rewrite the paragraph so it cannot happen again?
- Which test would have caught it?
From the lesson Printed reports: headings, pages and Report Writer
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
Users of a daily report complain about two things: some days the report ends with a page that has only headings and totals, and on days without transactions the report has totals but no headings at all. Explain both and redesign the page logic.
- What it tests
- Placing the page test relative to the WRITE, handling the first page and an empty input on purpose, and choosing the inputs that test page logic.
- First step
- Establish which input sizes give each symptom: run the report on inputs that end exactly at the end of a page, one line after it, and on an empty file, and see when the program decides to start a page compared with when it knows there is a line to print.
- Follow-ups
-
- Where exactly should the page test sit?
- What should an empty day print, and why?
- Which inputs belong in the regression tests?
From the lesson Printed reports: headings, pages and Report Writer
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
A suite of report programs written with Report Writer builds and runs with GnuCOBOL. They must now build and run with IBM Enterprise COBOL on z/OS, with the same reports. What do you check, what are your options, and how do you prove the reports did not change?
- What it tests
- Knowing where Report Writer can be compiled, choosing how to move a REPORT SECTION, and proving that report output stays the same across compilers and platforms.
- First step
- Establish first whether the target compiler accepts a REPORT SECTION at all, and freeze today's output of every report for a set of inputs, including an empty one and one that ends on a page boundary, as the expected results of the move.
- Follow-ups
-
- When would you rewrite instead of keeping Report Writer?
- What can differ in the output files between the two platforms?
- How do you compare reports that have page breaks?
From the lesson Printed reports: headings, pages and Report Writer
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
After a tidy-up of a branch and region report, the last branch and the last region of every run no longer print, and the grand total is lower than the day's deposits by exactly their amount. Every other total is right. What happened, and how do you fix and test it?
- What it tests
- Knowing that the last group of a file is closed only by a final break after the read loop, and testing the end of the file and an empty file on purpose.
- First step
- Compare the grand total with the sum of the input deposits and find which groups are missing. When it is always the groups at the end of the file, look at what the program does after its read loop ends, because no next record will ever close them.
- Follow-ups
-
- Why is every other total still right?
- What must the final break do on an empty file?
- Which test input catches it at once?
From the lesson Control-break processing with subtotals
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Mid to senior
Two regional managers report that their region totals are wrong by the same amount in opposite directions: one too low, the next one too high. The grand total agrees with the day's deposits. What kind of bug is this, how do you find it, and how do you test for it?
- What it tests
- Recognising a total rolled into the wrong level, knowing why cross-footing cannot see it, and testing each level against figures that do not come from the report.
- First step
- Find the amount by which each region is off and which group it matches: if it equals the total of the last branch of the region that came out too low, follow what the program does at a change of region, in the order it does it.
- Follow-ups
-
- Why does the grand total still balance?
- Which check would have caught it?
- How do you keep the order right when a third level is added?
From the lesson Control-break processing with subtotals
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Senior to staff
Operations want the nightly deposits report by region and branch to prove itself before the next job step runs. Design the checks the program makes and the return codes it ends with, and say which problems each check can and cannot catch.
- What it tests
- Designing control totals, sequence checks and trailer reconciliation for a batch report, with return codes that a job's later steps can act on.
- First step
- List what can go wrong between the sender and the printed report: records lost or added in transfer, records out of order, an empty day, a damaged file and mistakes in the program's own break logic. Give each one a check whose figures do not come from the report itself.
- Follow-ups
-
- What does the sender have to provide?
- Which return code for which result, and why?
- What can none of these checks catch?
From the lesson Control-break processing with subtotals
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A customer closed an account and opened a new one with the same number on the same day. The night's update rejected the opening as already on the main file, and the next morning the account was gone altogether. Explain what the update did, fix it, and say how rules like this should be decided.
- What it tests
- Applying several transactions for one key in order, keeping the account's state between them, and separating business rules from the update's mechanics.
- First step
- Write down the state of the account after each of its transactions: after the close it no longer exists. Then ask what the program compared the opening with at that moment, and whether it can handle more than one transaction for an account at all.
- Follow-ups
-
- Why did the account disappear instead of staying open?
- Which other combinations of transactions go wrong the same way?
- Who decides whether an open may follow a close?
From the lesson Balanced-line update of a main file
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
The nightly update of the savings main file ended with its control totals out of balance by 1,250.00, and its error report is empty. What can cause it, how do you find the cause, and what happens to tonight's new main file?
- What it tests
- Using the control-total equation to locate an error, reading the audit trail against the new file, and knowing which result may replace the old main file.
- First step
- Write the equation with the run's own figures, the old total plus adds minus deletes plus changes against the new file's total, and find the term that 1,250.00 matches. Then compare the audit trail, the transactions and the new file account by account for that kind of transaction.
- Follow-ups
-
- Which bugs produce exactly one transaction's amount as the difference?
- Can the totals balance while the file is still wrong?
- Who may release the run, and on what evidence?
From the lesson Balanced-line update of a main file
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
An update job failed in the middle of the night because its transaction file was out of order. Operations ask whether they must restore the main file from a backup before they restart. What do you tell them, and how should the job be built so that the answer is always simple?
- What it tests
- Designing batch updates that never change their input, return codes that tell operations what to do, and the use of generation data groups for old and new files on z/OS.
- First step
- Check whether the update changes the main file in place or writes a new one. If it only reads the old file, the old file is intact and the restart is a sorted input and the same run again; if it updates in place, the answer depends on how far it got.
- Follow-ups
-
- What should happen to the half-written new file?
- How do generation data groups help?
- What would make a rerun give a different result?
From the lesson Balanced-line update of a main file
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
After the nightly sort step moved to a different sort product, the update that follows it began rejecting some withdrawals as below zero, although the customers had deposited the money first. The sort's only key is the account. What happened, and how do you fix it so that it cannot happen again?
- What it tests
- Knowing that equal keys have no defined order unless asked for, seeing how that order reaches a balanced-line update, and making the order explicit.
- First step
- Look at the sort's keys and its DUPLICATES phrase. With the account as the only key, every transaction of one account is a tie, and their order is whatever the sort product chooses unless the sort is asked to keep the input order.
- Follow-ups
-
- Why did it work before the change?
- Which is better: WITH DUPLICATES IN ORDER or a sequence number key?
- How do you test that the order is kept?
From the lesson SORT and MERGE: input and output procedures
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A file sorted on z/OS by product code is copied to a Linux server, converted to ASCII and read by a GnuCOBOL control-break program with a sequence check. On its first night the program stops with records out of order. The codes mix letters and digits. Explain what happened and give two fixes.
- What it tests
- Knowing that EBCDIC and ASCII order letters and digits differently, and choosing between sorting again and comparing in the original collating sequence.
- First step
- Find the first pair of records the check called out of order and compare their codes character by character. Then establish in which collating sequence the file was sorted, and in which one the program compares its keys.
- Follow-ups
-
- Which fix would you choose, and why?
- Would a numeric key have the same problem?
- What else in the file can change when it moves platforms?
From the lesson SORT and MERGE: input and output procedures
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
A monthly report lists the debits of 10,000.00 or more by branch, from a file of 40 million transactions of which about 2 % qualify. A colleague sorts the whole file and filters afterwards. How would you design the sort step, and what do you expect it to change?
- What it tests
- Choosing between filtering before and after a sort, estimating the effect on the sort's work, and keeping the result checkable.
- First step
- Work out how many records the sort really needs: about 2 % of 40 million is 800,000. Then compare the work of sorting 40 million records with sorting 800,000, and decide which end of the sort can do the filtering and the totalling.
- Follow-ups
-
- What do you put in the input and output procedures?
- How much less work does the sort do, roughly?
- How do you prove the report did not lose qualifying records?
From the lesson SORT and MERGE: input and output procedures
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 2 minutes