NUMERIC DATA

Numeric data (other than data to be printed) is described in the FILE SECTION or the WORKING-STORAGE SECTION with a PIC that can contain 9, V and/or S. These symbols keep the number a pure mathematical number that can be used in calculations. When it is time to print the number, additional printing characters can be used that present the data in a readable way. But, internally the computer works most efficiently with pure numbers.
• 9 is used to indicate numeric data consisting of the digits from 0 to 9
• V tells where the assumed decimal place is located
• S will remember the sign, this is necessary if the data is negative (more about this later in the handout - for now we will just use 9 and V)
For example, you might have a field where you want to store data that contains three whole numbers and two decimal places. This field would be set up with the following picture:
PIC 999V99

The V in the PICTURE indicates that when processing the computer will assume that there is a decimal point in this position. Therefore, the number stored in the PICTURE above would be processed as three whole numbers followed by two decimal places.

Further examples:

 PIC 9(6)V99 6 whole numbers and 2 decimal places PIC V999 3 decimal places PIC 9(4)V9(4) 4 whole numbers and 4 decimal places PIC 9(5) 5 whole numbers PIC S9(5) 5 whole numbers, the sign is remembered PIC S9(4)V9 4 whole numbers and 1 decimal number, the sign is remembered PIC S99V999 2 whole numbers and 3 decimal numbers, the sign is remembered PIC S999 3 whole numbers, the sign is remembered
When it is time to print the line, the programmer edits the output with characters like the dollar sign, the comma and the actual decimal point to make the output more understandable to the people reading the report. Some of the editing characters available are shown in the chart below:
 Z suppresses leading zeros . inserts an actual decimal point in the number , inserts a comma in the number \$ inserts a \$ in the field - can be fixed or floating * inserts * instead of spaces to suppress leading zeros
• As shown in the chart, the Z suppresses leading zeros by turning them to a space. The number 0024 would print as space space 24. The Z only suppresses leading zeros, embedded zeros such as the zero in the number 2005 are not suppressed.
• The decimal point means print an actual decimal point in this space.
• The comma prints an actual comma in the space if a comma is needed - that is if there is one or more digits printing to the left of the comma.
• The single or fixed dollar sign will print in the space shown in the PIC. The floating \$ will float over next to the first printing number suppressing leading zeros and unused commas in the output picture. With floating \$ there should always be one more than the number of characters so there is a printing \$.
• The asterisk will replace leading zeros and unused commas in the output picture.
When the input or stored data is moved to the field on the printline, the data is aligned with the edited field and the result is printed. For example, suppose that on the file or stored in memory there was a number typed as 12345 and the input PIC was 999V99. This means that there is an assumed decimal point between the 3 and the 4. Now lets assume that the field on the printline where we want to print this number has PIC ZZ9.99. The assumed decimal point will line up with the actual decimal point and the number 123.45 will appear on the print line:

INPUT:           PIC 999V99         data stored as 123 assumed decimal point 45
OUTPUT:       PIC ZZ9.99           will print as 123.45

Some examples: (^ is used to designate a space in the output)

INPUT/WS DATA     INPUT/WS PIC     OUTPUT PIC     OUTPUT DATA
000123 9999V99 9999.99 0001.23
3455 99V99 Z9.99 34.55
123456 9(4)V99 Z,ZZ9.99 1,234.56
01278 9(3)V99 ZZ9.99 ^12.78
00012 999V99 ZZ9.99 ^^0.12
34234 9(3)V99 \$ZZ9.99 \$342.34
12345678 9(6)V99 \$ZZZ,ZZZ.99 \$123,456.78
00765432 9(6)V99 \$ZZZ,ZZZ.99 \$^^7,654.32
765 9(3) ZZ9 765
23645 9(3)V99 \$ZZ9.99 \$236.45
0002131 9(5)V99 \$ZZ,ZZ9.99 \$^^^^21.31
8765432 9(5)V99 \$ZZ,ZZ9.99 \$87,654.32
7654321 9(5)V99 \$\$\$,\$\$\$.99 \$76,543.21
0000123 9(5)V99 \$\$\$,\$\$\$.99 ^^^^^\$1.23
0001234 9(5)V99 \$\$\$,\$\$\$.99 ^^^^\$12.34
0000045 9(5)V99 \$\$\$,\$\$\$.99 ^^^^^^\$.45
124212456 9(7)V99 \$\$,\$\$\$,\$\$\$.99 \$1,242,124.56
12345678 9(6)V99 \$\$\$\$,\$\$\$.99 \$123,456.78
000234 9(4)V99 \$*,***.99 \$****2.34
065328 9(4)V99 \$*,***.99 \$**653.28
87654321 9(6)V99 \$***,***.99 \$876,543.21
0000064 9(5)V99 \$**,***.99 \$******.64
0000064 9(5)V99 \$**,**9.99 \$*****0.64
0000000000 9(7)V99 \$*,***,***.99 \$*********.00
The other valid symbol in the input or working storage picture is the S. The S at the front of the PICTURE will keep track of the sign and essentially remember whether the data is positive or negative. Data stored in fields without the S are stored as the absolute value of the number which means the unsigned number. An example of an input picture with an S in it:
PIC S999V99
With this picture, if the result of the calculation is a negative number or if the input was negative data, the sign will be remembered (Note: In computer code, the sign is stored with the units position). On the output picture, there are a variety of ways to indicate negative data:
 - fixed negative sign either to the left or right of the output picture, will print as space if data is not negative ---- floating negative sign to the left of the picture + fixed positive to the left or right of output picture, turns to - if the data is negative ++++ floating positive sign to left of picture, also turns to - if data negative DB to right of picture, prints if data is negative, otherwise two spaces CR to right of picture, prints if is data negative, otherwise two spaces

