DEV Community

Cover image for Learning COBOL as a Beginner β€” A Simple Step-by-Step Guide
Oussama Belhadi
Oussama Belhadi

Posted on

Learning COBOL as a Beginner β€” A Simple Step-by-Step Guide

Hey there! πŸ‘‹
I'm currently learning COBOL β€” yes, that old programming language from the 1960s! I know it looks outdated, but it’s still used in critical systems like banks, airlines, and government software.

I decided to document my learning journey here, in the simplest and shortest way possible, in case it helps someone else out there who's just getting started like me.

πŸ“š 1. What is COBOL?

COBOL stands for Common Business-Oriented Language

It was created in 1959 to process business data (e.g., invoices, reports)

Still used today in huge legacy systems

Super readable (like plain English), but very strict in structure

🧱 2. Structure of a COBOL Program

COBOL programs are divided into four main divisions, always in this order:

  • IDENTIFICATION : Metadata like name, author, etc.

  • ENVIRONMENT : System configuration (often skipped by beginners)

  • DATA : Variable declarations

  • PROCEDURE: The actual logic β€” your code goes here!

🧾 Example Program

      IDENTIFICATION DIVISION.
       PROGRAM-ID. HelloWorld.

       ENVIRONMENT DIVISION.

       DATA DIVISION.

       PROCEDURE DIVISION.
           DISPLAY "Hello, World!".
           STOP RUN.
Enter fullscreen mode Exit fullscreen mode

πŸ“ 3. COBOL Columns (Important!)

COBOL was made for punch cards, so it has strict rules about where you write your code:

1 – 6 : Sequence numbers (optional, can ignore)
7 : * for comments, - for line continuation
8–72 : Actual code goes here (indentation often starts at column 8)
73–80 : Ignored by compiler

πŸ“ 4. Declaring Variables (DATA DIVISION)

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 Name     PIC A(20).
       01 Age      PIC 99.
Enter fullscreen mode Exit fullscreen mode

Explanation:

PIC = Picture Clause, defines the variable type

A(20) = 20 alphabetic characters

99 = 2-digit number

🧾 5. Input and Output

       DISPLAY "Enter your name: ".
       ACCEPT Name.
       DISPLAY "Hello, " Name.
DISPLAY shows a message

Enter fullscreen mode Exit fullscreen mode

ACCEPT takes input from the user

πŸ” 6. IF Conditions

  IF Age > 18
           DISPLAY "You are an adult."
       ELSE
           DISPLAY "You are a minor."
Enter fullscreen mode Exit fullscreen mode

Pretty readable, right?

πŸ”„ 7. Loops with PERFORM

  WORKING-STORAGE SECTION.
       01 I      PIC 9 VALUE 1.

       PROCEDURE DIVISION.
           PERFORM VARYING I FROM 1 BY 1 UNTIL I > 5
               DISPLAY "Count: " I
           END-PERFORM.
Enter fullscreen mode Exit fullscreen mode

Prints:

Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
Enter fullscreen mode Exit fullscreen mode

That’s what I’ve learned so far!
This post is meant to be a beginner-to-beginner guide, I’ll keep sharing more as I go deeper into COBOL.
If you’re also learning COBOL or just curious about it, feel free to follow along! Let’s bring a bit of life into this powerful (but old-school) language.

Top comments (0)