Paragraph Names References Example


Scenario - Below example describes how the references used for procedure division names in COBOL programming.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION. 
       PROGRAM-ID. DREFPDN. 
       AUTHOR. MTH. 

       DATA DIVISION.
       WORKING-STORAGE SECTION.

       01 WS-GROUP1.
          05 WS-GENDER         PIC X(01). 
             88 MALE           VALUE 'M'. 
             88 FEMALE         VALUE 'F'. 

       PROCEDURE DIVISION.

           MOVE 'M'     TO WS-GENDER OF WS-GROUP1. 
 
           PERFORM PARAGRAPH1 OF SECTION1.
           STOP RUN.

       SECTION1 SECTION.
       PARAGRAPH1.
           IF MALE OF WS-GROUP1
              DISPLAY 'PERSON IS MALE' 
           ELSE
              DISPLAY 'PERSON IS FEMALE'
           END-IF.

       SECTION2 SECTION.
       PARAGRAPH1.
           IF MALE OF WS-GROUP1 
              DISPLAY 'PERSON IS MALE'
           ELSE 
              DISPLAY 'PERSON IS FEMALE'
           END-IF.

Output -

PERSON IS MALE

Explaining Example -

In the above example:

  • PARAGRAPH1 is a paragraph declared under section SECTION1, SECTION2.
  • The paragraph PARAGRAPH1 is not unique and should have a reference while used in the program. So, PARAGRAPH1 under SECTION1 refers to PARAGRAPH1 OF SECTION1 or PARAGRAPH1 IN SECTION1. Similarly, references should code for PARAGRAPH1 under SECTION 2.