Examples: (I will show a negative sign in front of the data on input/ws data, but this is only for these examples. Internally, the sign is stored with the units position. On the output picture, space is represented by ^ to clarify where spaces will occur.)

INPUT/WS DATA     INPUT/WS PIC     OUTPUT PIC     OUTPUT DATA
-67812 S999V99 -ZZ9.99 -678.12
45674 S999V99 -ZZ9.99 ^456.74
1234 S9999 Z,ZZ9- 1,234^
-1234 S9999 Z,ZZ9- 1,234-
0023 S9999 Z,ZZ9- ^^^23^
-0023 S9999 Z,ZZ9- ^^^23-
-24253 S9(5) +ZZ,ZZ9 -24,253
12345 S9(5) +ZZ,ZZ9 +12,345
-645642 S9(4)V99 +Z,ZZ9.99 -6,456.42
987654 S9(4)V99 +Z,ZZZ.99 +9,876.54
-000567 S9(4)V99 --,--9.99 ^^^^-5.67
000987 S9(4)V99 --,--9.99 ^^^^^9.87
-765793 S9(4)V99 --,---.99 -7,657.93
-067834 S9(4)V99 --,---.99 ^^-678.34
-0023256 S9(5)V99 +++,+++.99 ^^^-232.56
0023256 S9(5)V99 +++,+++.99 ^^^+232.56
-7867 S9(4) Z,ZZ9CR 7,867CR
000678 S9(4)V99 Z,ZZ9.99CR ^^^^6.78^^
-123345 S9(4)V99 Z,ZZ9.99DB 1,233.45DB
435454 S9(4)V99 Z,ZZ9.99DB 4,354.54^^
Just a note: Sometimes I use ZZ9.99 and sometimes I use ZZZ.99. The difference is whether when the whole numbers are 0, I want to print a single 0 before the decimal point or not.

Problems if the data and pictures are not compatible:

If the data is not correctly defined in both the input and the output, errors occur. The following represent some of frequent types of problems:

Examples: (I will show a negative sign in front of the data on input/ws data, but this is only for these examples. Internally, the sign is stored with the units position. On the output picture, space is represented by ^ to clarify where spaces will occur.)

INPUT/WS DATA     INPUT/WS PIC     OUTPUT PIC     OUTPUT DATA
123456 9(3)V99 ZZZ.99 234.56 OR 123.45
In the example above, the input/WS data is too big for the input/WS picture. If the data was defined in WORKING STORAGE, then the left most character would be lost and the output would be 234.56. If the data was defined in the FILE SECTION, the layout determines whether the first or last character will be lost. For example, let's say the field above is called AMT-IN and the layout for the input file is the following:
01  INPUT-REC.
05  FST-FLD-IN     PIC XXXX.
05  AMT-IN         PIC 9(3)V99.
05  ANOTHER-IN     PIC XXXX.

If the data on the record is: ABC123456MMMM then FST-FLD-IN = ABC1, AMT-IN = 23456 and ANOTHER-IN = MMMM. This would result in the output 234.56.
If the data on the record is: ABCD123456MMM then FST-FLD-IN = ABCD, AMT-IN = 12345 and ANOTHER-IN = 6MMM. This would result in the output 123.45.

Other problems:

INPUT/WS DATA     INPUT/WS PIC     OUTPUT PIC     OUTPUT DATA
12345 9(3)V99 ZZZ.9 123.4

In this case, the input stores the data as 123 followed by the assumed decimal point and then 45. When the number is moved to the output picture the V lines up with the actual decimal point. Since there is only room to print one decimal place, the 5 is lost.
INPUT/WS DATA     INPUT/WS PIC     OUTPUT PIC     OUTPUT DATA
1234 99V99 Z,ZZ9 ^^^12

In this example the input stores the data as 12 assumed decimal point 34. The output picture does not have room for decimal data, so when the data is moved in the assumed decimal point lines up with the end of the field. The 1 and 2 print while the decimals 3 and 4 are lost.
INPUT/WS DATA     INPUT/WS PIC     OUTPUT PIC     OUTPUT DATA
1234 9999 Z,ZZ9.99 1,234.00
This isn't an error. The 1234 are stored as whole numbers. Since the output picture calls for decimals the .00 is added to the whole number.
INPUT/WS DATA     INPUT/WS PIC     OUTPUT PIC     OUTPUT DATA
1234 999V9 ZZZ.99 123.40
Again, this isn't an error. The data is stored with 123 as whole numbers and 4 as the only decimal number. When the input/WS data is moved to the output picture the assumed decimal point lines up with the actual decimal point. However, since there is only one decimal number and the output picture calls for two decimal numbers a 0 is put into the second decimal position.

Examples of problems:

In these examples, the output is correct given the data and the pictures. The problem is that the pictures were not set up correctly to accurately represent the data.
INPUT/WS DATA     INPUT/WS PIC     OUTPUT PIC     OUTPUT DATA
234567 9(5)V9 Z,ZZZ.99 3,456.70
-1234 9999 -Z,ZZ9 ^1,234
-7654 S9999 Z,ZZ9 7,654
20034 9(4) \$*,***.99 \$2,003.00 OR \$***34.00
76543 999V99 ZZ,ZZ9 ^^^765
100234 9(4)V99 ZZ9.99 ^^2.34