COBOL COBOL 2014 (ISO/IEC 1989:2014), built with GnuCOBOL 3.x ·
✓ verified by execution on 2026-08-16
If you ask a non-COBOL programmer about the language, they’ll likely picture developers counting spaces to line up code perfectly into a strict 72-column grid, reminiscent of punched cards from the 1960s. They might also assume COBOL lacks modern conveniences like built-in string functions or Object-Oriented programming.
While those stereotypes were true for older standards like COBOL 85, the language hasn’t stood still. The COBOL 2002 and COBOL 2014 standards introduced massive modernizations to the language. Let’s look at what changed, and how those features fare today in open-source compilers like GnuCOBOL 3.x.
Freeing the Format
The most visible change in COBOL 2002 was the introduction of free-format source code. For decades, COBOL enforced a strict column layout:
Columns 1-6 for line numbers.
Column 7 for comments (*) or continuation (-).
Columns 8-11 (Area A) for Division, Section, and Paragraph headers.
Columns 12-72 (Area B) for actual statements.
COBOL 2002 allows you to ditch the grid entirely using the >>SOURCE FORMAT IS FREE directive.
cobol✓ verified output
>>SOURCE FORMAT IS FREEIDENTIFICATION DIVISION.PROGRAM-ID. FREE-FORMAT-TEST.PROCEDURE DIVISION. DISPLAY "Look ma, no column restrictions!" DISPLAY "I can indent however I want.". STOP RUN.
Output
Look ma, no column restrictions!
I can indent however I want.
Your output
A Wealth of Intrinsic Functions
Older COBOL required you to write manual loops to reverse strings or find the maximum value in an array. Modern COBOL standards introduced dozens of intrinsic functions for math, string manipulation, date handling, and more.
What will this program output when we use the UPPER-CASE function?
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. INTRINSIC-TEST.DATA DIVISION.WORKING-STORAGE SECTION.01 WS-STR PIC X(10) VALUE "hello".PROCEDURE DIVISION. DISPLAY FUNCTION UPPER-CASE(WS-STR). STOP RUN.
Output
HELLO
You predicted
The FUNCTION keyword can get repetitive. COBOL 2002 lets you make it optional by declaring FUNCTION ALL INTRINSIC in the REPOSITORY paragraph of the ENVIRONMENT DIVISION.
cobol✓ verified output
>>SOURCE FORMAT IS FREEIDENTIFICATION DIVISION.PROGRAM-ID. OPT-FUNC-TEST.ENVIRONMENT DIVISION.CONFIGURATION SECTION.REPOSITORY. FUNCTION ALL INTRINSIC.DATA DIVISION.WORKING-STORAGE SECTION.01 WS-STR PIC X(10) VALUE "world".PROCEDURE DIVISION. DISPLAY UPPER-CASE(WS-STR). STOP RUN.
Output
WORLD
Your output
The Bleeding Edge: What GnuCOBOL 3.x Doesn’t Support Yet
While enterprise compilers like IBM Enterprise COBOL fully implement these newer standards, open-source compilers like GnuCOBOL 3.x are still catching up on some of the more complex features.
Object-Oriented COBOL
COBOL 2002 introduced Object-Oriented syntax (CLASS-ID, INVOKE). However, GnuCOBOL 3.x explicitly rejects native class definitions with a syntax error.
cobol✓ verified output
>>SOURCE FORMAT IS FREEIDENTIFICATION DIVISION.CLASS-ID. MyClass.PROCEDURE DIVISION.
This example raises an error (on purpose)
syntax error
Your output
error: 'CLASS-ID' is a reserved word, but isn't supportederror: syntax error, unexpected Identifier
(This will fail to compile in GnuCOBOL, as native OO is still experimental).
Dynamic Length Strings
COBOL 2014 introduced DYNAMIC LENGTH elementary items, allowing strings to automatically resize without needing fixed PIC X(100) limits.
cobol✓ verified output
>>SOURCE FORMAT IS FREEIDENTIFICATION DIVISION.PROGRAM-ID. DYN-LEN-TEST.DATA DIVISION.WORKING-STORAGE SECTION.01 WS-DYN PIC X DYNAMIC.PROCEDURE DIVISION. DISPLAY "Dynamic length not fully in GC 3.x". STOP RUN.
This example raises an error (on purpose)
syntax error
Your output
error: syntax error, unexpected DYNAMIC
(This also throws a syntax error in GnuCOBOL 3.x, as the DYNAMIC keyword is not fully implemented for standard data items).
COBOL continues to evolve, proving that even a language designed in 1959 can adapt to the modern era!
Check yourself
What major change to source formatting was introduced in the COBOL 2002 standard?
Reveal answer
It allowed programs to be written in free-format, eliminating the strict 72-column punched-card margins. — The COBOL 2002 standard introduced free-format source code, finally freeing developers from the traditional 72-column margins inherited from punched cards.
How does GnuCOBOL 3.x handle Object-Oriented COBOL syntax like CLASS-ID (introduced in 2002)?
Reveal answer
It explicitly rejects it with a syntax error, as native OO support is still experimental. — While enterprise compilers like IBM's support OO COBOL, GnuCOBOL 3.x rejects CLASS-ID with a syntax error, showing that OO is not fully supported natively yet.
Which of the following is true about intrinsic functions in modern COBOL standards?
Reveal answer
The FUNCTION keyword can be made optional by declaring 'FUNCTION ALL INTRINSIC' in the REPOSITORY paragraph. — Modern COBOL allows you to omit the FUNCTION keyword (e.g., just calling UPPER-CASE(STR)) if you declare 'FUNCTION ALL INTRINSIC' in the Configuration Section's REPOSITORY paragraph.
Challenges
Challenge 1 +20 XP
Convert the given fixed-format COBOL program to use free-format using the >>SOURCE FORMAT IS FREE directive and remove the line numbers.
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 "It works!\n"
Need a hint? (−25% XP)
Add >>SOURCE FORMAT IS FREE at the very beginning and strip out all line numbers.
Show solution (0 XP)
>>SOURCE FORMAT IS FREEIDENTIFICATION DIVISION.PROGRAM-ID. FIX-TO-FREE.PROCEDURE DIVISION. DISPLAY "It works!". STOP RUN.
🐞 Bug Hunt+25 XP
The author tried to use the UPPER-CASE intrinsic function without typing the FUNCTION keyword, but the compiler is throwing a syntax error! Fix the program by adding the correct declaration in the REPOSITORY paragraph.
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 "COBOL\n"
Need a hint? (−25% XP)
You need to add FUNCTION ALL INTRINSIC. inside the REPOSITORY paragraph.
Show solution (0 XP)
>>SOURCE FORMAT IS FREEIDENTIFICATION DIVISION.PROGRAM-ID. BUG-HUNT.ENVIRONMENT DIVISION.CONFIGURATION SECTION.REPOSITORY. FUNCTION ALL INTRINSIC.DATA DIVISION.WORKING-STORAGE SECTION.01 WS-STR PIC X(5) VALUE "cobol".PROCEDURE DIVISION. DISPLAY UPPER-CASE(WS-STR). STOP RUN.