Module 3: COBOL Program structure
- COBOL source program must be written in a format acceptable to the COBOL compilers. Thus, COBOL programs are always written on COBOL Coding Sheet.
- The Coding Sheet has 80 character positions and these positions are grouped into the five fields Figure: - Illustration of COBOL Coding Sheet
- Margin A and Margin B actually contains the COBOL code.
- Sometimes Margin A and Margin B are also referred to as Area A and Area B
- Explanation of each of fields given as follows:-
Positions Field Explanation 1-6 Sequence Field
- Sequence Field is optional to specify
- It is usually used to give sequence number to the lines of code.
- This sequence number is formed by specifying page number on positions 1-3 and line number on positions 4-6
7 Indicator Field
- Indicator Field is optional to specify
- Coded asterisk(*) to indicate that the whole line is comment line
- Coded hyphen (-) to indicate that the current line is continuation of previous line
- Coded character D (single char D) to indicate that the current line is Debugging line. When DEBUGGING MODE is enabled in the program, these debugging lines are made part of program for debugging purpose. When DEBUGGIN MODE is not enabled, these lines will be considered as dummy lines (more information about DEBUGGING MODE and use of debugging line is provided in CONFIGURATION SECTION here )
- Coded slash (/) to indicate new page in the listing. i.e. The lines are printed after skipping to the top of the next page
- When left blank it will be considered as normal coding line
8-11 Margin A
- All Divisions, Sections, Paragraphs and some special entry declarations like ‘01’ and ‘77’ must start here
12-72 Margin B
- All Statements, Sentences and other entry declaration should be coded here
73-80 Identification Field
- As name suggests, it is used for identification purpose.
- COBOL programmers use this field as TAG field to identify their changes.
- COBOL compiler ignores this field of Coding Sheet
Explanation:-In above example, we can see, first 6 positions are used as sequence field. Actual coding is done in position 8-72. Asterisk at 7th position on line number ‘001000’ is used to comment the line. Character ‘D’ at 7th position on line number ‘000900’ is used for debugging purpose. Debugging clause is explained in more detail here . Character ‘-‘ at 7th position on line ‘001200’ is used to indicate the continuation from the previous line.