Introduction

In a business-programming environment, the ability to print reports is an important property for a programming language. COBOL allows programmers to write to the printer, either directly or through an intermediate print file.

But there would be little point in being able to write to the printer, if the output could not be formatted properly. COBOL allows sophisticated formatting of output through its Edited Picture clauses.

This tutorial introduces the additional symbols required for edited pictures and shows how they may be used to format data for output to screen or printer.


By the end of this unit you should -

  1. Know what an Edited Picture is.
  2. Know and be able to use the different kinds of Edited Picture.

What is an Edited Picture?

Most users of the data produced by COBOL programs are not content with the simple raw data. They often want it presented in a particular way. Some people like to have the thousands, in numeric values, separated by commas, others may want leading zeros suppressed while still others may require that the currency symbol "floats" up against the first non-zero digit. In COBOL these things can be achieved using Edited Pictures.

Original value
00023456.78
With commas inserted
00,023,456.78
Plus zero suppression
23,456.78
Plus floating currency symbol
$23,456.78
With anti-fraud printing
$***23,456.78

Edited Pictures, are PICTURE clauses that format data intended for output to screen or printer. To enable the data items to be formatted, COBOL provides additional picture symbols to supplement the basic 9, X, A, V and S.

The additional symbols are referred to as "Edit Symbols," and PICTURE clauses that include edit symbols are called "Edited Pictures".

The term edit is used, because the edit symbols have the effect of changing, or editing, the data inserted into the edited item.

Edited items cannot be used as operands in a computation, but they may be used as the result or destination of a computation (they can be used in items placed to the right of the word GIVING).


COBOL permits two basic types of editing picture:

  1. Insertion Editing This type of editing modifies a value by including additional items and has the following sub-categories:
    • Simple Insertion
    • Special Insertion
    • Fixed Insertion
    • Floating Insertion
  2. Suppression and Replacement Editing This type of editing suppresses and replaces leading zeros and has the following sub-categories:
    • Zero suppression and replacement with spaces
    • Zero suppression and replacement with asterisks

COBOL permits two basic types of editing picture:

Edit Symbol

Editing Type

, B 0 /

Simple Insertion

.

Special Insertion

+ - CR DB $

Fixed Insertion

+ - $

Floating Insertion

Z *

Suppression and Replacement


Insertion Editing

There are four types of Insertion Editing:-

  • Simple Insertion
  • Special Insertion
  • Fixed Insertion
  • Floating Insertion

Insertion Editing is so called because the edit symbol is inserted into the data item at the same position it occupies in the picture clause.


Simple Insertion editing consists of specifying the relevant insertion character(s) in the PICTURE string. When a value is moved into the edited item, the insertion characters are inserted into the item at the position specified in the PICTURE.

The comma, the B, the 0, and the slash (/) are the Simple Insertion editing symbols.

All Simple Insertion symbols count toward the number of characters printed or displayed. For instance, an item described as PIC 99/99/9999 will occupy 10 character positions when printed.

The comma (,) symbol

The comma symbol (,) instructs the computer to insert a comma at the character position where the symbol occurs. The comma counts towards the size of the printed item. The comma symbol cannot be the first symbol in the PICTURE string.

If all characters to the left of the comma are zeros and zero-suppression is called for, the comma is replaced by the replacement symbol (asterisk or space).

The space or blank (B) symbol

A space is inserted where the blank symbol (B) occurs.

The slash and zero symbols (/ and 0)

A slash is inserted where the slash symbol (/) occurs, and a 0 is inserted where the zero symbol (0) occurs.

In the examples/questions below, see if you can figure out what result will be produced when we move the value in the Sending item to the edited picture in the Receiving item. The description of the Sending item is shown in the Picture column and its current value is shown in the Data column.

Sending item Receiving item
Picture Data Picture Result
PIC 999999
123456
PIC 999,999
Click arrow for the answer Ans = 123,456
PIC 9(6)
000078
PIC 9(3),9(3)
Click arrow for the answer Ans = 000,078
PIC 9(6)
000078
PIC ZZZ,ZZZ
Click arrow for the answer

Ans = sssss78 s - indicates a space. The Z suppresses leading zeros, replacing them with spaces. Since there are only zeros to the left of the comma, it is replaced by a space.

PIC 9(6)
000178
PIC ***,***
Click arrow for the answer

Ans = ****178 Since only zeros are to the left of the comma it is replaced by the replacement symbol *.

PIC 9(6)
002178
PIC ***,***
Click arrow for the answer Ans = **2,178
PIC 9(6)
120183
PIC 99B99B99
Click arrow for the answer

Ans = 12s01s83 s - indicates a space

