COBOL - Negated Simple Condition
A simple condition is negated through the use of the logical operator NOT.
Format:
IF NOT [CONDITION]
COBOL Statements
END-IF. |
The negated simple condition gives the opposite truth value of the simple condition.
That is, if the truth value of the simple condition is true, then the truth value of that same negated simple condition is false, and vice versa.
Placing a negated simple condition within parentheses does not change its truth value. That is, the following two statements are equivalent:
NOT A IS EQUAL TO B.
NOT (A IS EQUAL TO B).
let's see the example:
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLOCOB.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NUM1 PIC 9(2) VALUE 20.
01 WS-NUM2 PIC 9(9) VALUE 25.
PROCEDURE DIVISION.
A000-FIRST-PARA.
IF NOT WS-NUM1 IS LESS THAN WS-NUM2 THEN
DISPLAY 'IF-BLOCK'
ELSE
DISPLAY 'ELSE-BLOCK'
END-IF.
STOP RUN.
|
When you compile and execute the above program, it produces the following result −
Output:
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!