Monday 28 July 2014

COBOL BLANK WHEN ZERO Clause | BLANK WHEN ZERO Example.

COBOL BLANK WHEN ZERO
BLANK WHEN ZERO In COBOL



While working on various COBOL reporting project's, I have come across with situation where requirement is to display SPACE despite of printing ZERO. Well! COBOL has a solution for that as well. 

You can use BLANK WHEN ZERO Clause. The Blank When Zero clause turns a numeric field to spaces when its value is zero. 

In this COBOL tutorial, I will discuss explain about BLANK WHEN ZERO COBOL Clause which is used to display COBOL numeric data in specific format (for example Suppressing leading zeros in COBOL).

The BLANK WHEN ZERO clause specifies that an item contains nothing but spaces when its value is zero. It can be specified only for elementary numeric or numeric-edit ed items. 

These items must be described, either implicitly or explicitly, as USAGE IS DISPLAY. When the BLANK WHEN ZERO clause in COBOL is specified for a numeric item, the item is considered a numeric-edited item (i.e. COBOL numeric-edited items are classified as alphanumeric data items and they cannot be used for any arithmetic expression) 


When you code the Blank When Zero clause, a numeric field that contains a value of zero is changed to spaces. If, for example, a field is defined with a Picture of ZZZ.99, it will look like .00 if a value of zero is moved to it. If you use the BLANK WHEN ZERO Clause with it, though, the field will be converted to spaces. 


Syntax : 


[VALUE IS literal]
[BLANK WHEN ZERO ]

Examples of Picture, Value, and Blank When Zero clauses.

05 HD1-EDIT-DTE             PIC 99/99/99. 
05 DTL-YTD-SALES-TOT        PIC S9(7)V99       VALUE ZERO. 
05 TRL-YTD-SALES-TOT-NBR    PIC Z,ZZZ,ZZZ.99CR BLANK WHEN ZERO.

Couple of Important Points that should be keep in mind while using COBOL BLANK WHEN ZERO CLAUSE.

  • The BLANK WHEN ZERO clause must not be specified for level-66 or level-88 items. You cannot use numeric-edited items as sending operands in arithmetic expressions or in ADD, SUBTRACT, MULTIPLY, DIVIDE, or COMPUTE statements.


  • The BLANK WHEN ZERO clause must not be specified for an entry containing the PICTURE symbols S or *

mainframe jobs

Preparing for Mainframe job interview? Have a look to our top 100 mainframe interview questions? 


Created with Artisteer

No comments:

Post a Comment

New In-feed ads