TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

COBOL - Sign Condition


The sign condition determines whether the algebraic value of a numeric operand is greater than, less than, or equal to zero.

Syntax:

operand-1 IS [NOT] {POSITIVE/NEGATIVE/ZERO} 

operand-1

Must be defined as a numeric identifier, or as an arithmetic expression that contains at least one reference to a variable.

operand-1 can be defined as a floating-point identifier.

The operand is:
  • POSITIVE if its value is greater than zero

  • NEGATIVE if its value is less than zero

  • ZERO if its value is equal to zero
An unsigned operand is either POSITIVE or ZERO.

NOT

One algebraic test is executed for the truth value of the sign condition. For example, NOT ZERO is regarded as true when the operand tested is.

Example:

Program to demonstrate sign condition

IDENTIFICATION DIVISION.
PROGRAM-ID. SIGCCOBL.

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.

When you compile and execute the above program, it produces the following result −

Output :

NUMBER-1 IS NEGATIVE
NUMBER-2 IS POSITIVE



If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal