Wednesday, December 15, 2010

COBOL PROGRAMMING STANDARDS

6.1       COBOL and Advanced COBOL Programming
This page defines the standards your program source code must meet. See the sample program for examples of the implementation of these standards.
6.2       General Coding Standards
  • Source code should be all UPPER-CASE except for comments.
  • Use proper indentation; set tab stops to every 4 columns (8, 12, 16, ...).
  • Separate the logical sections of source code with blank lines to make it easier to read.

6.3       IDENTIFICATION Division
  • The PROGRAM-ID should be the source code filename (8 characters maximum, no extension).
  • AUTHOR should be your name.
  • Use the DATE-WRITTEN paragraph with the date you turned in the program, in the form YYYY-MM-DD.
  • Include a comments with at least these headings:
  • FUNCTION. Brief statement of the function of the program.
  • INPUT FILES. Logical and physical filenames and the sort sequence (sort fields and sort order: ASC for ascending, DESC for descending, or UNSORTED) for each input file.
  • OUTPUT FILES. Logical and physical filenames, and the sort sequence of each output file.
  • PRINT OUTPUT. Brief description of each report generated. Note: consider all print-image output to be printed output, even if it is directed to a disk file for later printing).

6.4       ENVIRONMENT Division
  • In the FILE-CONTROL paragraph of the INPUT-OUTPUT SECTION, SELECT files in the same order in which they are referenced in your program.
  • ASSIGN files using direct, complete physical filenames (drive:\path\filename.ext)

6.5       DATA Division
Level numbers
  • Leave a blank line before each 01 level number
  • Use level numbers in increments of 5 (05, 10, 15, ...)
  • Indent each higher level number to next tab stop; align like level numbers to same tab stop
PICTURE clauses
  • Data type of data item should agree with its primary usage; it should be alphanumeric unless used for computation, subscripting, or edited-numeric output
  • PIC clauses should all be aligned to same tab stop regardless of level
6.6       FILE section
  • Logical file names should be descriptive and be suffixed -FILE.
  • File descriptions (FDs) should appear in the same order as in the FILE-CONTROL paragraph.
  • Use the RECORD CONTAINS clause in all FDs.
  • Record names (the 01-level entry on an FD) should be the same as the logical file name, with the suffix -REC.
  • Data items under the 01 level should have a 2-character prefix associating the item with its record.
6.7                WORKING-STORAGE section
Use descriptive, distinctive data item names, prefixed and suffixed as described below.
Do not initialize elementary items except for constants and constant values used to print/display; explicitly initialize other data items in the PROCEDURE DIVISION.
Group all data items under 01 levels in the following order:
  • 01 ACCUMULATORS. (prefix A-)
  • 01 CONSTANTS. (prefix C-)
  • 01 FLAGS. (prefix F-)
  • 01 PRINT-LINES. (prefix P-, and suffix as below)
  • -PHn for page header line n
  • -CHn for column header line n
  • -DLn for detail line n
  • -TLn for total line n
  • -JCn for job control line n)
  • 01 TABLES. (prefix T-)
  • 01 WORK-AREAS. (prefix W-)

6.8       PROCEDURE Division
Organization
  • Use meaningful paragraph names, each prefixed with an ascending four-digit number, with gaps sufficient to allow for program maintenance.
  • If organized into sections, prefix the names with ascending, single alphabetic character followed by 4 zeros, e.g.: A0000-ERROR-HANDLING SECTION. Paragraph names will be prefixed with the letter corresponding to the section and ascending 4-digit numbers.
  • Each paragraph must start with a comment listing the paragraphs from which it is PERFORMed, its purpose (if not obvious from the paragraph name) and an explanation of the logic if not straight-forward.
Modularity
  • The first paragraph should control the flow of program execution (the "driver"); it should be named 0000-MAINLINE.
  • PERFORM each paragraph except 0000-MAINLINE; program control should not "fall through" to the next paragraph.
  • Each paragraph must be a functionally independent unit of code with one entrance and one exit.
  • A paragraph cannot consist of a single PERFORM statement; it should be no longer than 15 statements (excluding comments).
Readability and Maintainability
  • Start each statement on a new line; indent the second and succeeding lines of a multiple line statement to the next tab stop.
  • Start clauses on a separate line, and indent them within a statement.
  • Leave a blank line before every selection and iteration structure.
  • Align the word TO in a sequence of MOVE statements.
  • Code literals only when the value will never need to be changed, and when its meaning is obvious.
  • Use scope terminators (END-IF, END-READ, etc.) unless the statement contains no clauses; align the terminator to the same tab stop as the statement it terminates.
  • Use parentheses in compound IFs and COMPUTEs for clarity.
  • Avoid use of PERFORM ... THRU, GO TO, and MOVE CORRESPONDING.
  • Comment liberally if the code is not straight-forward, but avoid useless comments.

Print Output
  • Every printed report must have a page heading on each page that includes:
  • Report title
  • Run date in the form YY/MM/DD
  • Page number
  • Unless otherwise specified, use these report formatting standards:
  • 50-column print width
  • 40 total print lines per page
  • Page header on line 1 followed by two blank lines, column header(s) followed by one blank line, then single-spaced detail lines

No comments:

Post a Comment