Revision as of 16:46, 20 February 2008 editLoadmaster (talk | contribs)Extended confirmed users, Pending changes reviewers, Rollbackers13,240 editsm moved Picture Clause to Picture clause: Proper title capitalization← Previous edit | Revision as of 16:57, 20 February 2008 edit undoLoadmaster (talk | contribs)Extended confirmed users, Pending changes reviewers, Rollbackers13,240 edits →Formatting: reword, add colors to tableNext edit → | ||
Line 5: | Line 5: | ||
== Formatting == | == Formatting == | ||
A picture clause is made up of various characters, each of which represents a certain |
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: | ||
Here are some examples (from COBOL) of picture characters and what they represent: | |||
{| width="80%" border="2" align="center" | {| width="80%" border="2" align="center" | ||
|- bgcolor="#F0F0F0" | |||
|- | |||
! Character | ! Character | ||
! Description | ! Description | ||
|- | |- | ||
|align="center"| '''A''' | |bgcolor="#E0FFFF" align="center"| '''A''' | ||
|Alphabetic character (A-Z, a-z, or blank) | |Alphabetic character (A-Z, a-z, or blank) | ||
|- | |- | ||
|align="center"| '''B''' | |bgcolor="#E0FFFF" align="center"| '''B''' | ||
|Blank (space) character | |Blank (space) character | ||
|- | |- | ||
|align="center"| '''CR''' | |bgcolor="#E0FFFF" align="center"| '''CR''' | ||
|Sign indicator ('CR' if negative, blanks if positive) | |Sign indicator ('CR' if negative, blanks if positive) | ||
|- | |- | ||
|align="center"| '''DB''' | |bgcolor="#E0FFFF" align="center"| '''DB''' | ||
|Sign indicator ('DB' if negative, blanks if positive) | |Sign indicator ('DB' if negative, blanks if positive) | ||
|- | |- | ||
|align="center"| '''E''' | |bgcolor="#E0FFFF" align="center"| '''E''' | ||
|Floating-point exponent<ref name="extension">Non-standard extension provided by ] and others.</ref> | |Floating-point exponent<ref name="extension">Non-standard extension provided by ] and others.</ref> | ||
|- | |- | ||
|align="center"| '''G''' | |bgcolor="#E0FFFF" align="center"| '''G''' | ||
|Double-wide graphic/alphanumeric character<ref name="extension"/> | |Double-wide graphic/alphanumeric character<ref name="extension"/> | ||
|- | |- | ||
|align="center"| '''P''' | |bgcolor="#E0FFFF" align="center"| '''P''' | ||
|Implied scaling digit (not displayed) | |Implied scaling digit (not displayed) | ||
|- | |- | ||
|align="center"| '''S''' | |bgcolor="#E0FFFF" align="center"| '''S''' | ||
|Implied sign (not displayed) | |Implied sign (not displayed) | ||
|- | |- | ||
|align="center"| '''V''' | |bgcolor="#E0FFFF" align="center"| '''V''' | ||
|Implied decimal point (not displayed) | |Implied decimal point (not displayed) | ||
|- | |- | ||
|align="center"| '''X''' | |bgcolor="#E0FFFF" align="center"| '''X''' | ||
|Any character, alphabetic, numeric, or other symbols | |Any character, alphabetic, numeric, or other symbols | ||
|- | |- | ||
|align="center"| '''Z''' | |bgcolor="#E0FFFF" align="center"| '''Z''' | ||
|Numeric digit, but leading-zero-suppressed (replaced by a blank when equal to zero) | |Numeric digit, but leading-zero-suppressed (replaced by a blank when equal to zero) | ||
|- | |- | ||
|align="center"| '''9''' | |bgcolor="#E0FFFF" align="center"| '''9''' | ||
|Numeric digit (0-9) | |Numeric digit (0-9) | ||
|- | |- | ||
|align="center"| ''',''' | |bgcolor="#E0FFFF" align="center"| ''',''' | ||
|Digit group separator<ref name="comma">The comma and decimal point can be switched for European use.</ref> | |Digit group separator<ref name="comma">The comma and decimal point can be switched for European use.</ref> | ||
|- | |- | ||
|align="center"| '''.''' | |bgcolor="#E0FFFF" align="center"| '''.''' | ||
|Decimal point<ref name="comma"/> | |Decimal point<ref name="comma"/> | ||
|- | |- | ||
|align="center"| '''+''' | |bgcolor="#E0FFFF" align="center"| '''+''' | ||
|Sign ('-' if negative, '+' if positive) | |Sign ('-' if negative, '+' if positive) | ||
|- | |- | ||
|align="center"| '''-''' | |bgcolor="#E0FFFF" align="center"| '''-''' | ||
|Sign ('-' if negative, blank if positive) | |Sign ('-' if negative, blank if positive) | ||
|- | |- | ||
|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, '$' to the left of the most significant digit, otherwise digit 0-9) | ||
|- | |- | ||
|align="center"| '''*''' | |bgcolor="#E0FFFF" align="center"| '''*''' | ||
|Floating digit fill ('*' for leading zeroes, otherwise digit 0-9) | |Floating digit fill ('*' for leading zeroes, otherwise digit 0-9) | ||
|} | |} |
Revision as of 16:57, 20 February 2008
A picture clause is an element in programming languages that is used to describe a data item, 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-wide graphic/alphanumeric 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 symbols |
Z | Numeric digit, but leading-zero-suppressed (replaced by a blank when equal to zero) |
9 | Numeric digit (0-9) |
, | Digit group separator |
. | 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
picture clause | data type | sample contents |
---|---|---|
PICTURE IS 999 | 3-digit number | 123, 005, 087, any number from 000 through 999 |
PICTURE IS S999 | 3-digit internally signed number | +123, -005, +087, any number from -999 through +999 |
PICTURE IS +999 | 3-digit output signed number | +123, -005, +087, any number from -999 through +999, with sign displayed. |
PICTURE IS ZZ9 | 3-digit number, leading zeros suppressed | 123, 5, 87, any number from 000 through 999 |
PICTURE IS A(8) | 8-character alphabetic string | "Fredrick", "Fred ", any string of 8 alphabetic letters (may include spaces) |
PICTURE IS X(8) | 8-character string | "Smithson", "O'Riley ", "Bon-Jovi", "23Skidoo", any string of 8 characters (may include spaces) |
Footnotes
- ^ Non-standard extension provided by IBM and others.
- ^ The comma and decimal point can be switched for European use.
- These examples are from COBOL.
This computer science article is a stub. You can help Misplaced Pages by expanding it. |