Displaying numeric data
You can define numeric items with certain editing symbols (such as decimal points, commas, dollar signs, and debit or credit signs) to make the items easier to read and understand when you display or print them.
About this task
For example, in the following code,
Edited-price
is a numeric-edited item that has USAGE
DISPLAY
. (You can specify the clause USAGE IS DISPLAY
for
numeric-edited items; however, it is implied. It means that the items are stored in character
format.)
05 Price Pic 9(5)v99.
05 Edited-price Pic $zz,zz9.99.
. . .
Move Price To Edited-price
Display Edited-price
If the contents of Price
are
0150099 (representing the value 1,500.99), $ 1,500.99
is
displayed when you run the code. The z
in the PICTURE
clause
of Edited-price
indicates the suppression of leading
zeros.
You can define numeric-edited data items to hold national (UTF-16) characters instead
of alphanumeric characters. To do so, define the numeric-edited items as
USAGE NATIONAL
. The effect of the editing symbols is the same for numeric-edited
items that have USAGE NATIONAL
as it is for numeric-edited items that have
USAGE DISPLAY
, except that the editing is done with national characters. For
example, if Edited-price
is declared as USAGE NATIONAL
in the
previous code, the item is edited and displayed using national characters.
You can cause an elementary numeric or numeric-edited item to be filled with spaces
when a value of zero is stored into it by coding the BLANK WHEN ZERO
clause for the
item. For example, each of the DISPLAY
statements causes blanks to be displayed
instead of zeros:
05 Price Pic 9(5)v99.
05 Edited-price-D Pic $99,999.99
Blank When Zero.
05 Edited-price-N Pic $99,999.99 Usage National
Blank When Zero.
. . .
Move 0 to Price
Move Price to Edited-price-D
Move Price to Edited-price-N
Display Edited-price-D
Display Edited-price-N
You cannot use numeric-edited items as sending
operands in arithmetic expressions or in ADD
, SUBTRACT
, MULTIPLY
, DIVIDE
,
or COMPUTE
statements. (Numeric editing
takes place when a numeric-edited item is the receiving field for
one of these statements, or when a MOVE
statement
has a numeric-edited receiving field and a numeric-edited or numeric
sending field.) You use numeric-edited items primarily for displaying
or printing numeric data.
You can move numeric-edited items
to numeric or numeric-edited items. In the following example, the
value of the numeric-edited item (whether it has USAGE
DISPLAY
or USAGE NATIONAL
) is moved
to the numeric item:
Move Edited-price to Price
Display Price
If these two statements immediately followed the statements in the first example, then
Price
would be displayed as 0150099, representing the value 1,500.99. Price
would also be displayed as 0150099 if
Edited-price
had USAGE NATIONAL
.
You can also move numeric-edited
items to alphanumeric, alphanumeric-edited, floating-point, and national
data items. For a complete list of the valid receiving items for numeric-edited
data, see the related reference about the MOVE
statement.
Examples: numeric data and internal representation
Displaying values on a screen or in a file (DISPLAY)
Controlling how numeric data is stored
Defining numeric data
Performing arithmetic
Defining national numeric data items
Converting to or from national (Unicode) representation
MOVE statement (COBOL for Linux® on x86 Language Reference)
BLANK WHEN ZERO clause (COBOL for Linux on x86 Language Reference)