HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to COBOLVariablesArithmeticConditions (IF)Loops (PERFORM)
REFERENCE
📖 Overview
🖥️ Structure & Output
📦 Variables
🔢 Arithmetic
🔀 Condition
🔁 Loop
COBOL›Introduction to COBOL

Introduction to COBOL

First step into COBOL, the legendary language of banking: program divisions (DIVISION) and DISPLAY.

Simple enough for a 5-year-old to understand

Program structure (DIVISIONs)

A COBOL program is divided into divisions: IDENTIFICATION (program name), PROCEDURE (commands). Every statement ends with a period (.).

Fixed format is important: DIVISION lines start with ~7 spaces, commands are indented further.

Your first program
1
IDENTIFICATION DIVISION.
Program identification.
DefinitionProgram identification.
2
PROGRAM-ID. HELLO.
Program name.
DefinitionProgram name.
3
PROCEDURE DIVISION.
Procedure division.
DefinitionProcedure division.
4
DISPLAY "Hello World".
Prints to the screen.
Output / InputPrints to the screen.
5
STOP RUN.
End the program.
CodeEnd the program.
DefinitionOutput / InputCode
💡 Hint: Every statement ends with a period (.). DISPLAY prints to the screen, STOP RUN ends the program.

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (2 left)

1.Which command is used to print to the screen in COBOL?
2.Print Hello World to the screen exactly as requested (DISPLAY).

🎯 Expected output: Hello World

Loading editor…

About this topic

COBOL was designed in 1959 for commercial data processing. Its name is an acronym for the English phrase "common business-oriented language", and its purpose was to express business processes in a language that non-engineers could read.

That is why COBOL resembles English sentences. Commands read like verbs, data like nouns, and a program flows almost like prose. Though this detail might seem overly verbose today, it allowed different teams to maintain the same code over sixty years.

COBOL is still running. At the core of banking, insurance, and government systems worldwide, COBOL exists; a large portion of daily transaction volume passes through this code. Therefore, knowing COBOL means understanding and maintaining what already exists rather than writing new code.

What you will learn

  • The four-division structure
  • Declaring the program ID
  • Printing to the screen
  • Ending statements with a period
  • The difference between fixed and free format

Who is this for?

  • Those working in banking and insurance systems
  • Those maintaining legacy systems
  • Those entering the mainframe world

When to use?

COBOL is learned to maintain and extend existing large-scale batch processing systems; these systems process billions of transactions a year, and rewriting them is very costly.

A new project is not started with COBOL; the language was not designed to compete with today's development tools and ecosystem.

Common mistakes

Wrong

IDENTIFICATION DIVISION.
PROGRAM-ID. MERHABA.
PROCEDURE DIVISION.
    DISPLAY 'Hello'

The final statement is not ended with a period, and the program termination command is missing. In COBOL, a period ends a sentence; a missing period leads to confusing errors, such as the compiler treating subsequent lines as part of the same sentence.

Correct

IDENTIFICATION DIVISION.
PROGRAM-ID. MERHABA.
PROCEDURE DIVISION.
    DISPLAY 'Hello'.
    STOP RUN.

Wrong

PROGRAM-ID. MERHABA.
IDENTIFICATION DIVISION.
PROCEDURE DIVISION.
    DISPLAY 'Hello'.
    STOP RUN.

The order of the divisions is fixed, and the identification division always comes first; the program ID is located within it. When the order is disrupted, the compiler gives errors that seem meaningless. The order of the four divisions is a rule that must be memorized.

Correct

IDENTIFICATION DIVISION.
PROGRAM-ID. MERHABA.
PROCEDURE DIVISION.
    DISPLAY 'Hello'.
    STOP RUN.

Wrong

IDENTIFICATION DIVISION.
    PROGRAM-ID. MERHABA.
PROCEDURE DIVISION.
    DISPLAY 'Hello'.
    STOP RUN.

In fixed format, division and paragraph headers must start within a specific column range; statements start further to the right. The program ID is a paragraph header, and if it is indented like a statement, the compiler will not recognize it. In free format, this restriction does not exist.

Correct

IDENTIFICATION DIVISION.
PROGRAM-ID. MERHABA.
PROCEDURE DIVISION.
    DISPLAY 'Hello'.
    STOP RUN.

Frequently asked questions

What are the four divisions?

The identification division names the program, the environment division defines file and hardware connections, the data division declares all variables, and the procedure division contains the actual code. In small programs, the environment division can be left empty.

Why are column numbers important?

Because COBOL was designed in the era of punch cards. In fixed format, the seventh column is for indicators, eight through eleven are for headers, and twelve through seventy-two contain statements. Modern compilers also support free format.

Which compiler can I use?

A free and common option is GnuCOBOL; it translates code to C and compiles it, running on a personal computer. In mainframe environments, vendor compilers are used, and there are differences in some extensions.

Summary

COBOL resembles English sentences.

The program consists of four divisions, and the order is fixed.

Every sentence ends with a period.

In fixed format, column positions are meaningful.

It is still common in finance and government systems.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code