StephenJohnston
Series: Learn COBOL

Introduction to COBOL

The Problem

As businesses began relying more heavily on computers for data processing—such as payroll, inventory, and banking—in the 1950s, it became clear that change was necessary. At the time, each computer manufacturer used its own proprietary programming language, often tied to specific hardware. Additionally, early languages like FORTRAN and Assembly Language were designed for scientific and engineering applications, respectively, and made it less approachable to business folks uneasy with mathematical symbols (e.g., <, >, ≠).

The Solution

Recognizing the inefficiency and cost of porting programs across systems, the U.S. Department of Defense (DoD) spearheaded efforts to create a standardized programming language that could be used universally. With this goal in mind, a group of experts gathered at the Conference on Data Systems Languages (CODASYL) in 1959. Among them was Grace Hopper, a pioneering computer scientist who was a driving force behind the development of the first compiler, playing a pivotal role in its creation alongside other contributors.

This conference birthed COBOL (Common Business-Oriented Language), a pioneering language designed for business data processing. Its English-like syntax — though not the first (see FLOW-MATIC), made programming accessible to non-technical users, empowering them to read, understand, and even write code. This innovation is aking to how today’s drag-and-drop website builders have removed barriers to web development.

The Structure of a COBOL program

Now that we’ve learned a bit about COBOL and some of the problems it solved, we’ll take a look at the structure of a COBOL program.

Columns in COBOL

Since COBOL dates back to the era of punched cards—where data was physically encoded on cards—it’s no surprise that its code is organized into specific column-based areas, each serving a unique purpose.

The Structure of a COBOL program

Because COBOL is English-like, perhaps it comes as no surprise that a COBOL program is structured much like a document, with divisions, sections, paragraphs, sentences, and statements. Let’s explore these a little more.

The Four Divisions of a COBOL program

Every COBOL program consists of four divisions; however, only two are required to write a basic COBOL program: the IDENTIFICATION DIVISION and the PROCEDURE DIVISION.

IDENTIFICATION DIVISION

The IDENTIFICATION DIVISION is mandatory for every COBOL program. Without it, the program is invalid. It provides a place to store some valuable metadata, such as the program name, author, and other details. Within this division, the PROGRAM-ID paragraph must appear directly after the IDENTIFICATION DIVISION and is the only required paragraph. Other optional paragraphs include AUTHOR, DATE-WRITTEN, DATE-COMPILED, and SECURITY.

ENVIRONMENT DIVISION

This division, which follows the IDENTIFICATION DIVISION, describes the system environment where the program will run, including:

  1. The computer hardware and operating system.
  2. Any I/O devices (e.g., printers, disk drives, etc.) the program will use.

The ENVIRONMENT DIVISION is divided into two sections:

DATA DIVISION

This is where your COBOL program defines and stores all the data it will use. It’s like the program’s “storage room” for variables, records, and files.

The DATA DIVISION is divided into the following sections:

  1. FILE SECTION - Defines the structure of files used for input/output.
  2. WORKING-STORAGE SECTION - Stores temporary data and variables used during program execution.
  3. LINKAGE SECTION - Defines data shared between programs (used in subprograms).

PROCEDURE DIVISION

The PROCEDURE DIVISION is mandatory for any COBOL program, as it contains the logic and operations that bring the program to life. This is where you define the logic, operations, and all the processing that will occur happens.

A Basic COBOL Program

If you have prior programming experience, this program will look familiar. It’s the basic ‘Hello World’ program.

We start by declaring our IDENTIFICATION DIVISION followed by a PROGRAM-ID, which is the only required paragraph in this division.

Next, we declare the PROCEDURE DIVISION, which is where the action happens. To display output, we use the DISPLAY verb, which writes to the output device. While this is typically a terminal screen today, it was often a printer in the past.

Finally, we instruct COBOL that immediately after it displays Hello World, we want to stop everything, and that’s done with the STOP RUN statement.

      *******************************************************************
      *                   IDENTIFICATION DIVISION                       *
      *******************************************************************
      * The IDENTIFICATION DIVISION provides metadata about our program,*
      * and is one of two mandatory DIVISIONS in COBOL. The PROGRAM-ID  *
      * is the only required entry within this DIVISION.                *
      *******************************************************************
       IDENTIFICATION DIVISION.
       PROGRAM-ID. HELLOWORLDPROGRAM.
      
      *******************************************************************
      *                     PROCEDURE DIVISION                          *
      *******************************************************************
      * The PROCEDURE DIVISION is where the program's logic is written. *
      *******************************************************************
       PROCEDURE DIVISION.

      * The DISPLAY verb prints the contents to the output device,
      * in this case, the console window.
           DISPLAY 'Hello, World'.

      * The STOP RUN statement ends the program
           STOP RUN.

Summary

In this article, I’ve described the history and reasoning behind COBOL, the structure of COBOL, and shown you how to write a basic program using COBOL.

As I continue to learn COBOL, I welcome any feedback or corrections. Please let me know, and I’ll update the article accordingly.

Acknowledgments

Big thanks to harrywwc, a knowledgeable COBOL enthusiast who provided invaluable feedback on this article, helping me refine the details and make it more accurate. Your insights were spot on!