PIC 9(6)
120183
PIC 99/99/99
Click arrow for the answer

Ans = 12/01/83 As in this case, the slash is often used to edit dates.

PIC 9(6)
031245
PIC 990099
Click arrow for the answer

Ans = 120045 Decimal point alignment means that 45 will be placed in the rightmost two digits, then the zeros will be inserted and then the 12 will be placed in the last two positions. The 3 will be truncated.


The decimal point is the only Special Insertion symbol. A decimal point is inserted in the character position where the symbol occurs.

Notes

When a numeric data-item is moved into an edited data-item containing the decimal point symbol, alignment occurs along the position of the decimal point symbol, with zero-filling and truncation as necessary.

There may be only one decimal point in each edited picture clause.

The decimal point symbol cannot be mixed with either the V (assumed decimal point) or the P (scaling position) symbol.

In the examples/questions below, see if you can figure out what result will be produced when the value in the Sending item is moved to the edited picture in the Receiving item. The description of the Sending item is shown in the Picture column and its current value is shown in the Data column.

Sending item Receiving item
Picture Data Picture Result
PIC 999V99
12345
PIC 999.99
Click arrow for the answer

Ans = 123.45 The assumed decimal point (V) aligns with the actual decimal point (.) so 45 goes after the decimal point and 123 before it.

PIC 999V99
02345
PIC 999.9
Click arrow for the answer

Ans = 023.4 The receiving field only allows one digit after the decimal point so after decimal point alignment the 5 will be lost.

PIC 999V99
71234
PIC 99.99
Click arrow for the answer

Ans = 12.34 In this case decimal point alignment causes most significant digit (7) to be lost.

PIC 9(4)
2456
PIC 999.99
Click arrow for the answer

Ans = 456.00 Decimal point alignment means that, the most significant digit (2) will be lost, and the positions after the decimal point will be filled with zeros


Fixed Insertion editing inserts the symbol at the beginning or end of the edited item.

The Fixed Insertion editing symbols are:

  • the plus (+) and minus (-) signs,
  • the letters CR and DB representing credit and debit,
  • and the currency symbol usually the $ sign.

All symbols count toward the size of the printed item.

Plus and minus symbols

These must appear in the leftmost or rightmost character positions and they count towards the size of the data item. They must be the first or last character in the PICTURE string.

Minus

If the sending item is negative, a minus sign is printed. If the sending item is positive, a space is printed instead. Use this to highlight negative values only.

Plus

If the sending item is negative, a minus in printed and if the sending item is positive, a plus is inserted. Use this to when you always want the sign printed.

CR and DB

CR and DB count towards the data item size and occupy two character positions. They may only appear in the rightmost position. Both are only printed if the sending item is negative. Otherwise two spaces are printed.

The currency symbol (usually $).

The currency symbol must be the leftmost character and it counts towards the size of the item. It may be preceded by a plus or a minus sign.

Like the previous examples/questions above, see if you can figure out what result will be produced when the value in the Sending item is moved to the edited picture in the Receiving item.

Sending item Receiving item
Picture Data Picture Result
PIC S999
-123
PIC -999
Click arrow for the answer Ans = -123
PIC S999
-123
PIC 999-
Click arrow for the answer Ans = 123-
PIC S999
+123
PIC -999
Click arrow for the answer

Ans = s123 s - indicates a space The - symbol only highlights negative values. If the value is positive, a space is printed instead of the sign.

PIC S9(5)
+12345
PIC +9(5)
Click arrow for the answer Ans = +12345
PIC S9(3)
-123
PIC +9(3)
Click arrow for the answer

Ans = -123 If a + symbol is used, a + is printed if the value is positive and a - is printed if the value is negative.

PIC S9(3)
-123
PIC 999+
Click arrow for the answer

Ans = 123- In this case decimal point alignment causes most significant digit (7) to be lost.

PIC S9(4)
+1234
PIC 9(4)CR
Click arrow for the answer

Ans = 1234ss s- indicates a space

PIC S9(4)
-1234
PIC 9(4)CR
Click arrow for the answer Ans = 1234CR
PIC S9(4)
+1234
PIC 9(4)DB
Click arrow for the answer

Ans = 1223ss s - indicates a space

PIC S9(4)
-1234
PIC 9(4)DB
Click arrow for the answer Ans = 1234DB
PIC 9(4)
1234
PIC $99999
Click arrow for the answer Ans = $01234
PIC 9(4)
0000
PIC $ZZZZZ
Click arrow for the answer

Ans = $sssss s - indicates a space


