COBOL Module 10
Copybooks, subprograms and interoperability interview questions
Interview questions on copybooks, subprograms and interoperability: 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
What is a copybook, and how does cobc find one?
Answered in the lesson Copybooks, COPY ... REPLACING and REPLACE
-
Fresher to mid
What is the difference between passing an argument BY REFERENCE and BY CONTENT?
Answered in the lesson CALL, the LINKAGE SECTION and return codes
-
Fresher to mid
What is the difference between WORKING-STORAGE and LOCAL-STORAGE in a called program?
Answered in the lesson Storage lifetimes, recursion and nested programs
-
Fresher to mid
When would you write a user-defined function rather than a called subprogram?
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to senior
The customer name in a copybook that 40 programs copy must grow from 20 to 30 bytes, and the programs pass customer records to each other through files. How do you plan the change and roll it out?
- What it tests
- Treating a copybook as an interface: finding every program that uses it, keeping writers and readers of a record layout in step, and releasing them together.
- First step
- List every program whose build reads the copybook, from dependency lists written by cobc -MT and -MF rather than a grep of program sources, and every file whose records it describes. A name 10 bytes wider moves every field after it, so the programs that write and read those files must change in one release, or the files must be converted.
- Follow-ups
-
- Three of the programs cannot be released this month. What then?
- How do you show that nothing else changed?
- What about records already stored in the old layout?
From the lesson Copybooks, COPY ... REPLACING and REPLACE
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; nothing renews unless you choose to. 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 program must hold an input and an output copy of a customer record, and the shared copybook has no tag. Copying it twice fails with 'CUST-ID' is ambiguous. What are your options, and which do you choose?
- What it tests
- COPY ... REPLACING with whole names, with LEADING and with a tag, how each can go wrong, and how to check what a COPY produced.
- First step
- Ask whether the copybook may change. If it may, add a tag such as :PFX: and copy it with REPLACING ==:PFX:== BY ==IN== and BY ==OUT==. If it may not, remember that LEADING ==CUST== also renamed CUSTOMER-TYPE to PREVOMER-TYPE in the lesson, so list whole names or check the copies with cobc -E.
- Follow-ups
-
- Why not use REPLACE instead of REPLACING?
- How do you check what each copy produced?
- The copybook copies another copybook. What changes?
From the lesson Copybooks, COPY ... REPLACING and REPLACE
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Mid to senior
A batch step handled every record correctly, yet it ends with return code 8 and the job skips its next steps. The main program never sets RETURN-CODE, but it calls a validation subprogram for every record. What happened, and how do you fix it?
- What it tests
- Knowing that RETURN-CODE comes back from every call and that its last value becomes the step's return code, and designing the status a run reports on purpose.
- First step
- Find every program that can write RETURN-CODE during the run: the main program, and every subprogram it calls, because each return hands the caller the subprogram's value. Then look at the value left there when the main program ends, and at the record that was processed last.
- Follow-ups
-
- How should the main program decide the step's return code?
- Would CALL ... RETURNING avoid the problem?
- How do you test the fix?
From the lesson CALL, the LINKAGE SECTION and return codes
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
After a release, a job step that calls a fee subprogram fails with system completion code 806. The calling program did not change. Where do you look, and how do you keep it from happening again?
- What it tests
- Telling static from dynamic calls, how a dynamically called program is found at run time, and what 806 means.
- First step
- Establish how the call is bound: a CALL of a literal or of an identifier, and the compiler options the caller was built with. Then check that the program it names exists, under exactly that name, in the libraries the step searches, and list what the release renamed, moved or removed.
- Follow-ups
-
- Why did the caller not need to change for this to break?
- How would the same failure look under GnuCOBOL?
- Should the call be made static instead?
From the lesson CALL, the LINKAGE SECTION and return codes
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
An account number in a caller's WORKING-STORAGE changes after a call to a subprogram that never mentions accounts. The run ends normally. How do you find the cause, and what stops it happening again?
- What it tests
- Recognising a LINKAGE item longer than its argument, proving it with a run-time check, and keeping the two sides of an interface in one description.
- First step
- List the CALLs made between the last moment the account number was right and the first moment it was wrong. For each, compare the size of every argument in the caller with the LINKAGE item it lands on, matched by position, and look at what lies in storage right after each argument.
- Follow-ups
-
- Why did nothing fail at compile time?
- Which programs must be built with the check?
- How do you keep the caller and the subprogram from drifting apart again?
From the lesson CALL, the LINKAGE SECTION and return codes
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A subprogram totals a customer's transactions and is called once for each customer. The second customer's total includes the first customer's transactions, and every later total grows the same way. What is wrong, and what are your ways to fix it?
- What it tests
- Knowing which storage keeps its values between calls, and choosing between LOCAL-STORAGE, setting fields at the start of each call, IS INITIAL and CANCEL.
- First step
- Find where the total is declared and where it is set to zero. A total that only ever grows across calls is kept between calls and never cleared at the start of one: look for a VALUE ZERO in WORKING-STORAGE and no MOVE 0 at the top of the procedure.
- Follow-ups
-
- Which fix would you choose, and why?
- The subprogram also caches a table of rates. Does your fix change that?
- How would a test have caught this?
From the lesson Storage lifetimes, recursion and nested programs
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Mid to senior
A recursive program that totals an account hierarchy returns plausible but wrong totals for deep hierarchies, and right ones for flat ones. It never fails. How do you find the cause, and how do you make it right under both GnuCOBOL and IBM's compiler?
- What it tests
- Seeing that the calls of a recursive program share WORKING-STORAGE, finding the fields used after the recursive call, and the RECURSIVE attribute in both dialects.
- First step
- List every field the program reads after its recursive call returns, and check which section declares each one. Then run it on a hierarchy of two levels and of three levels, whose totals you can work out by hand, and compare.
- Follow-ups
-
- Why are the flat hierarchies right?
- Would passing the arguments BY CONTENT fix it?
- What must the source say to build under both compilers?
From the lesson Storage lifetimes, recursion and nested programs
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
To avoid changing 30 CALL statements, a team wants to replace the parameters of its subprograms with one EXTERNAL record of run settings that every program declares. What do you advise, and under what conditions would you accept it?
- What it tests
- Weighing hidden coupling against convenience, the checks EXTERNAL data lacks, and how to keep its layout the same in every program.
- First step
- Separate the run-wide values, such as a run number, which many programs read and few change, from the data each call works on. Then ask what would tell the team, at build or run time, that two programs describe the record differently.
- Follow-ups
-
- What can go wrong that parameters would have caught?
- How would you keep the record the same in all 30 programs?
- How do tests change?
From the lesson Storage lifetimes, recursion and nested programs
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Mid to senior
A COBOL program passes binary counts to a C library function, and the C side sees huge, wrong numbers, although the COBOL fields display correctly. What do you check, and how do you fix the interface?
- What it tests
- Matching COBOL binary usages to C types by size and byte order, and choosing COMP-5 for data shared with C.
- First step
- Print the bytes of one count on the COBOL side with FUNCTION HEX-OF just before the call, and the value C reads just after it. Then compare, item by item, the USAGE and PICTURE of each COBOL field with the C type of its parameter: size first, then byte order.
- Follow-ups
-
- Why do the COBOL fields look right?
- Which usage do you choose, and why?
- The C function takes a struct. What else must match?
From the lesson User-defined functions and calling C
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Fresher to mid
A C function called from COBOL prints a customer name followed by stray characters, and sometimes by the value of another field. What is happening, and how do you fix it on the COBOL side and on the C side?
- What it tests
- Knowing that COBOL text is fixed-length with no terminator, and two ways to give a C function a length.
- First step
- Look at how the C function finds the end of the name. If it reads up to a NUL, ask where that NUL comes from: COBOL passes a PIC X item as a pointer to its bytes, and the C function reads whatever lies after them until it meets a zero byte.
- Follow-ups
-
- Why does it sometimes print another field?
- Which fix belongs in COBOL, and which in C?
- What about trailing spaces?
From the lesson User-defined functions and calling C
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Senior to staff
A C service must reuse a COBOL program that computes fees, without rewriting it. Design how the service calls it, how it learns that a call failed, and how the run ends.
- What it tests
- Calling COBOL from C: starting and ending the runtime, entry points, argument layouts and error handling.
- First step
- Write down the COBOL program's interface exactly: its PROGRAM-ID, the PICTURE and USAGE of every LINKAGE item, and the RETURN-CODE values it sets. The C side then needs one declaration for that entry point, buffers of exactly those layouts, and a rule for each status.
- Follow-ups
-
- What must happen before the first call?
- What if the COBOL program runs STOP RUN or fails?
- How do you build and test it?
From the lesson User-defined functions and calling C
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 2 minutes