BLANK WHEN ZERO Clause


BLANK WHEN ZERO clause defines a variable filled with spaces when its value is zero. It is coded with a numeric variable, or its picture clause is defined as numeric-edited. This clause is used only on elementary variables and is coded anywhere in Area B but not in Area A.

Syntax -

BLANK WHEN ZERO Clause Syntax
Note! All statements coded in [ ] are optional.

Rules -

  • The elementary variables must be declared as USAGE DISPLAY.
  • Numeric-edited items with BLANK WHEN ZERO shouldn't use in Arithmetic operations (ADD, SUBTRACT, MULTIPLY, DIVIDE, and COMPUTE).
  • It should not come up with level-66 and level-88.
  • It should not code with the variables declared with S or *.

Practical Example -


Scenario - Below example describes how the constants are used in COBOL programming.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. BWHENZER.
       AUTHOR. MTH. 

       DATA DIVISION.
       WORKING-STORAGE SECTION. 
       01 WS-VAR. 
          05 WS-NED-VAR    PIC ZZ,ZZ9.9(2).
	  * Declaring a variable with BLANK WHEN ZERO
          05 WS-BWZ-VAR    PIC ZZ,ZZ9.9(2) BLANK WHEN ZEROES.

       PROCEDURE DIVISION. 

           MOVE ZEROES         TO WS-NED-VAR 
                                  WS-BWZ-VAR.
           DISPLAY "WS-NED-VAR: " WS-NED-VAR. 
           DISPLAY "WS-BWZ-VAR: " WS-BWZ-VAR.
           DISPLAY " ".

           MOVE 20000          TO WS-NED-VAR 
                                  WS-BWZ-VAR.
           DISPLAY "WS-NED-VAR: " WS-NED-VAR.
           DISPLAY "WS-BWZ-VAR: " WS-BWZ-VAR. 
           STOP RUN. 

Output -

WS-NED-VAR:      0.00  
WS-BWZ-VAR:            

WS-NED-VAR: 20,000.00  
WS-BWZ-VAR: 20,000.00  

Explaining Example -

In the above example:

  • Initially, ZEROES assigned to all variables. WS-BWZ-VAR zero value replaced with spaces while displaying.
  • Next, 20000 value assigned to all variables. All variables displays 20000 including WS-BWZ-VAR.