Introduction
COBOL, the Common Business-Oriented Language, was designed in 1959 for business data processing, with statements close to English. It is still used for banking, insurance and government systems, much of it on IBM mainframes. The language is an ISO standard, most recently revised in 2023.
Source files on Windows, Linux and Unix are usually named .cbl or
.cob. .cpy is a copybook, a shared piece of source, most often
a record layout, pulled into programs with the COPY statement. On a
mainframe, source is kept in members of data sets, in EBCDIC, and gains an extension
only when it is moved elsewhere.
Structure
A program has up to four divisions, in order: IDENTIFICATION names it,
ENVIRONMENT ties it to files and hardware, DATA declares its
storage and PROCEDURE holds the code. Sentences end with a full stop.
Words are not case-sensitive and may be joined with hyphens.
Traditional fixed format gives each column of an 80-column card a job:
- columns 1 to 6: sequence number, ignored by the compiler
- column 7: indicator, with
*for a comment and-for a continuation - columns 8 to 11: Area A, for division, section and paragraph names and
01level numbers - columns 12 to 72: Area B, for statements
- columns 73 to 80: ignored
The 2002 standard added a free format with no column rules, which many compilers take
with a switch or the directive >>SOURCE FORMAT IS FREE.
Data items are declared with a level number and a PIC clause that gives
their shape: PIC X(10) is ten characters and PIC 9(5)V99 is a
number with five digits, an implied decimal point and two more digits. Higher level
numbers nest inside lower ones to build records.
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NAME PIC X(10) VALUE "WORLD".
PROCEDURE DIVISION.
DISPLAY "HELLO, " WS-NAME.
STOP RUN.
Links
Software
- GnuCOBOL – free compiler that translates COBOL to C (Windows, macOS, Linux)
- IBM Enterprise COBOL – IBM’s compiler for its mainframes (z/OS)
- Visual Studio Code – free code editor with COBOL extensions (Windows, macOS, Linux)
Reference
- Enterprise COBOL for z/OS documentation – IBM’s language reference and programming guides
- ISO/IEC 1989 – the international standard for COBOL