COBOL interview questions and answers for mainframe developers
COBOL interview questions test whether you can read and change the batch programs that still run banks, insurers and government systems: the four divisions, PIC clauses and USAGE (DISPLAY, COMP, COMP-3), level numbers including 88 conditions, tables with SEARCH, sequential and VSAM files with FILE STATUS, and the abends you will be paged for, above all S0C7 and S0C4. Strong candidates explain the data layout in bytes and debug from a dump or a status code, not by guessing.
By Evin JohnPublished 9 min read
Who gets COBOL questions, and how deep
COBOL roles sit in banks, insurance, payments, retail back offices, airlines and public sector agencies, usually on IBM mainframes, and increasingly in teams modernizing those systems. Interviews for experienced developers go straight to data layout and abends, because that is where production problems come from. Fresher and trainee programs focus on syntax and logic and expect you to learn the environment on the job. Most roles also touch JCL for batch, CICS interview questions for online transactions and Db2 interview questions for embedded SQL, so expect at least one question from each.
- Language and dataDivisions, PIC clauses, USAGE, level numbers and how many bytes a field takes. Often rapid-fire.
- Read or write codeTrace a PERFORM loop, find the bug in a table search, or write a file-matching program in pseudocode or real COBOL.
- Production supportAn abend code or a FILE STATUS value, and what you would look at first. This round separates experienced candidates.
- Environment and changeJCL steps, compile and link, testing a change safely, and how the team releases to production.
COBOL fundamentals questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What are the four divisions of a COBOL program? | Structure | IDENTIFICATION (program name), ENVIRONMENT (files and their external names), DATA (all storage, files and parameters) and PROCEDURE (the logic). |
| Which sections can the DATA DIVISION contain? | Storage | FILE SECTION for record layouts, WORKING-STORAGE for program storage that persists across calls, LOCAL-STORAGE for storage fresh on each call, and LINKAGE for data passed in by a caller. |
| What do level numbers 01, 05, 66, 77 and 88 mean? | Data hierarchy | 01 starts a record, 02 to 49 are subordinate fields, 66 RENAMES a range of fields, 77 is a standalone item, and 88 defines a condition name for values of the field above it. |
| What does PIC S9(5)V99 mean? | PIC clause | A signed numeric field with five digits before an implied decimal point and two after. The V takes no storage; the decimal point exists only in how the compiler treats the value. |
| What USAGE types do you know? | Storage formats | DISPLAY (one character per digit, zoned decimal), COMP or BINARY (binary halfword, fullword or doubleword), COMP-3 or PACKED-DECIMAL (two digits per byte), COMP-5 (native binary not truncated to the PIC), COMP-1 and COMP-2 (floating point). |
| Why use 88-level condition names? | Readability | IF ACCOUNT-CLOSED reads better than IF WS-STATUS = 'C', keeps valid values in one place, and SET ACCOUNT-CLOSED TO TRUE moves the right value without repeating the literal. |
| What is the difference between a subscript and an index? | Tables | A subscript is an occurrence number held in an ordinary field. An index holds a displacement, is set with SET and is used by SEARCH; it is usually more efficient. |
| STOP RUN, GOBACK or EXIT PROGRAM? | Ending | STOP RUN ends the whole run unit, even from a subprogram. GOBACK returns to the caller, or ends the run if it is the main program, which makes it the safe default. EXIT PROGRAM returns only from a called program. |
| NEXT SENTENCE versus CONTINUE? | Classic trap | CONTINUE does nothing and carries on after the END-IF. NEXT SENTENCE jumps past the next period, which in code without periods can skip many statements. Interviewers ask it because it causes real bugs. |
| What does INITIALIZE do to a group? | Initialization | Sets alphanumeric and alphabetic fields to spaces and numeric fields to zero, leaving FILLER alone by default. It is not the same as moving spaces to the group, which corrupts numeric fields. |
| What is a copybook? | Reuse | A shared member of source, usually a record layout, brought in with COPY so every program reading a file uses the same definition. REPLACING adapts prefixes when needed. |
Data layout and packed decimal
Byte-level questions are the most common filter for experienced roles. COMP-3 stores two digits per byte with the sign in the last half-byte, so a field takes (digits + 1) / 2 bytes rounded up: PIC S9(7) COMP-3 is four bytes. Binary COMP takes two bytes for up to four digits, four bytes for five to nine, and eight for ten to eighteen. Being able to work the layout out by hand is what lets you read a dump.
from decimal import Decimal
def pack(value: int, digits: int) -> bytes:
sign = 0xD if value < 0 else 0xC
s = str(abs(value)).rjust(digits, "0")
if len(s) > digits:
raise ValueError("does not fit")
nibbles = [int(ch) for ch in s] + [sign]
if len(nibbles) % 2:
nibbles.insert(0, 0) # pad to whole bytes
return bytes(nibbles[i] << 4 | nibbles[i + 1] for i in range(0, len(nibbles), 2))
def unpack(data: bytes, scale: int = 0) -> Decimal:
nibbles = [n for b in data for n in (b >> 4, b & 0xF)]
*digits, sign = nibbles
if any(d > 9 for d in digits) or sign not in (0xC, 0xD, 0xF):
raise ValueError("invalid packed data")
n = int("".join(map(str, digits)))
return Decimal(-n if sign == 0xD else n).scaleb(-scale)
# PIC S9(5)V99 COMP-3: 7 digits, so (7 + 1) / 2 = 4 bytes
raw = pack(-1234567, 7)
print(raw.hex().upper(), len(raw), unpack(raw, scale=2))
# 1234567D 4 -12345.67
try:
unpack(bytes.fromhex("40404040")) # EBCDIC spaces in a numeric field
except ValueError as e:
print(e)
# invalid packed data- Why are spaces in a COMP-3 field a problem? An EBCDIC space is X'40', whose last half-byte is not a valid sign, so arithmetic on it raises a data exception (S0C7). Typical causes: a record moved into a group with spaces, a field never initialized, or a layout mismatch between writer and reader.
- What does REDEFINES do, and what is the risk? It gives the same bytes a second layout, for example a date as one field or as year, month and day. The risk is reading the bytes through the wrong view, such as packed arithmetic on bytes that hold text.
- How does OCCURS DEPENDING ON work? The number of occurrences comes from another field at run time, giving variable-length records or tables. That count field must be set before the table is used, and it should sit before the table in the record.
- What happens when a value is too large for its PIC? High-order digits are truncated silently unless you code ON SIZE ERROR on the arithmetic statement. COMPUTE with ROUNDED and SIZE ERROR is the safe habit for money.
- How is a signed DISPLAY number stored? As zoned decimal, one digit per byte, with the sign carried in the zone half of the last byte. That is why a negative value can print with an odd last character.
- What does the TRUNC compiler option change? How binary COMP fields are truncated to their PIC size. COMP-5 always uses the full binary range, which is why it is preferred for values passed to non-COBOL code.
Logic, tables and files
FILE-CONTROL.
SELECT CUST-FILE ASSIGN TO CUSTIN
FILE STATUS IS WS-CUST-STATUS.
WORKING-STORAGE SECTION.
01 WS-CUST-STATUS PIC XX.
88 CUST-OK VALUE '00'.
88 CUST-EOF VALUE '10'.
01 WS-TOTAL PIC S9(11)V99 COMP-3 VALUE ZERO.
PROCEDURE DIVISION.
OPEN INPUT CUST-FILE
IF NOT CUST-OK
DISPLAY 'CUSTIN OPEN FAILED, STATUS ' WS-CUST-STATUS
MOVE 16 TO RETURN-CODE
GOBACK
END-IF
PERFORM UNTIL CUST-EOF
READ CUST-FILE
AT END CONTINUE
NOT AT END ADD CUST-BALANCE TO WS-TOTAL
END-READ
IF NOT CUST-OK AND NOT CUST-EOF
DISPLAY 'CUSTIN READ ERROR ' WS-CUST-STATUS
MOVE 16 TO RETURN-CODE
GOBACK
END-IF
END-PERFORM
CLOSE CUST-FILE
GOBACK.| Question | What it tests | What a strong answer shows |
|---|---|---|
| Which forms of PERFORM do you use? | Control flow | Out-of-line PERFORM of a paragraph, PERFORM THRU a range, PERFORM n TIMES, PERFORM UNTIL (test before by default, or WITH TEST AFTER), PERFORM VARYING for loops, and inline PERFORM ... END-PERFORM. |
| SEARCH or SEARCH ALL? | Table lookup | SEARCH is sequential from the current index value, so SET the index first. SEARCH ALL is a binary search that needs the table sorted on a declared ASCENDING or DESCENDING KEY and an INDEXED BY index. |
| What does EVALUATE replace? | Branching | Nested IFs. It works like a case statement, can test several subjects at once with ALSO, and should end with WHEN OTHER. |
| What do FILE STATUS 00, 10, 22, 23, 35 and 39 mean? | Files | Success, end of file, duplicate key on write, record not found on a keyed read, file not found at OPEN, and a conflict between the program's file attributes and the dataset's. Always check the status after each I/O. |
| What are the VSAM dataset types? | VSAM | KSDS (keyed, the most common), ESDS (entry sequenced, in arrival order) and RRDS (by relative record number). In COBOL they are indexed, sequential and relative organization. |
| Random, sequential or dynamic access on a KSDS? | Access modes | Random reads by key, sequential reads in key order, dynamic does both, typically a START to position followed by READ NEXT. |
| How does the SORT verb work? | Sorting | SORT on a sort file with keys, using files directly or INPUT and OUTPUT PROCEDUREs that RELEASE records into the sort and RETURN them out, so you can filter or reformat on the way. |
| STRING, UNSTRING and INSPECT: what is each for? | Text handling | STRING joins fields with delimiters, UNSTRING splits one field into many, INSPECT counts or replaces characters, for example TALLYING leading spaces. |
Senior and production support questions
- The nightly job abended with S0C7. Walk me through it. Find the failing statement from the offset in the dump or the debugging tool, identify the field, then look at the input record that caused it. Usually it is non-numeric data in a packed or zoned field: a bad upstream file, a layout change, or an uninitialized field. Fix the data or add validation, and restart from the right step.
- What causes S0C4? A storage protection exception: addressing memory the program may not use. Common causes are a subscript out of range, a LINKAGE item used without the caller passing it, or a mismatch in the parameter list between caller and called program. The SSRANGE compiler option helps catch subscripts in testing.
- SB37, SD37 or SE37 on a job step. What does it mean? The output dataset ran out of space: no secondary allocation, too many extents, or no room on the volume. Adjust the space or the volume, then restart the step.
- Static or dynamic CALL? A static call links the subprogram into the load module, so a change needs a relink of every caller. A dynamic call loads it at run time, so a new version is picked up without relinking, at a small cost. Which one you get depends on how the CALL is written and on compiler options.
- BY REFERENCE, BY CONTENT or BY VALUE? By reference passes the address, so the subprogram can change the caller's field. By content passes a copy. By value passes the value itself, mostly for calling C or system routines.
- How do you make a long batch job restartable? Commit work in batches, write checkpoint records with the last key processed, and code the program to resume from that key, so a failure at hour three does not mean starting again from the top.
- How would you test a change to a program that has no tests? Run the old and new versions against the same production-like input and compare outputs field by field, then check edge records: negatives, zero amounts, maximum lengths and empty files.
- How do COBOL systems get modernized? Commonly by exposing existing programs as APIs, moving batch reports to new platforms, or rewriting module by module with strong regression comparisons. Big-bang rewrites carry the most risk; interviewers want to hear about incremental steps and data validation.
- What does a typical batch step's JCL contain? An EXEC statement naming the program, DD statements mapping each file name in the program to a dataset with its DISP, and conditions or IF logic that decide whether later steps run based on return codes.
Fictional example
- Interviewer
- Tell me about an abend you were called for and how you handled it.
- Candidate
- A premium calculation job failed with S0C7 at around 2 a.m. The dump offset pointed to an ADD into a COMP-3 total, and the source field was the rider premium in a record from a new upstream feed. Browsing the input in hex showed spaces in that field for about forty records, where the sender had left optional riders blank. I agreed with the on-call lead to skip those records to a suspense file so the batch window could finish, then restarted the step. The permanent fix was a validation paragraph that treats non-numeric optional amounts as zero with a warning count, plus a change request to the sender. I also added a test file with blank riders to our regression set.
How to prepare for a COBOL interview
- Days 1 and 2: write the byte size of ten PIC and USAGE combinations by hand, then check them. Practice packing and unpacking a few values on paper.
- Days 3 and 4: with a free compiler such as GnuCOBOL or a training environment, write a two-file match-and-merge program with FILE STATUS checks and a summary report.
- Day 5: write a table lookup twice, once with SEARCH and once with SEARCH ALL, and explain what each needs.
- Day 6: prepare short answers for S0C7, S0C4, S0CB, S322, S806 and the space abends, each with a cause and a first check.
- Day 7: rehearse one real production story and one change you tested safely, with numbers you can actually stand behind.
Production support answers are judged on sequence, and nerves make people jump to the fix. Natively, an AI interview assistant for Mac and Windows, transcribes your mock mainframe interview on your computer, so you can read back whether you found the failing statement before blaming the data. During practice it can read a code listing or an abend message from a screenshot and suggest what to check, and with Pro or the free trial it uses the résumé and job description you add. Transcripts and notes are saved so you can review them.
Questions people ask
What COBOL questions are asked in interviews?
The four divisions, PIC clauses and USAGE types, level numbers including 88, COMP-3 sizing, REDEFINES and OCCURS DEPENDING ON, PERFORM forms, SEARCH versus SEARCH ALL, FILE STATUS codes, static and dynamic CALL, and common abends.
How many bytes does a COMP-3 field take?
The number of digits plus one, divided by two and rounded up, because each byte holds two digits and the last half-byte holds the sign. PIC S9(7) COMP-3 takes four bytes.
What causes a S0C7 abend in COBOL?
Arithmetic or a numeric comparison on a field that does not hold valid numeric data, such as spaces or low-values in a packed field. Find the statement from the dump offset and check the input record.
Is COBOL still asked in interviews for freshers?
Yes, in trainee programs for mainframe teams at banks, insurers and service companies. Fresher rounds focus on syntax, data definitions and simple programs rather than production abends.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
