Syntax

General format of a COBOL program

This is a brief guide to the syntax of a COBOL program. You can look at the sample program to see how it all fits together. There are also some links to more detailed entries.

Every COBOL program has four divisions.

  1. IDENTIFICATION DIVISION, which contains documentation to identify the program;
  2. ENVIRONMENT DIVISION , which contains information about the computer on which the program is to be compiled and the computer on which the program is to be run; This section also contains information about the files that the program uses for input and output.
  3. DATA DIVISION contains the definitions of all the internal variables used by the program;
  4. PROCEDURE DIVISION contains the actual instructions that the program is to carry out.

These must appear in the order given above. Each DIVISION may be divided into sections. Each section may be further divided into paragraphs.

Spacing

COBOL inherits rules about the layout of the program text from the days when computer programs were input on punched cards. Since a deck of cards could easily be dropped each card had to be numbered. Thus the first six (6) columns of each line are reserved for line numbers. Since some systems expected line numbers at the end of the line as well columns 73-80 are also reserved for identification. Furthermore if the character in column seven (7) is an asterisk (*) the line is ignored by the compiler. Such line are called comment lines. They are used to let the programmer know what the current section of the code is for. They can also be used to space the source code and make it more readable.

Thus only text in columns 8-72 are part of the program proper. There is another distinction within each line. Columns 8-11 are called AREA A, and columns 12- 72 AREA B. Division, section and paragraphs names must begin in area A. All other sentences must be confined to area B. A line can continue onto the next provide that the continuation is in area B.


Return to the cobol home page
Jonathan Hodgson Last Change: 9 January 1998