Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
COBOL
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====Data types==== Standard COBOL provides the following data types:{{sfn|ISO/IEC JTC 1/SC 22/WG 4|2014|loc=§ 8.5.2}} {| class="wikitable" |- ! Data type ! Sample declaration ! Notes |- | Alphabetic | {{code|PIC A(30)|lang=cobolfree}} | May contain only letters or spaces. |- | Alphanumeric | {{code|PIC X(30)|lang=cobolfree}} | May contain any characters. |- | Boolean | {{code|PIC 1 USAGE BIT|lang=cobolfree}} | Data stored in the form of 0s and 1s, as a binary number. |- | Index | {{code|USAGE INDEX|lang=cobolfree}} | Used to reference table elements. |- | National | {{code|PIC N(30)|lang=cobolfree}} | Similar to alphanumeric, but using an extended character set, e.g. [[UTF-8]]. |- | Numeric | {{code|PIC 9(5)V9(2)|lang=cobolfree}} | Contains exactly 7 digits (7=5+2). 'V' locates the implicit decimal in a fixed point number. |- | Object | {{code|USAGE OBJECT REFERENCE|lang=cobolfree}} | May reference either an object or <code>NULL</code>. |- | Pointer | {{code|USAGE POINTER|lang=cobolfree}} | |} Type safety is variable in COBOL. Numeric data is converted between different representations and sizes silently and alphanumeric data can be placed in any data item that can be stored as a string, including numeric and group data.{{sfn|ISO/IEC JTC 1/SC 22/WG 4|2014|loc=§ 14.9.24}} In contrast, object references and pointers may only be assigned from items of the same type and their values may be restricted to a certain type.{{sfn|ISO/IEC JTC 1/SC 22/WG 4|2014|loc=§ 14.9.35}} =====PICTURE clause===== A {{code|PICTURE}} (or {{code|PIC}}) clause is a string of characters, each of which represents a portion of the data item and what it may contain. Some picture characters specify the type of the item and how many characters or digits it occupies in memory. For example, a {{code|9}} indicates a decimal digit, and an {{code|S}} indicates that the item is [[signedness|signed]]. Other picture characters (called ''{{dfn|insertion}}'' and ''{{dfn|editing}}'' characters) specify how an item should be formatted. For example, a series of {{code|+}} characters define character positions as well as how a leading sign character is to be positioned within the final character data; the rightmost non-numeric character will contain the item's sign, while other character positions corresponding to a {{code|+}} to the left of this position will contain a space. Repeated characters can be specified more concisely by specifying a number in parentheses after a picture character; for example, {{code|9(7)}} is equivalent to {{code|9999999}}. Picture specifications containing only digit ({{code|9}}) and sign ({{code|S}}) characters define purely ''{{dfn|numeric}}'' data items, while picture specifications containing alphabetic ({{code|A}}) or alphanumeric ({{code|X}}) characters define ''{{dfn|alphanumeric}}'' data items. The presence of other formatting characters define ''{{dfn|edited numeric}}'' or ''{{dfn|edited alphanumeric}}'' data items.{{sfn|ISO/IEC JTC 1/SC 22/WG 4|2014|loc=§ 13.18.40}} {| class="wikitable" |+ Examples |- ! {{code|PICTURE}} clause ! Value in ! Value out |- | rowspan="2" | {{code|PIC 9(5)|lang=cobolfree}} | {{code|100}} | {{code|00100}} |- | {{code|"Hello"}} | {{code|"Hello"}} (this is legal, but results in [[undefined behavior]]){{sfn|ISO/IEC JTC 1/SC 22/WG 4|2014|loc=§ 14.9.24}} |- | {{code|PIC +++++|lang=cobolfree}} | {{code|-10}} | <code>" -10"</code><!-- {{code| -10}} deletes one of the spaces --> (note leading spaces) |- | {{code|PIC 99/99/9(4)|lang=cobolfree}} | {{code|30042003}} | {{code|"30/04/2003"}} |- | rowspan="2" | {{code|PIC *(4)9.99|lang=cobolfree}} | {{code|100.50}} | {{code|"**100.50"}} |- | <code>0</code> <!-- {{code|0}} produces a space for some reason --> | {{code|"****0.00"}} |- | {{code|PIC X(3)BX(3)BX(3)|lang=cobolfree}} | {{code|"ABCDEFGHI"}} | {{code|"ABC DEF GHI"}} |} =====USAGE clause===== {{missing information|section|COMPUTATIONAL-5|date=April 2021}} The {{code|USAGE}} clause declares the format in which data is stored. Depending on the data type, it can either complement or be used instead of a {{code|PICTURE}} clause. While it can be used to declare pointers and object references, it is mostly geared towards specifying numeric types. These numeric formats are:{{sfn|ISO/IEC JTC 1/SC 22/WG 4|2014|loc=§ 13.18.60.3}} * Binary, where a minimum size is either specified by the <code>PICTURE</code> clause or by a <code>USAGE</code> clause such as <code>BINARY-LONG</code> * {{code|USAGE COMPUTATIONAL|lang=cobolfree}}, where data may be stored in whatever format the implementation provides; often equivalent to {{code|USAGE BINARY|lang=cobolfree}} * {{code|USAGE DISPLAY|lang=cobolfree}}, the default format, where data is stored as a string * Floating-point, in either an implementation-dependent format or according to IEEE 754 * {{code|USAGE NATIONAL|lang=cobolfree}}, where data is stored as a string using an extended character set * {{code|USAGE PACKED-DECIMAL|lang=cobolfree}}, where data is stored in the smallest possible decimal format (typically [[packed binary-coded decimal]])
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
COBOL
(section)
Add topic