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

NEGATED SIMPLE CONDITION

 
   
 

Any of the simple condition described above can be preceded by the logical operator NOT. The effect of placing the operator NOT before a simple condition is to reverse the value of the condition.

It may be seen that the operator NOT can be used in two ways. In simple conditions it can be used as a part of the condition. It can also be used to precede a simple condition to make it a negated simple condition.

An example of the first use may be DEPOSIT NOT LESS THAN 500.00, while an example of the second use is NOT DEPOSIT LESS THAN 500.00.

Of course, in this case, both the conditions mean the same thing and can be used in either form. What matters is the role of the operator NOT. In the former case NOT is part of a relational operator and in the latter case it is a logical operator. However, NOT must not precede a simple condition that includes NOT as a part if it.

 
   
   
  COMPOUND CONDITION  
   
 

Two simple conditions can be connected by the logical operators AND or OR to form a compound condition (also known as combined condition). When two conditions are combined by AND, the compound condition becomes true only when both the constituent conditions are true. In all other cases the compound condition is false.

On the other hand, if OR is used to combine two conditions, the compound condition is true if either or both the constituent conditions are true. It is false only when both the conditions are false.

Example:

 
  AMOUNT GREATER THAN 499 AND AMOUNT LESS THAN 1000.  
 

This compound condition which will be true only when the value of AMOUNT is in the range 500 to 999(inclusive of both). This is because both the simple conditions are true for these values of AMOUNT. For other values of AMOUNT, only one of them is true.

 
  AMOUNT LESS THAN 500 OR AMOUNT GREATER THAN 999.  
 

This compund condition will be false only when the value of AMOUNT is in the range 500 to 999.

 
 
A compound condition can consist of any number of simple or negated simple conditions joined either by AND or OR.

A compound condition has the following form:

 
   
 
 
 
Example:

 
  IF AGE IS LESS THAN 30 AND (HIGHLY-EDUCATED OR HIGHLY-EXPERIENCED)
MOVE 3 TO BONUS-CODE.
 
 

Here, HIGHLY-EDUCATED and HIGHLY-EXPERIENCED are condition names. If either of them is true and if AGE is less than 30, 3 will be moved to BONUS-CODE.

 
  Abbreviation:  
 

Consecutive relational conditions in a compound condition can be abbreviated:

1. When the subjects in the consecutive relational conditions are identical.

 
 
The compound condition
AMOUNT GREATER THAN 499 AND AMOUNT LESS THAN 1000.
can be abbreviated to
AMOUNT GREATER THAN 499 AND LESS THAN 1000.
 
 

2. When the subjects and relational operators in the consecutive relational conditions are Identical.

 
 

The compound condition
CARD-CODE = 3 OR CARD-CODE = 5 OR CARD-CODE = 7.
may be abbreviated to
CARD-CODE = 3 OR 5 OR 7.

The condition
AGE LESS THAN 30 AND NOT LESS THAN 20 OR 40.
is interpreted to be an abbreviation of the compound condition
AGE LESS THAN 30 AND AGE NOT LESS THAN 20 OR AGE NOT LESS THAN 40.

The condition
NOT AGE LESS THAN 20 AND 30.
will be interpreted to be an abbreviation of
NOT AGE LESS THAN 20 AND AGE LESS THAN 30.