Skeleton of a COBOL Program

This is just an overview. For complete details, consult the appropriate IBM manuals. There are more options than are listed here, and older compilers may require some items now not mandatory.


4 Divisions of a COBOL program


Example

       Identification Division.

       Program-ID.    Program-Name.
       Author.        Your Name.
       Date-Compiled. (Supplied by the system.)

 
       Environment Division.
 
       Configuration Section.

       Source-Computer.  IBM-390.
       Object-Computer.  IBM-390.
 
       Input-Output Section.

       File-Control.
           Select File-Name Assign To DDname.

       Data Division.
 
       File Section.
 
       FD  File-Name
           Recording Mode is F.
 
       01  Record-Name.
      * (definition of Record-Name)
 
       Working-Storage Section.
      * (definitions of various items)

       Linkage Section.
       * (descriptions of parameters)

       Procedure Division.

       000-Main.
      * (assorted code)
           Stop Run.

       100-Sub.    
      * (code)


Let's look at the above example.

In the Procedure Division, execution will begin with the first line of code, and it ends when the Stop Run command is executed. We normally have just one Stop Run in a program.

This example has no documentation (other than the parenthetical remarks). Normally, we do require documentation in a COBOL program.


Page layout

COBOL code is written in 80-column lines. We leave columns 1-6 blank, we usually leave column 7 blank, and we always leave columns 73-80 blank. Columns 8-11 are the A margin, and columns 12-72 are the B margin.

Column 7 is used in two ways: put an asterisk (*) in column 7 to make the line into a comment, or put a dash (-) in column 7 to indicate continuation of a character literal to the next line.

Some items must begin in the A margin: names of divisions, names of sections, names of subroutines, 01-level items in the Data Division, etc.