Home
About
TeleMarshal 
 System
Telemanagement 
 Dates Handling
COBOL 
 Standards
Customers
Contact
phone and shield
COBOL Programming Standards

Guide to Consistent and     
Effective Program Design     

 In a COBOL context           
with examples           
 

ID DIVISION.
PROGRAM-ID. program-name.
AUTHOR.
PAUL MCARDLE
INSTALLATION.  client-company.
DATE-WRITTEN.  date.
REMARKS.

     System Name  --  Program Name
      Program functional name
       Brief functional description.
                      

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. computer.
OBJECT-COMPUTER. computer.
INPUT-OUTPUT-SECTION.
FILE-CONTROL.
    SELECT file-name       ASSIGN TO name.

file-name. Use plain language file-names
    ending with -FILE; such as INPUT-FILE,
    MASTER-FILE, ACCOUNT-FILE.

DATA DIVISION.
FILE SECTION.
FD  file-name
    RECORDING MODE IS mode
    LABEL RECORDS ARE STANDARD
    (BLOCK CONTAINS ___ RECORDS)
    (RECORD CONTAINS ___ CHARACTERS)  
    (REPORT IS (REPORTS ARE) report-name-1,
        report-name-2 ...)

report-name. Use plain language report-names
    ending with -REPORT, or some other
    appropriate descriptor denoting a
    printed format, such as -LIST,
    -REGISTER, etc.

01 record-name, PIC X(___).

