Summary -

In this topic, we described about the BLANK WHEN ZERO Clause with detailed example.

BLANK WHEN ZERO clause specifies an item filled with spaces when its value is zero.

This clause used only for elementary items where its PICTURE clause defined as category numeric-edited or numeric without the symbol S or *.

A BLANK WHEN ZERO clause is specified for a numeric item where its picture clause defined as category numeric-edited.

When BLANK WHEN ZERO clause specified with numeric data item, it can be specified as numeric-edited item.

Syntax -


These items must be specified as USAGE DISPLAY either implicitly or explicitly. This clause can be specified anywhere in the Area B but not in Area A.

Rules -

  • Numeric-edited items with BLANK WHEN ZERO should not use as operands in Arithmetic operations (ADD, SUBTRACT, MULTIPLY, DIVIDE and COMPUTE).
  • BLANK WHEN ZERO clause should not come up with level-66 and level-88.
  • BLANK WHEN ZERO should not specify with the variables that are declared with S or *.

Practical Example -

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

Code -

bwz program Code
***************************** Top of Data ******************************
       IDENTIFICATION DIVISION.                                         
       PROGRAM-ID. BWHENZER.                                            
       AUTHOR. MTH.                                                     
       DATA DIVISION.                                                   
       WORKING-STORAGE SECTION.                                         
       01 WS-VAR        PIC 9(5).9(2).                                  
       01 WS-NED-VAR    PIC ZZ,ZZ9.9(2).                                
       01 WS-BWZ-VAR    PIC ZZ,ZZ9.9(2) BLANK WHEN ZERO.                
       PROCEDURE DIVISION.                                              
           MOVE ZEROES         TO WS-VAR                                
           DISPLAY "WS-VAR:     " WS-VAR.                               
           DISPLAY "WS-NED-VAR: " WS-NED-VAR.                           
           DISPLAY "WS-BWZ-VAR: " WS-BWZ-VAR.                           
           DISPLAY " ".                                                 
           MOVE 20000          TO WS-VAR                                
           DISPLAY "WS-VAR:     " WS-VAR.                               
           DISPLAY "WS-NED-VAR: " WS-NED-VAR.                           
           DISPLAY "WS-BWZ-VAR: " WS-BWZ-VAR.                           
           STOP RUN.                                                    
**************************** Bottom of Data ****************************

Output -

bwz program Output

Explaining Example -

In the above example, WS-VAR is numeric variable. WS-NED-VAR is the numeric edited variable without BLANK WHEN ZERO. WS-BWZ-VAR is the numeric edited variable with BLANK WHEN ZERO.

In first iteration, ZEROES assigned to all variables and WS-BWZ-VAR zero value replaced with spaces.

in second iteration, 20000 value assigned to all variables. All variables displays 20000 including WS-BWZ-VAR. Because BLANK WHEN ZERO replaces the value with SPACES only when value is ZERO.