COBOL - Picture Clause
- A cláusula Picture é usada para especificar o tipo e o tamanho de um item de dados elementar.
- Consiste na palavra PIC ou PICTURE seguida pela cláusula de imagem real, onde o tipo e o tamanho são especificados.
- O tipo é especificado usando um caractere específico selecionado na tabela abaixo. Cada caractere de imagem representa uma posição no item de dados. Caracteres diferentes podem ser combinados dentro da mesma cláusula Picture.
- Várias ocorrências do mesmo tipo de caractere são indicadas pela repetição do caractere ou pela inclusão de um fator de repetição após o caractere.
Por exemplo, três caracteres alfabéticos podem ser representados com a cláusula PIC AAA ou PIC A(3).
Typically,
repetições de menos de quatro caracteres são feitas repetindo o caractere e repetições de quatro ou mais caracteres são feitas com o número entre parênteses.
Caracteres de representação de dados:
Character |
Purpose |
Description |
X |
Any character |
May contain any character including special or unprintable characters |
9 |
Numeric character |
May contain only the characters 0 through 9 |
A |
Alphabetic character |
May contain only the characters A - Z, a - z, and space |
Arithmetic Positioning Characters:
Character |
Purpose |
Description |
S |
Numeric sign |
Does not use any actual storage space, without this character a numeric item would be treated as unsigned |
V |
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 |
P |
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:
Character |
Purpose |
Description |
- |
Minus sign |
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 |
+ |
Plus sign |
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 |
Z |
Zero Suppress |
Replaces leading zeros with blanks; has no effect on non-zero positions or zeros not in leading positions |
, |
Comma |
Inserts a comma into the data item in this position; commonly used as a separator in numeric data items |
$ |
Dollar sign |
Inserts a dollar sign into the first position in the data item; commonly used for currency |
* |
Asterisk |
Replaces leading zeros with asterisks; has no effect on non-zero positions or zeros not in leading positions; commonly used in check writing |
CR |
Credit |
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
|
DB |
Debit |
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
|
/ |
Slash |
Inserts a slash into the data item in this position; commonly used as a separator in date fields |
0 |
Zero |
Inserts a zero into the data item in this position; not commonly used |
Lista completa de símbolos de cláusula de imagem, veja aqui