Relation Condition in COBOL

Relation Condition

  • Two operands are compared in relation condition.
  • The operands can be an identifier, literal or an arithmetic expression.
Syntax:
[Data Name/ Arithmetic Operation] [IS] [NOT]
[Equal to (=), greater than (>), Less than (<), greater than or equal (>=), Less than or equal(<=) ]
[Data Name/ Arithmetic Operation]

Example : Program to demonstrate relation condition

IDENTIFICATION DIVISION.
PROGRAM-ID. RC.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 N1 PIC 9(3).
   01 N2 PIC 9(5).

PROCEDURE DIVISION.
   A000-FIRST-PARA.
   MOVE 47 TO N1.
   MOVE 50 TO N2.
   
   IF N1 IS GREATER THAN OR EQUAL TO N2 THEN
      DISPLAY 'NUMBER-1 IS GREATER THAN NUMBER-2'
   ELSE
      DISPLAY 'NUMBER-1 IS LESS THAN NUMBER-2'
   END-IF.
   
STOP RUN.


Output:
NUMBER-1 IS LESS THAN NUMBER-2