Search code examples
optimizationcobolmainframezos

What is the logic behind COBOL paragraph numbering?


I've seen the following paragraph naming structure lots of times:

nnnn-PARAGRAPH-NAME.

Where nnnn stands for a 4 digit number.

Here is a complete example:

0000-MAINLINE. 
    PERFORM 1000-INITIALIZE-THE-PROGRAM. 
    PERFORM 2000-PROCESS-1-BILLING-RECORD 
        UNTIL 88-100-ALL-RECORDS-PROCESSED. 
    PERFORM 3000-TERMINATE-THE-PROGRAM. 
    GOBACK. 
1000-INITIALIZE-THE-PROGRAM. 
    PERFORM 1100-VALIDATE-CONTROL-CARD. 
    PERFORM 1200-OPEN-THE-FILES. 
    PERFORM 8000-GET-NEXT-BILLING-RECORD. 
1100-VALIDATE-CONTROL-CARD. 
    PERFORM 1110-READ-CONTROL-CARD. 
    PERFORM 1120-EDIT-CONTROL-CARD. 
1110-READ-CONTROL-CARD. 
    PERFORM 9000-ABEND-THE-PROGRAM.  *> IF A READ ERROR OCCURRED 
1120-EDIT-CONTROL-CARD. 
    PERFORM 9000-ABEND-THE-PROGRAM   *> IF AN EDIT ERROR OCCURRED 
1200-OPEN-THE-FILES. 
    PERFORM 9000-ABEND-THE-PROGRAM   *> IF AN OPEN ERROR OCCURRED 
2000-PROCESS-1-BILLING-RECORD. 
    PERFORM 2100-CALCULATE-BILLABLE-AMT. 
    PERFORM 2200-PRINT-BILLING-REPORT. 
    PERFORM 8000-GET-NEXT-BILLING-RECORD. 
2200-PRINT-BILLING-REPORT. 
    PERFORM 2210-PRINT-REPORT-HEADER.  *> WHEN IT'S NEEDED 
3000-TERMINATE-THE-PROGRAM. 
    PERFORM 3100-CLOSE-THE-FILES. 
    PERFORM 3200-DISPLAY-FINAL-MESSAGES. 
8000-GET-NEXT-BILLING-RECORD. 
    PERFORM 9000-ABEND-THE-PROGRAM.    *> IF A READ ERROR OCCURRED 
9000-ABEND-THE-PROGRAM. 

Therefore, my questions are the following:

  1. Is this deprecated nowadays?
  2. Why is (or was) it a good practice?
  3. Which criteria does the paragraph numbering follow?

Solution

  • Explanation

    The numbers tell you the program structure. In this program:

    • 1* are all initialization procedures and 1000-... calls 1100-... and 1200-. While 1100-... calls 1110-... and 1120-... etc
    • 2* is the main processing logic procedures
    • 3* is the finalization processing logic procedures
    • 8000 called from anywhere
    • 9000 error procedures

    So the program call structure is

                                         0000-
               +---------------------------+------------------------------+                             
             1000-                       2000-                          3000-
      +--------+------+             +------+------+               +-------+-------+ 
    1100-           1200-         2100-         2200-           3100-           3200-
    
     etc...
    

    Specific Questions

    1. Is this deprecated nowadays? Absolutely not, It should be used in other procedural languages. Learn the numbering system
    2. Why is (or was) it a good practice? It is good practice because it tells you
      • How procedure relate to one another - that can be very handy.
      • The call structure for getting to a procedure
      • Improves understanding
      • saves a lot of time. For exaple if you find 2000- you will go to the main processing logic
    3. Which criteria does the paragraph numbering follow?

    Other points

    Once you get used to the numbering system it makes understanding program so much easier. Different sites do it differently, some may use letters as well/instead of numbers e.g.

          Perform A000-Initialise
          Perform B000-Main
          Perform C000-Finalise
    
     A000-Initialise.
         Perform A100-...
         etc
    

    At any one site, they will use the same numbering standard across all (or most programs).

    Sites might reserve the first number/letter for specific purposes. This is more common if using A000-, B000- format. You might use R... for file reads W... for file writes S... for SQL calls etc.

    The numbering system makes life easier for the experienced programmer. Having worked in other languages, it should be used other procedural languages other than Cobol.