COBOL Edited Picture Clause Examples
Edited Picture Clause in COBOL is to format the display of data in the required format. COBOL provides symbols to
format the data, these are called “Edit Symbols” and the PIC clauses that contain these symbols are called “Edited Picture clauses”.
There are basically two types of Edited picture clauses based on their type of editing.
1. Insertion Type
2. Suppression and Replacement Type
1. Insertion Type Picture Clause.
This type of edited pic simply inserts the symbol into the resultant value. There are different insertion type
picture clauses
I) Simple Insertion:
It is allowed for numeric-edited and alphanumeric-edited data types. ‘B 0 / – . , &’ are the valid symbols for this.
B==> represents a Space or it inserts a space in the output.
0==> Inserts a Zero into the data value.
/==> inserts a ‘/’ in to the data value
.==> inserts a decimal symbol(.) in to the data value
,==> inserts a comma(,) into the data value.
&==> inserts a ‘&’ in to the data value
Notes:
- Each insertion symbol is counted in the size of the item and represents the position within the item where the equivalent characters will be inserted.
- . and & are allowed for Alphanumeric-edited picture clauses only. The remaining ones are allowed for Alphanumeric edited & Numeric edited fields.
Examples:
01 NAME-DEPT PIC X(10)/XX VALUE SPACES.
MOVE ‘MAHENDER/01’ TO NAME-DEPT
DISPLAY NAME-DEPT
A)MAHENDER/0/1
01 NAME-DEPT PIC X(10)/XX VALUE ‘MAHENDER/01’.
DISPLAY NAME-DEPT
A)MAHENDER/01
II) Special Insertion
Period(.) is the special insertion symbol and is valid for Numeric edited and Floating point items only.
Example:
01 WA-NO PIC 9(2).99.
If the data present above is 12.34, Then this picture displays it as 12.34
III) Fixed Insertion:
Currency Symbols, Special Currency control symbols(CR, DB), and Sings(+, -) are the ones that come under this
category.
Notes: Valid only for Numeric edited data types.
Examples:
01 WW-VAR-1 PIC $999.99. If it has a value of 99082 then it displays it as $990.82
IV) Floating Insertion Editing
There are legal only for numeric-edited items.
Currency Symbols and Signs are used in this type.
Example:
01 WW-NUM-1 PIC $$$.99. If it has a value of 345.67, Then it displays it as $345.67
If it has a value of 1.43 then it displays it as $1.43
If the value is .19, then it displays it as $.19
Notes:
– If the value in this type of variable is Zeroes then it displays nothing but spaces.
2. Suppression and Replacement Type
In this type, zeroes would be replaced with Spaces or Asterisk. Symbols Z & * are used for this type of editing and both can not be used in a single variable.
Example:
01 WW-NUM-2 PIC ZZZ9.99.
Value resultant Value
1.23 1.23
11.23 11.23
.23 0.23
01 WW-NUM-3 PIC **9.99.
Value resultant Value
876.23 876.23
76.2 *76.20
7.98 **7.98
.67 **0.67
More Examples:
Value |
PIC |
Edited Picture |
Resultant Value |
190211 |
PIC X(06) |
PIC XX/XX/XX |
19/02/11 |
122315 |
PIC 9(06) |
PIC 9,99,999 |
1,22,315 |
001123 |
PIC 9(06) |
PIC **,**** |
1123 |
021123 |
PIC 9(06) |
PIC **,**** |
2,1123 |
23315 |
PIC 9(05) |
PIC $$$$9 |
$23315 |
For more details on this topic, refer to IBM official knowledge center @ IBM Reference
How to continue a pic clause over to the next line?
( just as a pic x value ‘literal etc ‘ can be continued
by using col7 hyphen and then ‘extended literal’. )
/Volumes/U001/EpsonPrt/20220527/COLLAGE.TXT
COLLAGE.TXT Page 1
000223*
000224 01 WW−LINE−CONTINUOUS PIC X(80)
000225 VALUE ALL ‘000100100011010001010110’.
000226 01 WW−LINE−WITH−BLANKS PIC XXXXBXXXXB
000227− XXXXBXXXXBXXXXBXXXXBXXXXBXXXXBXXXXB
000228− XXXXBXXXXBXXXXBXXXXBXXXXBXXXXBXXXXB.
000229*
000400*
000401
000402
000403
000404*
000405
000406
000407
000408
000409
000410*
MOVE WW−LINE−CONTINUOUS
TO WO−SYSF.
PERFORM X−WRITE−SYSF.
MOVE WW−LINE−CONTINUOUS
TO WW−LINE−WITH−BLANKS.
MOVE WW−LINE−WITH−BLANKS
TO WO−SYSF.
PERFORM X−WRITE−SYSF.
Program EXPERB Vers 0016 Date 20220527 Time 10092280
SOURCE−COMPUTER. Debugging Mode is OFF
00010010001101000101011000010010001101000101011000010010001101000101011000010010
0001 0010 0011 0100 0101 0110 0001 0010 0011 0100 0101 0110 0001 0010 0011 0100
Sorry about the proportional font.
Font Courier New or Deja Vu Sansmono not available.