COBOL Coding Rules

COBOL coding rules are very important and you should follow a particular COBOL format because of COBOL of structured programming language.

This picture shows the major areas in a COBOL Program.

TutorialBrain - Area in COBOL Program

Areas in COBOL Program

There are 5  areas in COBOL Program –

  1. Sequence Number Area
  2. Indicator Area
  3. Area A
  4. And Area B
  5. Program Identification Area

1. Sequence Number Area

  • Column 1 to Column 6 is the Sequence Number area.
  • The Sequence number area stores the Sequence numbers.
  • And it’s number is for labeling a source statement line.

In the above picture of a COBOL program, the numbers in yellow area(column 1-6) are Sequence numbers.

Question: Can you find the sequence numbers in the below?

|----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 000001  01 SEQUENCE-NUMBER  PIC 9(03.
000002 01 WS-TEMP-VAR PIX X(3).

Answer

000001
000002

2. Indicator Area

  • Column 7 is the Indicator Area in COBOL.
  • You can start Comments, Continuation or Debugging mode(D) in this Indicator Area.

The Syntax of Comment:

|----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
000001  *THIS IS A COMMENT IN COBOL

Example of Comments in the COBOL program

Comments in COBOL

The Syntax of Continuation:

|----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 000001 - 

The Syntax of Debugging:

|----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 000001 D 

3. Area A

  • Area A Starts from Column 8 to Column 11.
  • All Division, Section, Paragraph, Start Declarative, End Declarative, 01 Level number must start in Area A.

Example of Area A

Area A In COBOL

In this sample screenshot, you can see that DIVISION, SECTION and 01 LEVEL starts from Area A.

4. Area B

  • Area B Starts from Column 12 to Column 72.
  • All Statement, Sentence, Verbs, Clause,  Characters, and Words must start in Area B.
The Sentence is divided into various types of Statements and there can be one or more statements in a sentence.
Let us take all the lines one by one –
Line1 –  MOVE “HELLO WORLD” TO WS-HELLO.
            This is a Sentence which is also a Statement.
 
Line2 –  MOVE A TO B
            This is a Statement.
 
Line3 –  MOVE C TO D
            This is also a Statement.
 
Line4 – COMPUTE E = C + D.
            This is also a Statement.
 
If we combine Line 2, Line 3 and Line 4, then it becomes a Sentence so at the end of a Sentence, we must have a dot(.).

In, MOVE A TO B, MOVE is a verb.

Similarly, COMPUTE E = C + D. -> Here COMPUTE is also a Verb.

Example of Area B

Area B in COBOL. This contains sentence, clause, statements, words

In this sample screenshot, you can see that statement, sentence etc are starting in Area B.

5. Program Identification Area

  • Program Identification area in COBOL Program is the area between column 73 to column 80.
  • They do not have much relevance in today’s world.
  • The idea of using this area was to enter the program identification of each individual lines in the code.

Example of Program Identification Area

Program Identification in COBOL

Tutorials for all brains!