Defining numeric data

Define numeric items by using the PICTURE clause with the character 9 in the data description to represent the decimal digits of the number. Do not use an X, which is for alphanumeric data items.

About this task

For example, Count-y below is a numeric data item, an external decimal item that has USAGE DISPLAY (a zoned decimal item):


05  Count-y        Pic 9(4)  Value 25.
05  Customer-name  Pic X(20) Value "Johnson".

You can similarly define numeric data items to hold national characters (UTF-16). For example, Count-n below is an external decimal data item that has USAGE NATIONAL (a national decimal item):


05  Count-n        Pic 9(4)  Value 25  Usage National.

You can code up to 18 digits in the PICTURE clause when you compile using the default compiler option ARITH(COMPAT) (referred to as compatibility mode). When you compile using ARITH(EXTEND) (referred to as extended mode) or ARITH(FULL) (referred to as full mode), you can code up to 31 digits in the PICTURE clause.

Other characters of special significance that you can code are:

P
Indicates leading or trailing zeros
S
Indicates a sign, positive or negative
V
Implies a decimal point

The s in the following example means that the value is signed:


05  Price  Pic s99v99.

The field can therefore hold a positive or a negative value. The v indicates the position of an implied decimal point, but does not contribute to the size of the item because it does not require a storage position. An s usually does not contribute to the size of a numeric item, because by default s does not require a storage position.

However, if you plan to port your program or data to a different machine, you might want to code the sign for a zoned decimal data item as a separate position in storage. In the following case, the sign takes 1 byte:


05  Price  Pic s99V99  Sign Is Leading, Separate.

This coding ensures that the convention your machine uses for storing a nonseparate sign will not cause unexpected results on a machine that uses a different convention.

Separate signs are also preferable for zoned decimal data items that will be printed or displayed.

Separate signs are required for national decimal data items that are signed. The sign takes 2 bytes of storage, as in the following example:


05 Price Pic s99V99 Usage National Sign Is Leading, Separate.

You cannot use the PICTURE clause with internal floating-point data (COMP-1 or COMP-2). However, you can use the VALUE clause to provide an initial value for an internal floating-point literal:


05  Compute-result  Usage Comp-2  Value 06.23E-24.

For information about external floating-point data, see the examples referenced below and the related concept about formats for numeric data.

Examples: numeric data and internal representation

Related references  
Sign representation of zoned and packed-decimal data  
Storage of character data  
ARITH  
SIGN clause (COBOL for Linux® on x86 Language Reference)