Condition Names References Example


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

Code -

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

       DATA DIVISION.
       WORKING-STORAGE SECTION.
	   
       01 WS-GROUP1. 
          05 WS-GENDER         PIC X(01).
             88 MALE           VALUE 'M'.
             88 FEMALE         VALUE 'F'.  
       01 WS-GROUP2.
          05 WS-GENDER         PIC X(01).
             88 MALE           VALUE 'M'. 
             88 FEMALE         VALUE 'F'.
 
       PROCEDURE DIVISION. 

           MOVE 'M'     TO WS-GENDER OF WS-GROUP1.
           IF MALE OF WS-GROUP1 
              DISPLAY 'PERSON IS MALE'
           ELSE 
              DISPLAY 'PERSON IS FEMALE'
           END-IF.
           STOP RUN.

Output -

PERSON IS MALE

Explaining Example -

In the above example:

  • WS-GENDER is an elementary item declared under group items WS-GROUP1 and WS-GROUP2.
  • WS-GENDER declared with condition names MALE and FEMALE. Those condition names are not unique and should have a reference in the program. So, the MALE condition name under WS-GROUP1 refers to MALE OF WS-GROUP1 or MALE IN WS-GROUP1. Similarly, references should code for the FEMALE condition name.