Misplaced Pages

Picture clause: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Browse history interactively← Previous editNext edit →Content deleted Content addedVisualWikitext
Revision as of 03:31, 25 November 2007 editHenning Makholm (talk | contribs)Extended confirmed users, Rollbackers7,449 editsm Defaultsort Category:Programming language topics← Previous edit Revision as of 16:32, 20 February 2008 edit undoLoadmaster (talk | contribs)Extended confirmed users, Pending changes reviewers, Rollbackers13,240 edits Structure: converted to table, removed incorrect text about sign 'S'Next edit →
Line 7: Line 7:
A picture clause is made up of various characters, each of which represents a certain type of data item. The number of repeated characters indicates the size of the data item. A picture clause is made up of various characters, each of which represents a certain type of data item. The number of repeated characters indicates the size of the data item.
Here are some examples (from COBOL) of picture characters and what they represent: Here are some examples (from COBOL) of picture characters and what they represent:
*A -- an alphabetic character (A-Z or a-z, plus blank)
*B -- the blank character
*X -- any character, alphabetic, numeric, or other symbols
*9 -- a numeric digit
*Z -- a numeric digit, but leading-zero-suppressed (replaced by a blank when equal to zero)
*S -- a sign for a number
*V -- an implied period, used in storing decimal points in input and storage numbers
*, -- the comma, used as a separator in displaying numbers<ref name="comma">The comma and decimal point can be switched for European use.</ref>
*. -- the period, used as a decimal point in displaying numbers<ref name="comma"/>
*+ -- the plus sign, used in displaying signed numbers
*- -- the minus sign, used in displaying signed numbers


{| width="70%" border="2" align="center"
Some picture characters are used in input fields and data storage, some only in output fields, and some in both. For example, ''S'' is used for a signed number on input and storage fields, but output fields will display a ''+'' or ''-'' sign.
|-
! Character
! Description
|-
|align="center"| A
|Alphabetic character (A-Z, a-z, blank)
|-
|align="center"| B
|Blank (space) character
|-
|align="center"| X
|Any character, alphabetic, numeric, or other symbols
|-
|align="center"| 9
|Numeric digit (0-9)
|-
|align="center"| Z
|Numeric digit, but leading-zero-suppressed (replaced by a blank when equal to zero)
|-
|align="center"| S
|Implied sign for a number
|-
|align="center"| V
|Implied decimal point
|-
|align="center"| ,
|Digit group separator<ref name="comma">The comma and decimal point can be switched for European use.</ref>
|-
|align="center"| .
|Decimal point<ref name="comma"/>
|-
|align="center"| +
|Sign ('-' if negative, '+' if positive)
|-
|align="center"| -
|Sign ('-' if negative, blank if positive)
|}


== Examples<ref>These examples are from COBOL.</ref> == == Examples<ref>These examples are from COBOL.</ref> ==

Revision as of 16:32, 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.

Structure

A picture clause is made up of various characters, each of which represents a certain type of data item. The number of repeated characters indicates the size of the data item. Here are some examples (from COBOL) of picture characters and what they represent:

Character Description
A Alphabetic character (A-Z, a-z, blank)
B Blank (space) character
X Any character, alphabetic, numeric, or other symbols
9 Numeric digit (0-9)
Z Numeric digit, but leading-zero-suppressed (replaced by a blank when equal to zero)
S Implied sign for a number
V Implied decimal point
, Digit group separator
. Decimal point
+ Sign ('-' if negative, '+' if positive)
- Sign ('-' if negative, blank if positive)

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

  1. ^ The comma and decimal point can be switched for European use.
  2. These examples are from COBOL.
Categories: