COBOL - Picture Clause
- The Picture clause is used to specify the type and size of an elementary data item.
- It consists of the word PIC or PICTURE followed by the actual picture clause, where the type and size are specified.
- The type is specified using a specific character selected from the table below. Each picture character represents one position in the data item. Different characters may be combined within the same Picture clause.
- Multiple occurrences of the same type of character are indicated by repeating the character or including a repetition factor after the character.
For example, three alphabetic characters may be represented either with the clause PIC AAA or PIC A(3).
repetitions of less han four characters are done by repeating the character and repetitions of four or more characters are done with the number enclosed in parentheses.
Data Representation Characters:
||May contain any character including special or unprintable characters
||May contain only the characters 0 through 9
||May contain only the characters A - Z, a - z, and space
Arithmetic Positioning Characters:
||Does not use any actual storage space, without this character a numeric item would be treated as unsigned
||Implied decimal point
||Does not use any actual storage space, separates the integer portion of a numeric item from its decimal portion; used to keep track of the decimal point for arithmetic calculations; this character will not print or display; use the actual decimal point character, ".", f r printing
||Numeric place holder
||Does not use any actual storage space; used to change precision, e.g. 99PPP will hold values in amounts of even 1,000 from zero to 99,000 without actually storing anything for the three lowest order positions; can also be used to represent positions after the decimal, e.g. PP9 will hold values in amounts in even thousandths, from 0 to .009 without actually storing anything for the two highest order positions
Numeric Editing Characters:
||Used to display a sign in a printed item, the "-" character will be showed only if the numeric value is negative, the position will be left blank for positive values
||Used to display a sign in a printed item, "-" will be shown for negative values, "+" will be shown for positive values
||Actual decimal point
||Separates the integer portion of a numeric item from its decimal portion; this character cannot be used in an item involved in a calculation; use the implied decimal point character, "V", for calculations
||Replaces leading zeros with blanks; has no effect on non-zero positions or zeros not in leading positions
||Inserts a comma into the data item in this position; commonly used as a separator in numeric data items
||Inserts a dollar sign into the first position in the data item; commonly used for currency
||Replaces leading zeros with asterisks; has no effect on non-zero positions or zeros not in leading positions; commonly used in check writing
||Used at the end of a PICTURE clause, the CR will appear in the position indicated if the item is negative; will b blank for a positive number
||Used at the end of a PICTURE clause, the DB will appear in the position indicated if the item is negative; will b blank for a positive number
||Inserts a slash into the data item in this position; commonly used as a separator in date fields
||Inserts a zero into the data item in this position; not commonly used
Complete list of picture clause symbols, see here
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!