COBOL Edited Picture Clause Examples

Edited Picture Clause in COBOL is to format the the display of data in required format. COBOL provides symbols to
format the data, these are called “Edit Symbols” and the PIC clauses that contains these symbols are called as “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.

These type of edited pic, simply inserts the symbol in to 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==> represent a Space or it inserts a space in the output.
0==> Inserts a Zero in to 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 pictures clauses only. 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 in 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 comes 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

 

For more details on the this topic, refer IBM official knowledge center @ IBM Reference

Leave a Reply

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