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

2 Comments

Leave a Reply to Kevin O'Brien Cancel reply

Your email address will not be published. Required fields are marked *

Close Bitnami banner