Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

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.

15 questions: 4 warm-ups and 11 with model answers · Levels: Fresher to staff

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher to mid

    What is a copybook, and how does cobc find one?

    Answered in the lesson Copybooks, COPY ... REPLACING and REPLACE

  2. 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

  3. 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

  4. Fresher to mid

    When would you write a user-defined function rather than a called subprogram?

    Answered in the lesson User-defined functions and calling C

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. 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

    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.

    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
  2. 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

    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
  3. 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

    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
  4. 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

    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
  5. 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

    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
  6. 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

    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
  7. 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

    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
  8. 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

    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
  9. 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

    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
  10. 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

    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
  11. 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

    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

All COBOL interview questions · The COBOL track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.