What is COBOL?

19 April 2024

Authors

Chrystal R. China

Writer

Michael Goodwin

Editorial lead, Automation & ITOps

What is COBOL?

Common business-oriented language (COBOL) is a high-level, English-like, compiled programming language that is developed specifically for business data processing needs.

COBOL was designed with optimal versatility in mind; its verbosity enables programmers to use a readable, easily maintainable programming language that can function across mainframe computers and operating systems. In fact, it was one of the first programming languages that the American National Standards Institute (ANSI) and International Organization for Standardization (ISO) standardized.

Although COBOL is considered a legacy system, many government and private sector organizations continue to use it to run financial, administrative and business applications. In fact, COBOL’s imperative, procedural and (in its newer iterations) object-oriented configuration serves as the foundation for more than 40 percent of all online banking systems.1

It also supports 80 percent of in-person credit card transactions, handles 95 percent of all ATM transactions, and powers systems that generate more than USD 3 billion of commerce each day.1 Due to its superior stability and processing power, it continues to play an integral role in helping businesses maintain apps and programs in existing architectures.

Aerial view of highways

Keep your head in the cloud 


Get the weekly Think Newsletter for expert guidance on optimizing multicloud settings in the AI era.

History of COBOL

COBOL was developed by a consortium of government and business organizations called the Conference on Data Systems Languages (CODASYL), which formed in 1959. Partly derived from FLOW-MATIC, a language created by computer science pioneer Dr. Grace Hopper, COBOL was created as part of a US Department of Defense initiative pushing for a programming language that could work across operating systems (Linux®, Windows, Unix, z/OS®, etc.) and hardware environments.

The first version of the COBOL programming language was released in 1960. And though COBOL programming was originally intended to serve as a stopgap measure, the DoD quickly realized its usefulness and mandated computer manufacturers to offer it.

COBOL was ultimately standardized as a computer language in 1968, after which COBOL programmers implemented several revisions and modernizations, including COBOL-61, COBOL-68, COBOL-74 and COBOL-85. The most recent iteration, COBOL 2002, attempts to make COBOL applications more compatible with modern software development practices by introducing object-oriented features and other advanced programming paradigms to the language.

AI Academy

Achieving AI-readiness with hybrid cloud

Led by top IBM thought leaders, the curriculum is designed to help business leaders gain the knowledge needed to prioritize the AI investments that can drive growth.

COBOL structure

The COBOL program has a hierarchical structure that comprises divisions, sections, paragraphs, sentences, verbs and character strings. The divisional nature of a COBOL system (which comprises four divisions) enables a distinct separation of concerns within COBOL programs.

COBOL divisions are as follows:

Identification division

The identification division is the first division of a COBOL program—and a mandatory one. It assigns the program a name and provides other identification information like author, date written and a brief description of the program's purpose.

COBOL programs need a PROGRAM-ID paragraph to function within the identification division. For example:

