COBOL: Coding standards to use for CIS 314
Coding standards for CIS 314
(last updated
April 14, 1999)
General
- All work must be your own. You may confer with a classmate on
general discussions but your valid resources are your kind-hearted
instructor, your talented grader and your wise consultant.
- All text in COBOL source code must in upper case, with the exception
of literals (i.e. VALUE clauses, prompts).
- All file names, record names, field names and paragraph names must
be descriptive.
- All division, section and paragraph names start in column 8.
Back to Table of Contents
Identification Division
- PROGRAM-ID must be the same as file name containing the source code
(without the .cob). For example, LAB1A.
- AUTHOR is required and is to contain your name, first name first.
It will be a comment so have an '*' in column 7.
- The other sections (INSTALLATION, etc.) are optional. If included, they
must also be comments.
- All of the values associated with the sections are to be vertically
aligned.
- Each section name and its associated value are to be on the same
line.
- This division ends with a comment (do not use the section name 'REMARKS')
describing what this program is supposed to accomplish.
Back to Table of Contents
Environment Division
- SOURCE-COMPUTER and OBJECT-COMPUTER are both to be HP-ACUCOBOL.
- SOURCE-COMPUTER and OBJECT-COMPUTER are to use only one line each.
- The values of the SOURCE-COMPUTER and OBJECT-COMPUTER are to be
vertically aligned.
- Each SELECT is to use only one line.
- The words 'SELECT' and 'ASSIGN TO' are to be vertically aligned.
- Can assign all files to DISK, nothing will go directly to the
printer.
Back to Table of Contents
Data Division
- All PIC clauses must be vertically aligned, at least within an
01-level field (a 'PIC' must start in the same column as the other PICs
in the same 01-level field but not necessarily in the same column as all
of the other PICs in the program).
- All level numbers are to be vertically aligned with other level
numbers of the same value, at least within an 01-level field (an '05'
level number must start in the same column as the other '05's in the
same 01-level field but not necessarily in the same column as all of the
other '05's in the program).
- Record names start in column 12.
- Put two spaces between the level number and the field-name.
- Level numbers are 4 columns in from the previous level number
('01' level number is in column 8. If '05' is the next one used it will
be in column 12 with all the other '05's, etc.).
- Use the repetition factor in PIC clauses if a PIC character is repeated
4 or more times (PIC 9(5) instead of PIC 99999).
- The level number, field name and PIC are to be on the same line.
- Vertically align all 'VALUE's within an 01-level field whenever
possible.
- All WORKING-STORAGE field names begin with a 'W-'.
- The word FILLER is optional. It is OK to use no name at all.
Back to Table of Contents
Procedure Division
(See language reference examples for
acceptable formatting of statements)
- Close every file you open.
- Have separate paragraphs for initialization and termination tasks.
Perform each only once, do not have it in a loop.
- Code only one STOP RUN. It is to be in the main paragraph (the one
that immediately follows the words 'PROCEDURE DIVISION'), not in the
termination paragraph.
- Precede each paragraph with a short comment describing the function
of the paragraph.
- Paragraph names start with a 3 or 4 digit number (be consistant
throughout the program - do not miz 3 and 4 digit prefixes), followed by
descriptive text (i.e. 100-INITIALIZE, 8200-READ-PAYROLL-RECORD). The
physical location of these paragraphs is determined by this numeric
prefix.
- Each paragraph is to perform a specific task. Do not have one paragraph
do too much.
- READS and WRITES should be in their own paragraphs.
- Only code one statement in either the AT END or NOT AT END clauses of
a READ. The ACUCOBOL compiler has been known to get lost if there's more
than one. The one statement can be a PERFORM.
- All statement clauses (i.e AT END for a READ, UNTIL/WHILE/VARYING for a
PERFORM, etc.) are to be indented from the statement.
- Indent code that is inside an IF or ELSE.
- All end-delimiters (i.e. END-IF, END-READ, etc.) are vertically aligned
with the statement they are delimiting.
- Every IF has an END-IF.
- Every READ has an END-READ.
- If using one of the clauses of a WRITE (i.e. BEFORE, AFTER, FROM) then
have an END-WRITE.
- When nesting IFs do not go more than 4 levels deep. If logically
necessary then place the extras in another paragraph and PERFORM it.
- Do not mix WRITE AFTERs and WRITE BEFOREs in the same program.
Back to Table of Contents