COBOL (COmmon Business-Oriented Language) is one of the oldest high-level programming languages, and it remains a massive, albeit often invisible, pillar of the global economy.
COBOL was created in 1959 by a committee called CODASYL, with significant influence from Rear Admiral Grace Hopper.
Purpose: It was designed to be a "universal" language for business data processing—something that could run on different types of computers (portability) and be readable by non-programmers (business analysts).
English-like Syntax: It uses prose-style syntax (e.g., ADD 1 TO TOTAL) rather than the mathematical symbols common in C++ or Java.
COBOL programs are famously rigid and hierarchical. Every program is divided into four mandatory Divisions:
Division - Purpose
IDENTIFICATION - Contains metadata like the program name, author, and date.
ENVIRONMENT - Describes the hardware (source and object computers) and file systems.
DATA - This is where all variables and file structures are declared. It is very detailed.
PROCEDURE - Contains the actual logic and executable instructions (the "code").
IDENTIFICATION DIVISION.
PROGRAM-ID. MULTIPLY-ROUTINE.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
* Link the logical file 'PRINT-FILE' to the physical printer
SELECT PRINT-FILE ASSIGN TO PRINTER.
DATA DIVISION.
FILE SECTION.
FD PRINT-FILE.
01 PRINT-LINE.
05 PR-DESC PIC X(20).
05 PR-RESULT PIC ZZZ,ZZ9.99.
WORKING-STORAGE SECTION.
* Variables to hold our inputs and result
01 WS-NUM1 PIC 9(5)V99.
01 WS-NUM2 PIC 9(5)V99.
01 WS-RESULT PIC 9(10)V99.
* Formatted display for the screen
01 WS-DISPLAY-RESULT PIC Z,ZZZ,ZZ9.99.
PROCEDURE DIVISION.
000-MAIN.
OPEN OUTPUT PRINT-FILE.
* 1. Accept user inputs from screen
DISPLAY "ENTER FIRST NUMBER: ".
ACCEPT WS-NUM1.
DISPLAY "ENTER SECOND NUMBER: ".
ACCEPT WS-NUM2.
* 2. Store and Multiply
MULTIPLY WS-NUM1 BY WS-NUM2 GIVING WS-RESULT.
* 3. Output to Display Screen
MOVE WS-RESULT TO WS-DISPLAY-RESULT.
DISPLAY "THE CALCULATED RESULT IS: " WS-DISPLAY-RESULT.
* 4. Output to Printer
MOVE "TOTAL CALCULATION: " TO PR-DESC.
MOVE WS-RESULT TO PR-RESULT.
WRITE PRINT-LINE.
CLOSE PRINT-FILE.
STOP RUN.
Micro Focus COBOL (now officially a brand under OpenText and often marketed as Visual COBOL) is the industry-leading commercial implementation of the COBOL language.
While standard COBOL is a set of rules, Micro Focus is the "power tool" that allows those rules to run on modern hardware, in the cloud, and alongside languages like Java and C#.