```

IDENTIFICATION DIVISION.

PROGRAM-ID. YourProgramName

AUTHOR. Your name

DATE-WRITTEN. YYYYMMDD

COMMENT. "Short description of the program"

Environment division

The environment division specifies the runtime environment for a program and defines the input and output resources it will use. It’s subdivided into two sections.

Unsurprisingly, the configuration section provides information about the system configuration, including the computer and compiler features it’s using. However, due to advancements in compiler tools, configuration sections have become somewhat obsolete in modern COBOL systems, which can typically infer and automatically adapt to their environment.

The input-output section specifies the files and associated devices that the program can interact with. It includes the FILE-CONTROL paragraph—which maps file names within the program to external files—and the I-O-CONTROL paragraph that typically contains optimization or sequencing information for input-output operations.

Data division

The data division houses all variable, file and constant definitions for the program. Like the environment division, the data division is subdivided.

The file section lists every file that the program will read from or write to. A file description entry defines each file and describes the structure of the records in the file.

The working-storage section defines variables that maintain their values throughout the run of the program—including counters, accumulators, constants and any other data storage that isn’t relevant to I-O files.

Introduced in later iterations of COBOL, the local-storage section defines variables allocated upon deployment of the program or method and deallocated upon termination, making local-storage especially useful for recursive algorithms and reentrant programs.

Finally, the linkage section defines data items that pass from one program to another.

Procedure division

The procedure division contains the executable code of the program, that is divided into paragraphs and sections that structure the code into code blocks for better readability and easier maintenance.

Additional components

Every division of a COBOL system can include sections and paragraphs, which are analogous to sections and paragraphs in human languages. Sections are the named, logical subdivisions within each division that contain one or more paragraphs; they serve as modular units of code that can be called or invoked within the program.

Paragraphs are collections of sentences—the smallest executable units in a COBOL program—that serve a particular function and are identified by a unique name. Each COBOL statement or sentence within a paragraph starts with a COBOL verb (like MOVE, DISPLAY and ADD) that indicates how the code should be run.

The most basic and indivisible unit of the COBOL language is a character. Character strings are characters or sequences of contiguous characters that form a COBOL word, literal or comment-entry, delimited by separators.

COBOL syntax

COBOL's English-like syntax is self-documenting and nearly self-explanatory, with an emphasis on verbosity and readability. This feature sets it apart from terser languages, like FORTRAN. It can also support several different data types (numeric, alphanumeric and edited data, for example), but it relies on a few additional syntactical components to execute a program.

Sentences and statements

Sentences are lines of COBOL code that consist of one or more statements terminated by a period. Statements, however, are the individual instructions that orchestrate file handling and data handling processes (by using verbs like ADD, START, DISPLAY and WRITE, among others).

For instance, MOVE statements transfer data from one part of the system’s memory to another; COMPUTE statements perform arithmetic operations and store the results as variables; and READ statements retrieve records from input files.

Clauses

Clauses are components of statements that can modify or qualify how a statement is executed. A picture clause like “PIC 9(3),” as one example, defines a numeric variable that can hold up to three digits.

Control structures

Iterative and conditional control structures in COBOL enable the system to control data flow.

IF ... ELSE structures, for example, implement conditional logic in COBOL so the program can execute different blocks of code depending on an evaluation of system condition. And the PERFORM statement executes a paragraph or section a specified number of times or until a condition is met, similar to loops in other programming languages.

Subprograms

COBOL can facilitate modular programming by using subprograms, which are deployed from the main program or other subprograms. Whereas internal subprograms are defined within the same source code as the calling program (written in the procedure division), external subprograms are compiled separately and linked as needed.

Creating a COBOL program

The process of building a program with COBOL varies depending on organizational circumstances. However, it tends to involve a few key steps.

  • Writing the program. If a software engineer wanted to write the basic “Hello, world!” program, for instance, they would write:

    ```

    IDENTIFICATION DIVISION. PROGRAM-ID. hello-world. PROCEDURE DIVISION. DISPLAY "Hello, world!"

    Using a COBOL-compatible integrated development environment (IDE) or text editor can help with the process.

  • Compiling the program. Like other high-level programming languages, COBOL code must be compiled before it’s executed. COBOL compilers (like GnuCOBOL, Micro Focus and IBM® COBOL Compiler Family) translate programs into machine code so the computer's CPU can understand and execute it.

  • Executing the program. When the program is compiled, the programmer can execute it on the target system. Assuming there are no bugs, the program follows the data processing logic defined in the procedure division to process data. The execution process typically entails reading data from files and databases, performing data calculations or transformations and then writing the results to files or databases.

  • Debugging the program (if necessary). If there are any errors or bugs in the program, programmers need to identify and fix them (a process called debugging). Relying on debugging tools and techniques can streamline this process.

Benefits of COBOL programming

Despite the proliferation of more modern languages (like Python, Java, JavaScript), COBOL language was once the most widely used in computer programming for business applications. Even now, COBOL development remains a functional and critical part of the global tech infrastructure, particularly for banking institutions, insurance companies and government agencies.

As evidenced by its staying power, COBOL programming can offer a myriad of benefits to organizations that choose to use it (despite a relative dearth of COBOL programmers1) including:

Stability

COBOL is known for its stable, reliable performance in mission-critical applications. Systems written in COBOL tend to have high uptime and experience few failures, which is vital to the nonstop operations of financial institutions and government services.

Scalability

Developers can scale COBOL applications to handle increasing workloads without significant changes in the codebase, enabling organizations to grow their COBOL-based systems alongside their businesses and without frequent rewrites or migrations to other languages.

Data handling and file processing

COBOL offers exceptional file processing capabilities. It can handle complex, large-scale transaction data and support multiple file access methods, including sequential, indexed and relative data file handling. COBOL's robustness in process automation makes it ideal for batch processing jobs, like processing financial transactions, managing databases and generating reports.

Interoperability

Today’s COBOL systems can interoperate with other languages and technologies (like HTML, JSON, XML and generative AI2) due to the introduction of object-oriented COBOL and interfaces to new programming languages. Object-orientation also facilitates COBOL app integration with virtual and cloud services—like Amazon Web Services (AWS), Microsoft Azure and IBM Cloud®—SQL databases and other modern DevOps infrastructures.

Footnotes

1 The World Depends on 60-Year-Old Code No One Knows Anymore, PC Mag, 1 December 2023

2 Generative AI In Code Generation, Inc42 Media, 24 March 2024

Related solutions
IBM Cloud

IBM Cloud is an enterprise cloud platform designed for regulated industries, providing open, AI-ready, secure and hybrid solutions.

Explore cloud solutions
IBM watsonx Code Assistant

Harness the power of AI-driven automation with watsonx Code Assistant to simplify coding across languages such as Python, Java and more.

Explore IBM watsonx Code Assistant
IBM Z developer tools

Discover a comprehensive suite of developer tools for IBM Z, ranging from AI and testing to cloud-native development and transaction processing.

Explore IBM Z development tools
Take the next step

Unlock the potential of DevOps to build, test and deploy secure cloud-native apps with continuous integration and delivery.

Explore DevOps solutions Learn about hybrid cloud for AI