Custom Search

mainframes cobol programing tips

The areas of a COBOL program.

Indicator area Area A Area B Identification area

000100 IDENTIFICATION DIVISION.

000200 PROGRAM-ID. COMMENT.

000300 ENVIRONMENT DIVISION.

DATA DIVISION. MB072197

000500 PROCEDURE DIVISION.

000600

000700* This is a comment. MB072197

000800* This paragraph displays information about the program. MB072197

000900 PROGRAM-BEGIN.

003700 DISPLAY "This program contains four DIVISIONS,". MB072197

003800 DISPLAY "three PARAGRAPHS". MB072197

001000 DISPLAY "and four SENTENCES".

001100 PROGRAM-DONE.

001200 STOP RUN.

Note that the output is the same as sentnces.cbl:

OUTPUT:

C>pcobrun comment

Personal COBOL version 2.0 from Micro Focus

PCOBRUN V2.0.02 Copyright (C) 1983-1993 Micro Focus Ltd.

This program contains four DIVISIONS,

three PARAGRAPHS

and four SENTENCES

C>

ANALYSIS: As a historical note, the very first COBOL programs were written using punch cards. Each card carried one line of code that had been carefully entered using a keypunch machine (a kind of typewriter that punches holes in cards). The stack of punched cards was carried to the computer and fed into it using a card reader. An "out of sequence" warning was used to let you know that you probably had dropped the punch card deck and hadn't put them back together in the correct sequence. Compiler error messages also referred to line numbers, and locating an error was difficult without line numbers on the cards. PC COBOL compilers rarely give warnings about sequence.

Lines 000700 and 000800 contain an asterisk in column 7, the indicator area. Everything beyond the asterisk is ignored and can be used as a comment, as in the example.

DIVISIONs and paragraphs start in Area A but can extend into Area B.

Sentences begin and end in Area B. In Listing 1.5, sentences appear at lines 003700, 003800, 001000, and 001200.