Blank When Zero Clause
Blank When Zero Clause Example
Scenario - Explaining how the BLANK WHEN ZERO is 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-REAL-DV PIC 9(5).9(2).
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 ZERO.
PROCEDURE DIVISION.
MOVE ZEROES TO WS-REAL-DV
WS-NED-VAR
WS-BWZ-VAR.
DISPLAY "WS-REAL-DV: " WS-REAL-DV.
DISPLAY "WS-NED-VAR: " WS-NED-VAR.
DISPLAY "WS-BWZ-VAR: " WS-BWZ-VAR.
DISPLAY " ".
MOVE 20000 TO WS-REAL-DV
WS-NED-VAR
WS-BWZ-VAR.
DISPLAY "WS-REAL-DV: " WS-REAL-DV.
DISPLAY "WS-NED-VAR: " WS-NED-VAR.
DISPLAY "WS-BWZ-VAR: " WS-BWZ-VAR.
STOP RUN.
Output -
WS-REAL-DV: 00000.00 WS-NED-VAR: 0.00 WS-BWZ-VAR: WS-REAL-DV: 20000.00 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 displays as spaces because it has zeroes.
- Next, 20000 value assigned to all variables. All variables displays 20000 including WS-BWZ-VAR.