Sign Condition in COBOL

Sign Condition

  • The sign of numeric operand is checked by using sign condition.
  • A given value for the conditions such as greater than, less than or equal to zero is determined using a sign condition.
Syntax for sign condition is:
[Data Name/Arithmetic Operation]
[IS] [NOT]
[Positive, Negative or Zero]
[Data Name/Arithmetic Operation]

Example : Program to demonstrate sign condition

IDENTIFICATION DIVISION.
PROGRAM-ID. SIGC.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 N1 PIC S9(9) VALUE -678.
   01 N2 PIC S9(9) VALUE 78923.

PROCEDURE DIVISION.
   A000-FIRST-PARA.
   IF N1 IS POSITIVE THEN
      DISPLAY 'NUMBER-1 IS POSITIVE'.
      
   IF N1 IS NEGATIVE THEN
      DISPLAY 'NUMBER-1 IS NEGATIVE'.
      
   IF N1 IS ZERO THEN
      DISPLAY 'NUMBER-1 IS ZERO'.

   IF N2 IS NEGATIVE THEN
      DISPLAY 'NUMBER-2 IS NEGATIVE'.
      
   IF N2 IS POSITIVE THEN
      DISPLAY 'NUMBER-2 IS POSITIVE'.

STOP RUN.


Output:
NUMBER-1 IS NEGATIVE
NUMBER-2 IS POSITIVE