PICTURE clause specifies the characteristics of the variable while declaring it, e.g., variable type, length, etc.
Syntax -
level-number variable-name
[PIC|PICTURE picture-symbol(variable-length)
[VALUE literal]].
Note! All statements coded in [ ] are optional.
For example - Declaring a variable of alphabetic type to store a value HELLO.
01 WS-VAR PIC A(05) VALUE "HELLO".
- level-number - Specifies the level number of the declaration from 01 to 49. From the example, it is 01.
- variable-name - Specifies the name of the variable. From the example, it is WS-VAR.
- PIC - PIC is a short form for PICTURE
- picture-symbol (data-type-character) - Specifies the variable type. From the example, it is A (Alphabetic).
- variable-length - Specifies the variable length to store the data. From the example, it is 05 (variable length is 5).
- literal - Specifies the literal character string. From the example, it is HELLO.
Notes -
- PICTURE clause should code with every elementary and individual variable to specify its type and length.
- PICTURE clause not applicable to the below -
- Index variables
- RENAMES clause
- Internal floating-point variables
- 88-level number
- COMP-1 and COMP-2 variables
PICTURE Symbol (Data type Character) -
- PICTURE symbol is the letter used to specify the type of the variable during its declaration.
- PICTURE symbols are two types -
- PICTURE symbol for data types
- PICTURE symbol for editing.
PICTURE symbol for data types -
This type specifies the PICTURE symbols assigned for each data type in COBOL. Those are -
Data Type |
PICTURE Symbol |
Declaration Meaning |
Alphabetic |
A |
Alphabetic character or space.
Represents alphabetic data type.
For example -
Input |
PICTURE Clause |
Output |
HELLO |
PIC A(5) |
HELLO |
|
Numeric |
9 |
Numeric character.
Represents numeric data type.
For example -
Input |
PICTURE Clause |
Output |
123 |
PIC 9(5) |
00123 |
000123 |
PIC 9(4) |
0123 |
|
Alphanumeric |
X |
Alphanumeric character or space.
Represents alphanumeric data type.
For example -
Input |
PICTURE Clause |
Output |
HELLO |
PIC X(5) |
HELLO |
HI |
PIC X(5) |
HI |
|
Assumed decimal point |
V |
Represents the decimal point.
It is not counted in the size of the variable/variable.
For example -
Input |
PICTURE Clause |
Output |
123.45 |
PIC 999V99 |
12345 |
123.45 |
PIC 99V99 |
2345 |
|
Operational sign |
S |
Represents the Sign of the value.
It is not counted in the size of the variable unless a SIGN clause with the SEPARATE CHARACTER phrase is specified.
For example -
Input |
PICTURE Clause |
Output |
-123 |
PIC S999 |
12L |
+123 |
PIC S999 |
12C |
-123 |
PIC S999 SIGN IS LEADING SEPERATE CHARACTER |
-123 |
-123 |
PIC S999 SIGN IS TRAILING SEPERATE CHARACTER |
123- |
|
PICTURE symbol for editing -
PICTURE symbol for editing is used to display the data in the user's desired format.
These are classified into two types, and those are -
Insertion editing - It is a way to format the data in the numeric variables, for displaying in human-readable format.
Type |
Description |
PIC Symbols |
Simple insertion |
Simple insertion editing involves inserting character(s) like blank, 0, /, and space in the PICTURE string while displaying for better readability. |
B
0
/
(Space) |
Special insertion |
Special insertion editing is used to insert the decimal-point while displaying the decimal values of a variable. |
. (Dot) |
Fixed insertion |
Fixed insertion editing is used to insert fixed characters (-, +, CR, DB, and $) into a numeric edited item. |
cs
+
-
CR
DB |
Floating insertion |
Floating insertion editing is used for formatting numeric variables, mainly when dealing with currency values. |
cs
+
- |
ZERO suppression and replacement editing
Type |
Description |
PIC Symbols |
Zero suppression and replacing with spaces |
Zero Suppression involves omitting leading zeros from a number, and replacement editing involves replacing leading zeros with a space. |
Z
* |
Zero suppression and replacing with asterisks |
Zero Suppression involves omitting leading zeros from a number, and replacement editing involves replacing leading zeros with an asterisk (*). |
Z
*
+
-
cs |
Examples -
Below are the total PICTURE clause symbol list -
Symbol |
Declaration Meaning |
B |
Space insertion character that represents numeric-edited and alphanumeric-edited character. For example -
Input |
PICTURE Clause |
Output |
150682 |
PIC 99B99B99 |
15 06 82 |
15061982 |
PIC XXBXXBXXXX |
15 06 1982 |
|
P | Decimal scaling position but not counted in size of variable. For example -
Input |
PICTURE Clause |
Output |
77 |
PIC 99P |
77 |
77 |
PIC P99 |
77 |
|
Z | Zero suppression character. For example -
Input |
PICTURE Clause |
Output |
123 |
PIC ZZZZZ. |
123 |
000123 |
PIC ZZZZZZ. |
123 |
|
0 | Zero insertion character. For example -
Input |
PICTURE Clause |
Output |
1234 |
PIC 990099. |
120034 |
1234 |
PIC 999900. |
123400 |
|
/ | Slash insertion character. For example -
Input |
PICTURE Clause |
Output |
150682 |
PIC 99/99/99. |
15/06/82 |
|
, | Comma insertion character. For example -
Input |
PICTURE Clause |
Output |
123456 |
PIC 999,999. |
123,456 |
12345 |
PIC zzz,999. |
12345 |
|
. | Decimal point or period editing control character. For example -
Input |
PICTURE Clause |
Output |
1234.56 |
PIC 9999.99. |
1234.56 |
1234.56 |
PIC 999.99. |
234.56 |
1234.56 |
PIC 9999.9. |
1234.5 |
|
+ | Plus sign insertion editing control character. For example -
Input |
PICTURE Clause |
Output |
+12345 |
PIC +9(5). |
+12345 |
-123 |
PIC +9(3). |
-123 |
-123 |
PIC 9(3)+. |
123- |
|
- | Minus sign editing control character. For example -
Input |
PICTURE Clause |
Output |
-123 |
PIC -9(3). |
-123 |
+123 |
PIC +9(3). |
123 |
-123 |
PIC 9(3)-. |
123- |
|
CR | Credit editing control character. For example -
Input |
PICTURE Clause |
Output |
+123 |
PIC 9(3)CR. |
123 |
-123 |
PIC 9(3)CR. |
123CR |
|
DB | Debit editing control character or Check protect insertion character.For example -
Input |
PICTURE Clause |
Output |
+123 |
PIC 9(3)DB. |
123 |
-123 |
PIC 9(3)DB. |
123DB |
|
$ | Currency symbol insertion character. $ is the default. For example -
Input |
PICTURE Clause |
Output |
000 |
PIC $,$$9.99. |
0.00 |
90 |
PIC $$9.00. |
$90.00 |
12345 |
PIC $$,$$9. |
$2,345 |
|
- Insertion Editing
- ZERO suppression and replacement Editing