Picture clause - Numeric data with examples

 

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)V996 whole numbers and 2 decimal places
PIC V9993 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)V94 whole numbers and 1 decimal number, the sign is remembered
PIC S99V9992 whole numbers and 3 decimal numbers, the sign is remembered
PIC S9993 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    
0001239999V999999.990001.23
345599V99Z9.9934.55
1234569(4)V99Z,ZZ9.991,234.56
012789(3)V99ZZ9.99^12.78
00012999V99ZZ9.99^^0.12
342349(3)V99$ZZ9.99$342.34
123456789(6)V99$ZZZ,ZZZ.99$123,456.78
007654329(6)V99$ZZZ,ZZZ.99$^^7,654.32
7659(3)ZZ9765
236459(3)V99$ZZ9.99$236.45
00021319(5)V99$ZZ,ZZ9.99$^^^^21.31
87654329(5)V99$ZZ,ZZ9.99$87,654.32
76543219(5)V99$$$,$$$.99$76,543.21
00001239(5)V99$$$,$$$.99^^^^^$1.23
00012349(5)V99$$$,$$$.99^^^^$12.34
00000459(5)V99$$$,$$$.99^^^^^^$.45
1242124569(7)V99$$,$$$,$$$.99$1,242,124.56
123456789(6)V99$$$$,$$$.99$123,456.78
0002349(4)V99$*,***.99$****2.34
0653289(4)V99$*,***.99$**653.28
876543219(6)V99$***,***.99$876,543.21
00000649(5)V99$**,***.99$******.64
00000649(5)V99$**,**9.99$*****0.64
00000000009(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
DBto right of picture, prints if data is negative, otherwise two spaces
CRto 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    
-67812S999V99-ZZ9.99-678.12
45674S999V99-ZZ9.99^456.74
1234S9999Z,ZZ9-1,234^
-1234S9999Z,ZZ9-1,234-
0023S9999Z,ZZ9-^^^23^
-0023S9999Z,ZZ9-^^^23-
-24253S9(5)+ZZ,ZZ9-24,253
12345S9(5)+ZZ,ZZ9+12,345
-645642S9(4)V99+Z,ZZ9.99-6,456.42
987654S9(4)V99+Z,ZZZ.99+9,876.54
-000567S9(4)V99--,--9.99^^^^-5.67
000987S9(4)V99--,--9.99^^^^^9.87
-765793S9(4)V99--,---.99-7,657.93
-067834S9(4)V99--,---.99^^-678.34
-0023256S9(5)V99+++,+++.99^^^-232.56
0023256S9(5)V99+++,+++.99^^^+232.56
-7867S9(4)Z,ZZ9CR7,867CR
000678S9(4)V99Z,ZZ9.99CR^^^^6.78^^
-123345S9(4)V99Z,ZZ9.99DB1,233.45DB
435454S9(4)V99Z,ZZ9.99DB4,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    
1234569(3)V99ZZZ.99234.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    
123459(3)V99ZZZ.9123.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    
123499V99Z,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    
12349999Z,ZZ9.991,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    
1234999V9ZZZ.99123.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    
2345679(5)V9Z,ZZZ.993,456.70
-12349999-Z,ZZ9^1,234
-7654S9999Z,ZZ97,654
200349(4)$*,***.99$2,003.00 OR $***34.00
76543999V99ZZ,ZZ9^^^765
1002349(4)V99ZZ9.99^^2.34

No comments:

Post a Comment