sign in
 
   
 
 
 
   
  COBOL TUTORIAL FOR BCA STUDENTS OF M G UNIVERSITY  
  UNIT 4: PROCEDURE DIVISION . . .  
   
 

CONDITIONS-NAME CONDITION

 
   
 

A condition name is an entity which itself is a condition and as such can have either a true or false value. However, a condition name cannot be defined independently. It must always be associated to a data name called the conditional variable. The condition name may be defined in any section of the DATA DIVISION and must be placed immediately after the entry that defines the conditional variable. There can be more than one condition names associated to a conditional variable. In that case all the condition name entries must follow the entry defining the conditional variable.

A condition name entry specifies either a single value or a set of values and/or a range of values for the conditional variable. The condition name becomes true whenever the conditional variable assumes any of these values. Otherwise, the condition name is set to false. It must be noted that it is not possible to set the value of a condition name explicitly. The value of a condition name is always set implicitly depending on the current value of the conditional variable.

The format of the condition name entry is given below:

 
   
 

The following rules apply for a condition name:

1. Condition names must be described at level 88. The level number begins in margin A or any position after it. The condition name must begin from margin B or any position after it. There must be at least one space between the level number and condition name.

2. The normal rules for naming a data item also apply in the case of a condition name.

3. If the same condition name is used in more than one place, the condition name must be qualified by the name of its conditional variable.

4. The name of the conditional variable can be used as a qualifier for any of its condition names. If the reference to a conditional variable requiresqualification or subscripting, the same combination of qualification or subscripting must also be used for the associated condition name.

5. The values specified through the VALUE clause in the condition name entry must not conflict with the data description of the conditional variable. A literal in the VALUE clause can either a numeric literal, non numeric literal or figurative constant.

6. When the THRU/THROUGH phrase is used, literal – 1 must be less than literal – 2 and literal – 3 must be less than literal- 4.

7. A conditional variable can be an elementary item or a group item. However, it cannot be another condition name, or a 66-level item (RENAMES clause) or a group containing the JUSTIFY clause, or the SYNCHRONIZED clause or the USAGE clause other than DISPLAY.

Example:

 
 
77 MARITAL-STATUS PIC 9.
88 SINGLE VALUE IS ZERO.
88 MARRIED VALUE IS 1.
88 WIDOWED VALUE IS 2.
88 DIVORCED VALUE IS 3.
88 ONCE-MARRIED VALUE ARE 1, 2, 3.
88 VALID-STATUS VALUE ARE 0 THRU 3.
 
 

It may be noted that six condition names have been defined here. All of them are associated with the conditional variable MARITAL – STATUS. If at a point of time, MARITAL STATUS gets the value of 2, then the condition names WIDOWED, ONCEMARRIED and VALID-STATUS will become true and others will become false.

The condition names can be used as conditions.

Thus in PROCEDURE DIVISION we may have statements, such as:

(a) IF SINGLE SUBTRACT 125 FROM DEDUCTIONS.
(b) IF ONCE-MARRIED ADD 32 TO SPECIAL-PAY.
(c) IF NOT VALID–STATUS GO TO ERROR–IN–STATUS.

In (a) SUBTRACT 125 FROM DEDUCTIONS will be executed if MARITAL-STATUS is equal to zero. Similarly, in (b) the ADD statement will be executed only when MARITAL–STATUS is equal to 1, 2 or 3 and in (c) the control goes to the procedure ERROR-IN–STATUS only when MARITAL-STATUS has a value other than the 0, 1, 2 or 3. As in (c) a condition name can be preceded by NOT to indicate the negation of the condition.