Value Clause Example


Scenario - VALUE clause usage in COBOL programming.

Code -

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

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-STD-DETAILS.
           05 WS-STD-NUM          PIC 9(03) VALUE 1.
           05 WS-STD-NAME         PIC X(20) VALUE "PAWAN".
           05 WS-STD-GENDER       PIC X(01) VALUE "M".
              88 WS-VALID         VALUE 'M' 'F'.
              88 WS-MALE          VALUE 'M'.
              88 WS-FEMALE        VALUE 'F'.
           05 WS-STD-PERCENTAGE   PIC 9(03) VALUE 70.
              88 WS-FIRST-CLASS   VALUE 60  THRU 100.
              88 WS-SECOND-CLASS  VALUE 50  THRU 59.
              88 WS-THIRD-CLASS   VALUE 35  THRU 49.
              88 WS-FAIL          VALUE 00  THRU 34.
       PROCEDURE DIVISION.
   
           DISPLAY "Student initialization With value Clause".
           STOP RUN.

Explaining Example -

In the above example: it defines a data structure WS-STD-DETAILS containing various fields and its initialization using VALUE clause.

  • WS-STD-NUM, WS-STD-NAME, WS-STD-GENDER and WS-STD-PERCENTAGE are the variables that are initialized with a value.
  • WS-MALE, WS-FEMALE are condition names that are initialized with a single value.
  • WS-VALID is a condition name initialized with multiple values.
  • WS-FIRST-CLASS, WS-SECOND-CLASS, WS-THIRD-CLASS, and WS-FAIL is a condition name that are initialized with a range of values.