Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
like image 529
mllamazares Avatar asked May 18 '18 07:05

mllamazares


People also ask

What is paragraph in COBOL?

Paragraphs are the subdivision of a section or division. It is either a user-defined or a predefined name followed by a period, and consists of zero or more sentences/entries. Sentences are the combination of one or more statements. Sentences appear only in the Procedure division. A sentence must end with a period.

What is the difference between performing a section and a paragraph?

Performing a SECTION will cause all the paragraphs that are part of the section, to be performed. Performing a PARAGRAPH will cause only that paragraph to be performed.

What are level numbers in COBOL?

A level-number is a one-digit or two-digit integer between 01 and 49, or one of three special level-numbers: 66, 77, or 88. The following level-numbers are used to structure records: 01. This level-number specifies the record itself, and is the most inclusive level-number possible.

Is Procedure Division mandatory in COBOL?

The Procedure Division is optional in a COBOL source program. The Procedure Division consists of optional declaratives, and procedures that contain sections and/or paragraphs, sentences, and statements. The structure of the Procedure Division is as follows: Format 1 - with Sections and Paragraphs.


2 Answers

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.

like image 86
Bruce Martin Avatar answered Nov 30 '22 06:11

Bruce Martin


The 4 digit number isn't really used for anything BUT if the program is structured correctly it can help an experienced programmer know their way around the program. Lets look at this example:

PROCEDURE DIVSION.
0000-MAINLINE.
   PERFORM OPEN-FILES
   PERFORM VALIDATE-CONTENTS
   PERFORM PROCESS-DATA
   PERFORM WRITE-REPORTS
   PERFORM CLOSE-FILES
.
CLOSE-FILE.
   PERFORM CLOSE-FILE1
   PERFORM CLOSE-FILE2
   PERFORM CLOSE-FILE3
.
PROCESS-DATA.
   PERFORM VARYING X 
              FROM 1 BY 1
             UNTIL X > NUMBER-OF-RECS
      PERFORM DO-THE-THINGS
   END-PERFORM
.
WRITE-REPORTS.
   DISPLAY 'THIS IS MY REPOR'.
.
VALIDATE-CONTENTS.
   IF REC NOT EQUAL SPACES
       SET GOOD-REC TO TRUE
   END-IF
.
OPEN-FILES.
   PERFORM OPEN-FILE1
   PERFORM OPEN-FILE2
   PERFORM OPEN-FILE3
.
DO-THE-THINGS.
   CONTINUE
.

I am aware the program is silly and doesn't really make sense, but that's ok for this example. Try to follow the flow of this program. If we assign a number to each paragraph start and one and increment (so CLOSE-FILE is 1, PROCESS-DATA is 2...) then the mainline is jumping around like this:

5

4

2, 6

3

1

That "ok" for a small program like this, because we can still find our way around. Now imagine your program is thousands of lines long and everything is out of order. Yes you can figure it out, but wouldn't it be much easier if it looked like this:

PROCEDURE DIVSION.
0000-MAINLINE.
   PERFORM A0000-OPEN-FILES
   PERFORM B0000-VALIDATE-CONTENTS
   PERFORM C0000-PROCESS-DATA
   PERFORM D0000-WRITE-REPORTS
   PERFORM E0000-CLOSE-FILES
.
A0000-OPEN-FILES.
   PERFORM OPEN-FILE1
   PERFORM OPEN-FILE2
   PERFORM OPEN-FILE3
.
B0000-VALIDATE-CONTENTS.
   IF REC NOT EQUAL SPACES
       SET GOOD-REC TO TRUE
   END-IF
.
C0000-PROCESS-DATA.
   PERFORM VARYING X 
              FROM 1 BY 1
             UNTIL X > C1000-NUMBER-OF-RECS
      PERFORM DO-THE-THINGS
   END-PERFORM
.
C1000-DO-THE-THINGS.
   CONTINUE
.
D0000-WRITE-REPORTS.
   DISPLAY 'THIS IS MY REPOR'.
.
E0000-CLOSE-FILE.
   PERFORM CLOSE-FILE1
   PERFORM CLOSE-FILE2
   PERFORM CLOSE-FILE3
.

At my shop the way we do it is everything in the mainline starts with a letter (hence A0000). If A0000 calls something that paragraph will be called A1000. If A1000 calls something it will be A1100. So we use the character to indicate nesting. so I might have something that looks like this:

PROCEDURE DIVSION.
0000-MAINLINE.
   PERFORM A0000-DO-SOMETHING
   PERFORM B0000-SHUTDOWN
.
A0000-DO-SOMETHING.
   PERFORM A1000-DO-MORE
   PERFORM A2000-VALIDATE-STUFF
.
A1000-DO-MORE.
   PERFORM A1100-DO-THING1
   PERFORM A1200-DO-THING2
   PERFORM A1300-DO-THING3
.

In short, it just helps with navigation and following the program. There is nothing stopping you from omitting the numbers, but once the program gets bigger and someone else needs to maintain it the numbers will be a great help. I loath working on programs that are not structured properly because it makes debugging and learning the program that much more difficult. Especially when I am using a terminal emulator and can only see 20 lines at a time.

like image 29
SaggingRufus Avatar answered Nov 30 '22 06:11

SaggingRufus