Revision as of 11:08, 13 September 2012 edit80.149.113.234 (talk) →The S symbol was marked as not displayed. This seems to be a typo, because also in your examples the S requires extra space in the output and is visible (unlike the V-picture symbol which is really not displayed)← Previous edit | Revision as of 01:02, 14 September 2012 edit undoLoadmaster (talk | contribs)Extended confirmed users, Pending changes reviewers, Rollbackers13,240 edits Undid good-faith edit 80.149.113.234; the 'S' element is implied and is not displayed; the +/- chars in the examples indicate the value, not displayed charactersNext edit → | ||
Line 13: | Line 13: | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''A''' | |bgcolor="#E0FFFF" align="center"| '''A''' | ||
|Alphabetic character (A-Z, a-z, or blank) | |Alphabetic character (<code>A-Z</code>, <code>a-z</code>, or blank) | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''B''' | |bgcolor="#E0FFFF" align="center"| '''B''' | ||
Line 19: | Line 19: | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''CR''' | |bgcolor="#E0FFFF" align="center"| '''CR''' | ||
|Sign indicator ('CR' if negative, blanks if positive) | |Sign indicator (<code>'CR'</code> if negative, blanks if positive) | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''DB''' | |bgcolor="#E0FFFF" align="center"| '''DB''' | ||
|Sign indicator ('DB' if negative, blanks if positive) | |Sign indicator (<code>'DB'</code> if negative, blanks if positive) | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''E''' | |bgcolor="#E0FFFF" align="center"| '''E''' | ||
|Floating-point exponent<ref name="extension">Non-standard extension provided by ] and others |
|Floating-point exponent<ref name="extension">Non-standard extension provided by ] and others</ref> | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''G''' | |bgcolor="#E0FFFF" align="center"| '''G''' | ||
Line 37: | Line 37: | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''S''' | |bgcolor="#E0FFFF" align="center"| '''S''' | ||
|Implied sign | |Implied sign (not displayed) | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''V''' | |bgcolor="#E0FFFF" align="center"| '''V''' | ||
Line 43: | Line 43: | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''X''' | |bgcolor="#E0FFFF" align="center"| '''X''' | ||
|Any character, alphabetic, numeric, or other |
|Any character, alphabetic, numeric, or other symbol | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''Z''' | |bgcolor="#E0FFFF" align="center"| '''Z''' | ||
Line 49: | Line 49: | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''0''' | |bgcolor="#E0FFFF" align="center"| '''0''' | ||
|Inserted '0' digit | |Inserted <code>'0'</code> digit | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''9''' | |bgcolor="#E0FFFF" align="center"| '''9''' | ||
|Numeric digit (0-9) | |Numeric digit (<code>0-9</code>) | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''/''' | |bgcolor="#E0FFFF" align="center"| '''/''' | ||
|Inserted '/' character | |Inserted <code>'/'</code> character | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| ''',''' | |bgcolor="#E0FFFF" align="center"| ''',''' | ||
|Inserted digit group separator<ref name="comma">The comma and decimal point can be switched for European use |
|Inserted digit group separator<ref name="comma">The comma and decimal point can be switched for European use</ref> | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''.''' | |bgcolor="#E0FFFF" align="center"| '''.''' | ||
Line 64: | Line 64: | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''+''' | |bgcolor="#E0FFFF" align="center"| '''+''' | ||
|Sign ('-' if negative, '+' if positive) | |Sign (<code>'-'</code> if negative, <code>'+'</code> if positive) | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''-''' | |bgcolor="#E0FFFF" align="center"| '''-''' | ||
|Sign ('-' if negative, blank if positive) | |Sign (<code>'-'</code> if negative, blank if positive) | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''$''' | |bgcolor="#E0FFFF" align="center"| '''$''' | ||
|Floating currency sign (blank for leading zeroes, '$' to the left of the most significant digit, otherwise digit 0-9) | |Floating currency sign (blank for leading zeroes, <code>'$'</code> to the left of the most significant digit, otherwise digit <code>0-9</code>) | ||
|- | |- | ||
|bgcolor="#E0FFFF" align="center"| '''*''' | |bgcolor="#E0FFFF" align="center"| '''*''' | ||
|Floating digit fill ('*' for leading zeroes, otherwise digit 0-9) | |Floating digit fill (<code>'*'</code> for leading zeroes, otherwise digit <code>0-9</code>) | ||
|} | |} | ||
Line 80: | Line 80: | ||
{| class="wikitable" border="1" | {| class="wikitable" border="1" | ||
|- bgcolor="honeydew" | |- bgcolor="honeydew" | ||
! |
! Picture clause!! Data type!! Sample values | ||
|- | |- | ||
||PIC 999 ||3-digit number || 123, 005, 087, any number from 000 through 999 | ||PIC 999 ||3-digit number || 123, 005, 087, any number from 000 through 999 | ||
|- | |- | ||
||PIC S999 ||3-digit internally signed number || +123, -005, +087, any number from -999 through +999 | ||PIC S999 ||3-digit internally signed number || +123, -005, +087, any number from -999 through +999, sign is not displayed | ||
|- | |- | ||
||PIC +999 ||3-digit output signed number || +123, -005, +087, any number from -999 through +999, with sign displayed |
||PIC +999 ||3-digit output signed number || +123, -005, +087, any number from -999 through +999, with sign displayed | ||
|- | |- | ||
||PIC ZZ9 ||3-digit number, leading zeros suppressed || 123, 5, 87, any number from 000 through 999 | ||PIC ZZ9 ||3-digit number, leading zeros suppressed || 123, 5, 87, any number from 000 through 999 |
Revision as of 01:02, 14 September 2012
A picture clause is an element in programming languages that is used to describe a datum, by using sample characters that indicate the item characteristics and size.
History
The picture clause was first used in the COMTRAN (Commercial Translator) language developed by Bob Bemer of IBM in 1957. In 1959, it was incorporated into the original definition of COBOL. Since then, many other programming languages have copied this feature.
Formatting
A picture clause is made up of various format characters, each of which represents a certain portion of the data item. Each format character can be repeated or followed by a repeat number, which specifies the number of times the format item occurs in the data item. Some examples (from COBOL) are:
Character | Description |
---|---|
A | Alphabetic character (A-Z , a-z , or blank)
|
B | Blank (space) character |
CR | Sign indicator ('CR' if negative, blanks if positive)
|
DB | Sign indicator ('DB' if negative, blanks if positive)
|
E | Floating-point exponent |
G | Double-byte (DBCS) graphic/alphanumeric character |
N | Double-byte (DBCS) character |
P | Implied scaling digit (not displayed) |
S | Implied sign (not displayed) |
V | Implied decimal point (not displayed) |
X | Any character, alphabetic, numeric, or other symbol |
Z | Numeric digit, but leading-zero-suppressed (replaced by a blank when equal to zero) |
0 | Inserted '0' digit
|
9 | Numeric digit (0-9 )
|
/ | Inserted '/' character
|
, | Inserted digit group separator |
. | Inserted decimal point |
+ | Sign ('-' if negative, '+' if positive)
|
- | Sign ('-' if negative, blank if positive)
|
$ | Floating currency sign (blank for leading zeroes, '$' to the left of the most significant digit, otherwise digit 0-9 )
|
* | Floating digit fill ('*' for leading zeroes, otherwise digit 0-9 )
|
Examples
Examples from COBOL.
Picture clause | Data type | Sample values |
---|---|---|
PIC 999 | 3-digit number | 123, 005, 087, any number from 000 through 999 |
PIC S999 | 3-digit internally signed number | +123, -005, +087, any number from -999 through +999, sign is not displayed |
PIC +999 | 3-digit output signed number | +123, -005, +087, any number from -999 through +999, with sign displayed |
PIC ZZ9 | 3-digit number, leading zeros suppressed | 123, 5, 87, any number from 000 through 999 |
PIC A(8) | 8-character alphabetic string | "Fredrick", "Fred ", "Fred Jr ", any string of 8 alphabetic letters (may include spaces) |
PIC X(8) | 8-character string | "Smithson", "O'Riley ", "Bon-Jovi", "23Skidoo", any string of 8 characters (may include any valid character) |
Footnotes
- ^ Non-standard extension provided by IBM and others
- ^ The comma and decimal point can be switched for European use
This programming-language-related article is a stub. You can help Misplaced Pages by expanding it. |