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.
Areas in COBOL Program
There are 5 areas in COBOL Program –
- Sequence Number Area
- Indicator Area
- Area A
- And Area B
- 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.
Comments To give a comment a line in COBOL, you can give an 'asterisk' i.e. '*' symbol in Column 7
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
Continuation If you are writing a COBOL program and for some reason, you are not able to fit your current code in a line, then you can continue it from the next line by providing a hyphen i.e. '-' symbol in the 7th column.
Note: We will discuss Continuation in detail as we will move further.
Note: We will discuss Continuation in detail as we will move further.
The Syntax of Continuation:
|----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
000001 -
Debugging Sometimes, we want to debug a COBOL program for the possible list of lines which might be causing an issue so what we do is, we code a character 'D' in 7th column which tells the compiler that this line is used for Debugging purpose. You can code 'D' for suspected lines and once you have found the issue, you can remove the 'D' from the 7th column.
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
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
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.