The problem with using the fixed insertion symbols is that they can be somewhat unsightly. Values like $0045,345.56 or -0012 are more acceptablely presented as $45,345.56 and -12.

What makes these formats more presentable is that the leading zeros have been suppressed and the editing symbol has been "floated" up against the first non-zero digit. In COBOL this is achieved using Floating Insertion.

Floating Insertion suppresses leading zeros, and "floats" the insertion symbol up against the first non-zero digit.

The Floating Insertion symbols are;

  • The plus and minus signs
  • and the currency symbol.

Every floating symbol counts toward the size of the printed item.

Except for the left-most one, which is always printed, each Floating Insertion symbol is a placeholder that may be replaced by a digit. Accordingly, there will always be at least one symbol printed, even though this may be at the cost of truncating the number (see the fourth row in the example below.)

Like the previous examples/questions above, see if you can figure out what result will be produced when the value in the Sending item is moved to the edited picture in the Receiving item.

Sending item Receiving item
Picture Data Picture Result
PIC 9(4)
0000
PIC $$,$$9.99
Click arrow for the answer

Ans = ssss$0.00 s - indicates a space

PIC 9(4)
0080
PIC $$,$$9.00
Click arrow for the answer

Ans = sss$80.00 s - indicates a space The fixed insertion zeros are added to the end.

PIC 9(4)
0128
PIC $$,$$9.99
Click arrow for the answer

Ans = ss$128.00 s - indicates a space

PIC 9(5)
57397
PIC $$,$$9
Click arrow for the answer

Ans = $7,397 Although the receiving field appears to have enough room for the value, the programmer forgot that the left-most floating symbol cannot be replaced by a digit. This causes the digit (5) to be lost.

PIC S9(4)
-0005
PIC ++++9
Click arrow for the answer

Ans = sss-5 s - indicates a space

PIC S9(4)
+0080
PIC ++++9
Click arrow for the answer

Ans = sss+80 s - indicates a space

PIC S9(4)

-0080
PIC - - - - 9
Click arrow for the answer

Ans = sss-80 s- indicates a space

PIC S9(5)
+71234
PIC - - - - 9
Click arrow for the answer

Ans = s1234 s- indicates a space The left-most sign cannot be replaced by a digit, so the most significant digit (7) is truncated.


Suppression and Replacement Editing

Suppression and replacement editing is used to remove leading zeroes from the value to be edited. There are two varieties of suppression and replacement editing-

  • Suppression of leading zeros and replacement with spaces
  • Suppression of leading zeros and replacement with asterisks

Notes

The characters Z and * are the suppression symbols.

Using Z in an editing picture, instructs the computer to suppress a leading zero in that character position and replace it with a space.

Using an * in an editing picture, instructs the computer to suppress a leading zero in that character position and replace it with an *.

If all the character positions in a data item are Z editing symbols and the sending item is 0 then only spaces will be printed.

If a Z or * is used, the picture clause symbol 9, cannot appear to the left of it.

Sending item Receiving item
Picture Data Picture Result
PIC 9(5)
12345
PIC ZZ,999
Click arrow for the answer Ans = 12,345
PIC 9(5)
01234
PIC ZZ,999
Click arrow for the answer

Ans = s1,234 s - indicates a space

PIC 9(5)
00123
PIC ZZ,999
Click arrow for the answer

Ans = sss123 s - indicates a space Because there are only zeros to the left of the comma, it is replaced by the replacement symbol space.

PIC 9(5)
00012
PIC ZZ,999
Click arrow for the answer

Ans = sss012 s - indicates a space

PIC 9(5)
05678
PIC **,**9
Click arrow for the answer Ans = *5,678
PIC 9(5)
00567
PIC **,**9
Click arrow for the answer Ans = ***567
PIC 9(5)
00000
PIC **,***
Click arrow for the answer

Ans = ****** s- indicates a space

PIC 9(5)V99

00043.45
PIC $**,**9.99
Click arrow for the answer

Ans = $****43.45 Helps to prevent fraud when printing cheques.


Some combinations of picture symbols are not permitted. The table below shows the combination of symbols that is allowed.

Character May be followed by
P
B
0
/
,
.
+
-
CR or DB
$
9
V
P B 0 / , + - CR DB 9 V
P B 0 / , . + - CR DB 9 V
P B 0 / , . + - CR DB 9 V
P B 0 / , . + - CR DB 9 V
P B 0 / , . + - CR DB 9 V
B 0 / , . + - CR DB 9
P B 0 / , . + $ 9 V
P B 0 / , . - $ 9 V
Nothing at all
P B 0 / , . + - CR DB $ 9 V
P B 0 / , . + - CR DB 9 V
B 0 / , + - CR DB 9