COBOL COBOL 2014 (ISO/IEC 1989:2014), built with GnuCOBOL 3.x ·
✓ verified by execution on 2026-08-16
When you sit down for a mainframe developer interview, you will not be asked about how to install a compiler or what year COBOL was invented. Instead, interviewers will ask you practical questions about the language’s unique idiosyncrasies. They want to know if you can safely maintain code that has been running for decades.
This lesson covers the most common technical questions you will face, proving your understanding with runnable examples. You will need to know these concepts not just to pass an interview, but to survive your first day on the job maintaining a legacy codebase.
Packed Decimal vs Binary
One of the most universal interview questions is explaining the difference between COMP and COMP-3. In modern programming languages, developers rarely think about the physical memory layout of an integer. In COBOL, it is critical.
COMP (Computational) is standard binary format. COMP-3, however, is Packed Decimal (Binary Coded Decimal). Packed decimal stores two decimal digits per byte, plus a sign nibble at the end. It is ubiquitous in mainframe financial software because it avoids the rounding errors inherent to floating-point binary math.
cobol✓ verified output
>>SOURCE FORMAT IS FREEIDENTIFICATION DIVISION.PROGRAM-ID. EX1.DATA DIVISION.WORKING-STORAGE SECTION.01 WS-NUM-COMP PIC S9(4) COMP VALUE +1234.01 WS-NUM-COMP3 PIC S9(4) COMP-3 VALUE +1234.PROCEDURE DIVISION. DISPLAY 'COMP-3 is packed decimal' STOP RUN.
Output
COMP-3 is packed decimal
Your output
When an interviewer asks you about COMP-3, they want to hear that you understand it saves space (two digits per byte) and perfectly preserves base-10 precision for money.
The Power of EVALUATE TRUE
Many languages have a switch or case statement that checks a single variable against various constants. COBOL’s EVALUATE can do that, but EVALUATE TRUE does something much more powerful: it acts as a generalized decision table.
Interviewers will often ask you to simplify a messy nested IF structure. EVALUATE TRUE allows each WHEN clause to evaluate completely independent logical conditions.
cobol✓ verified output
>>SOURCE FORMAT IS FREEIDENTIFICATION DIVISION.PROGRAM-ID. EX2.DATA DIVISION.WORKING-STORAGE SECTION.01 WS-VAL PIC 9 VALUE 5.PROCEDURE DIVISION. EVALUATE TRUE WHEN WS-VAL < 3 DISPLAY 'SMALL' WHEN WS-VAL >= 3 AND < 7 DISPLAY 'MEDIUM' WHEN OTHER DISPLAY 'LARGE' END-EVALUATE. STOP RUN.
Output
MEDIUM
Your output
Static vs Dynamic CALLs
When one COBOL program calls another, it uses the CALL statement. The interviewer’s question is: “What is the difference between a static and a dynamic call?”
A static call uses a literal string (CALL 'SUBPGM'). The compiler links the subprogram directly into the calling program’s executable module. A dynamic call uses a variable (CALL WS-PGM). The system resolves the module at runtime.
cobol✓ verified output
>>SOURCE FORMAT IS FREEIDENTIFICATION DIVISION.PROGRAM-ID. EX3.DATA DIVISION.WORKING-STORAGE SECTION.01 WS-PGM PIC X(8) VALUE 'SUBPGM'.PROCEDURE DIVISION. DISPLAY 'Static vs Dynamic CALL logic'. STOP RUN.
Output
Static vs Dynamic CALL logic
Your output
If a dynamically called program is updated and recompiled, the caller automatically picks up the new version without needing a recompile. Static calls execute slightly faster but require you to re-link everything if the subprogram changes.
Parsing Strings with UNSTRING
Legacy data often arrives as comma-separated text or pipe-delimited files. How do you parse it? COBOL doesn’t have a split() function like modern languages. Instead, it uses UNSTRING.
cobol✓ verified output
>>SOURCE FORMAT IS FREEIDENTIFICATION DIVISION.PROGRAM-ID. EX5.DATA DIVISION.WORKING-STORAGE SECTION.01 WS-CSV PIC X(20) VALUE 'APPLES,BANANAS,PEARS'.01 WS-W1 PIC X(10).01 WS-W2 PIC X(10).01 WS-W3 PIC X(10).PROCEDURE DIVISION. UNSTRING WS-CSV DELIMITED BY ',' INTO WS-W1 WS-W2 WS-W3. DISPLAY WS-W1 '-' WS-W2 '-' WS-W3. STOP RUN.
Output
APPLES -BANANAS -PEARS
Your output
You must explicitly provide a receiving variable (WS-W1, WS-W2, etc.) for every delimited chunk you expect to extract.
Reference Modification: Substring Extraction
Another whiteboard favorite is extracting a substring. In COBOL, this is called Reference Modification.
Before you predict the output below, remember one critical rule: COBOL is strictly 1-indexed. The first character is character 1, not character 0.
Predict the outputcobol
Read the code. What exactly will it print? Commit to an answer before you look.
>>SOURCE FORMAT IS FREEIDENTIFICATION DIVISION.PROGRAM-ID. EX6.DATA DIVISION.WORKING-STORAGE SECTION.01 WS-FULL PIC X(10) VALUE '2026-08-15'.01 WS-YEAR PIC X(4).PROCEDURE DIVISION. MOVE WS-FULL(1:4) TO WS-YEAR. DISPLAY 'Year: ' WS-YEAR. STOP RUN.
Output
Year: 2026
You predicted
In the syntax WS-FULL(1:4), the first number is the starting position, and the second number is the length of the substring. Therefore, it extracts a 4-character string starting from position 1.
String Replacements with INSPECT
You will often need to clean up data by replacing specific characters. INSPECT is the workhorse statement for this.
cobol✓ verified output
>>SOURCE FORMAT IS FREEIDENTIFICATION DIVISION.PROGRAM-ID. EX4.DATA DIVISION.WORKING-STORAGE SECTION.01 WS-STR PIC X(15) VALUE 'COBOL IS GREAT '.01 WS-COUNT PIC 99 VALUE 0.PROCEDURE DIVISION. INSPECT WS-STR TALLYING WS-COUNT FOR ALL ' '. DISPLAY 'Spaces: ' WS-COUNT. STOP RUN.
Output
Spaces: 03
Your output
In addition to TALLYING (counting characters), INSPECT can also REPLACE characters in place, which you will need to do in the challenge below.
Check yourself
What is the main difference between COMP and COMP-3 in COBOL?
Reveal answer
COMP is binary, while COMP-3 is packed decimal (BCD) and safer for financial calculations. — COMP is binary data. COMP-3 is packed decimal (Binary Coded Decimal), which is universally used in mainframe financial calculations to prevent floating point inaccuracies and save space.
How does a static CALL differ from a dynamic CALL in COBOL?
Reveal answer
Static CALLs are linked at compile time, while dynamic CALLs are resolved at runtime. — Static CALLs (CALL 'LITERAL') are linked at compile time and become part of the load module. Dynamic CALLs (CALL identifier) resolve the module name at runtime, allowing updates without recompiling the caller.
How does reference modification indexing work in COBOL?
Reveal answer
It uses 1-based indexing, where STRING(1:4) gets the first 4 characters. — Unlike modern languages, COBOL reference modification is strictly 1-based. STRING(1:4) extracts a 4-byte substring starting at the very first character.
What is a key advantage of EVALUATE TRUE over a standard EVALUATE variable?
Reveal answer
It allows evaluating multiple independent expressions using WHEN conditions. — EVALUATE TRUE acts like a generic decision table, letting you evaluate completely independent logical conditions in each WHEN clause, rather than being restricted to matching the value of a single variable.
Challenges
🐞 Bug Hunt+20 XP
An interviewer asks you to write an EVALUATE TRUE statement to categorize a temperature, but the current code has a logic gap. Fix it so temperatures exactly at 32 display 'FREEZING'.
This code runs. It just does the wrong thing. Read it, find the defect,
fix it — the tests below decide when you are right.
cobol✓ solution verified at build time
COBOL has no in-browser runtime, so this one is pen-and-paper: work out what the
fixed code should be, then open the solution and compare. The expected output
below is real — it came from compiling the solution with GnuCOBOL when this page
was built.
Test 1 — expects "FREEZING\n"
Need a hint? (−25% XP)
Add a WHEN clause for WS-TEMP = 32.
Show solution (0 XP)
>>SOURCE FORMAT IS FREEIDENTIFICATION DIVISION.PROGRAM-ID. CH1.DATA DIVISION.WORKING-STORAGE SECTION.01 WS-TEMP PIC S999 VALUE 32.PROCEDURE DIVISION. EVALUATE TRUE WHEN WS-TEMP < 32 DISPLAY 'COLD' WHEN WS-TEMP = 32 DISPLAY 'FREEZING' WHEN WS-TEMP > 32 DISPLAY 'WARM' END-EVALUATE. STOP RUN.
🐞 Bug Hunt+20 XP
An interviewer asks you to replace all spaces with dashes in a string. The current code tallies spaces instead. Fix it to REPLACE spaces with dashes ('-').
This code runs. It just does the wrong thing. Read it, find the defect,
fix it — the tests below decide when you are right.
cobol✓ solution verified at build time
COBOL has no in-browser runtime, so this one is pen-and-paper: work out what the
fixed code should be, then open the solution and compare. The expected output
below is real — it came from compiling the solution with GnuCOBOL when this page
was built.
Test 1 — expects "A-B-C-D-E------\n"
Need a hint? (−25% XP)
Use INSPECT ... REPLACING ALL ' ' BY '-'.
Show solution (0 XP)
>>SOURCE FORMAT IS FREEIDENTIFICATION DIVISION.PROGRAM-ID. CH2.DATA DIVISION.WORKING-STORAGE SECTION.01 WS-TEXT PIC X(15) VALUE 'A B C D E'.PROCEDURE DIVISION. INSPECT WS-TEXT REPLACING ALL ' ' BY '-'. DISPLAY WS-TEXT. STOP RUN.