record-name. Use same name as file-name,
    except add the suffix -RECORD (or -REC.
    Define as an elementary data item,
    except where necessary to define key
    fields.

WORKING-STORAGE SECTION.

77-level entries. Used rarely, except for
    constants subject to occasional
    change, to make easier to locate.

01-level-entries. Used for major divisions
    of working-storage into areas for:
        literals
        flags
        record work areas
        record and key holding areas
        computing and edit areas
        print field areas
        table areas.

    subordinate level numbers are incre-
        mented by 5 and indented by
        multiples of 4 columns. Thus, 05
        level always appears in column
        12, 10 level in column 16, etc.
        When required, insert 07 level
        in column 14, level 12 in column
        18, etc.

    data-names are in plain language or
        mnemonics. All data-names within
        a given 01 level category or
        subcategory share a common one or
        two character prefix. Abbreviating
        conventions are used consistently
        when data-items are defined in
        several places; for example,
        TR-CUST and M-CUST, rather than
        TR-CUSTOMER and M-CUST.

    PIC begins in column 44.

    USAGE and VALUE are aligned at 56.

    redefining fields are highlighted by
        misaligning the PIC clause,
        relative to the redefined field,
        usually by putting it in column 56.

    numeric fields contain a sign
        specification unless its absence
        is specifically called for.

    packed fields are designed with an odd
        number of digits.

    binary fields are defined with 4, 9, or
        18 digits, and are synchronized,
        unless defined at the start of an
        01 level.

    table areas. Unless the table has only
        a few entries, or is accessed only
        by direct addressing, tables are
        set up so that binary searches
        (SEARCH ALL) can be used. The
        table-name is constructed with a
        mnemonic followed by -TABLE. The
        index name is 2 or 3 characters,
        with the last character X.
        Multiple indexes are numbered
        sequentially. An elementary item,
        outside but adjacent to the table,
        beginning with index-name and
        ending in -MAX, is initialized
        with a value equal to the number
        of entries specified in the OCCURS
        clause.
 
        Here's an example:


        01  TABLE-AREAS.
            05  L-LOCATION-LIST.
                10  FILLER       PIC X(12)  VALUE "1BOSTON".
                10  FILLER       PIC X(12)  VALUE "2NEW YORK".
                10  FILLER       PIC X(12)  VALUE "3WASHINGTON".
                10  FILLER       PIC X(12)  VALUE "4ATLANTA".
                10  FILLER       PIC X(12)  VALUE HIGH-VALUES.
            05  L-LOCATION-ARRAY REDEFINES L-LOCATION-LIST
                10  L-LOCATION-TABLE        OCCURS 5 TIMES
                        ASCENDING KEY L-TABLE-CODE
                        INDEXED BY LX, LX2, LX3.
                    15  L-TABLE-CODE        PIC X.
                    15  L-TABLE-NAME        PIC X(11).
            05  LX-MAX           PIC S9999  COMP SYNC VALUE 5.
            05  L-ENTRY.
                10  L-ENTRY-CODE PIC X.
                10  L-ENTRY-NAME PIC X(11).

        COPY areas appear at the end of working-storage,
             just before the LINKAGE SECTION, if it exists.


PROCEDURE DIVISION.

Modularity. Each program is modularized functionally into
             five types of paragraphs or sections:

        Control. Selects other modules to be performed.

        Housekeeping. Opens/closes files; initializes areas,
             records, and tables; performs beginning or ending
             tasks.

        Process. Manipulates data, either within itself, if the
             task is simple, or through the performance of other
             processes. (To the extent it does the latter, it
             becomes a Control module.)

        Input/Output. Reads or writes records and executes
             certain end of file procedures.

        Utility. Prints error messages, does table lookups, or
             does other kinds of processing that may be required
             at more than one point in the program.

Hierarchical Dependence. The MAIN module, which appears first,
        controls the overall logic of the program. (Paragraphs are
        preferred over Sections, which are used only if required by
        the compiler, such as when external sorting is performed.)
             The MAIN paragraph performs first-level modules,
        which are named beginning with a single non-zero digit
        followed by a functional name or mnemonic, separated by a
        dash. First level modules that involve roughly more than 20
        non-trivial lines of instruction are broken logically into
        Second level lower modules that are performed from the First
        level.
             Second level paragraphs will be named with the same
        1st digit as the performing routine, followed with a second
        digit of its own. Similarly, each Second level routine may
        perform Third level routines, which will have three digit
        prefixes and so on.
             These level modules constitute a strict tree structure.
        Each module in the tree is performed by one and only one
        higher level (lower numbered) module, but may itself perform
        one or more lower level (higher numbered) modules.
             Those functions that must be performed from several
        branches of the tree--whether Process, I/O, Housekeeping,
        or Utility--are grouped at the end of the program and given
        functional names or mnemonics.
             Calls to subroutines are grouped in separate paragraphs
        at the very end of the program and performed as needed.

Control Conventions
             PERFORM, PERFORM __ UNTIL, and PERFORM __ VARYING __
        UNTIL are the principal means to control program looping,
        and to conduct execution of lower level modules.
             GO TO's are avoided. One may be used (rarely) for
        exception branching, such as GO TO ABORT-EXIT. The preferred
        way of handing such exceptions is to set a flag that is
        tested at a higher level and acted upon there.
             IF statements are used as required for selective
        processing, but when compound or nested IF statements result
        in code that is difficult to interpret, PERFORM's are
        introduced.
             ALTER statements are not used.
 

An Example of a Naming Convention

        This is the naming convention adopted in TeleMar's
TeleMarshal® Telephone Management System for six character
program names and copy library (COPYLIB) data packet names.

Position 1-2   mnemonic   (TM for TeleMarshal)

Position 3     0 (zero)   Mainline Programs
               S          Subroutine Subprograms
               W          COPYLIB - Working-Storage areas
               L          COPYLIB - Linkage areas
               P          COPYLIB - Procedure areas

Position 4     0          Programs - Utility
               1          Programs - Daily/Monthly
               2          Programs - Telco Billing/Equip
               3          Programs - Call Accounting
               4          Programs - Traffic Analysis
               D          Subprograms - Database
               H          Subprograms - Help
               I          Subprograms - Input
               O          Subprograms - Output
               P          Subprograms - Processing
               T          Subprograms - Table
               U          Subprograms - Update
               Z          Subprograms - Intrinsic
               D          COPYLIB - Database Area
                                 or Detail Record
               F          COPYLIB - File Record
               M          COPYLIB - Master Record
               S          COPYLIB - Save Area

Position 5-6   Numeric    Programs    - Serial Number
           Alpha/numeric  Subprograms - Function Mnemonic
                          COPYLIB     - Function Mnemonic

        All data items in COPYLIB have 3 character prefixes
that are the same as position 4-6 of the packet name, except
for the name of the level 01 item, which is the same as the
six-character packet name.
        Programs which call subroutines use position 4-6 of
subroutine name as the prefix in the name of the paragraph at
the end of the program that contains the subroutine call.
        See the
sample program for examples.