Data Description
A data description describes a data item.
General Format:
level-number [ data-name ]
[ FILLER ]
[ REDEFINES identifier-1 ]
[ IS EXTERNAL ]
[ IS GLOBAL ]
[ IS TYPEDEF ]
[ {PICTURE} IS picture-string ]
{PIC }
[ [ USAGE IS ] usage-type ]
[ [ SIGN IS ] {LEADING } [ SEPARATE CHARACTER ] ]
{TRAILING}
[ OCCURS { integer TIMES }
{ int-1 TO int-2 TIMES DEPENDING ON reference }
[ {ASCENDING } KEY IS {key-name} ... ] ...
{DESCENDING}
[ INDEXED BY {occurs-index} ... ] ]
[ {SYNCHRONIZED} [{LEFT } ] ]
{SYNC} [{RIGHT}]
[ {JUSTIFIED} RIGHT ]
{JUST}
[ BLANK WHEN ZERO ]
[ BASED ]
[ ANY LENGTH ]
[ RENAMES qualified-word [ {THRU } qualified-word ]
{THROUGH}
[ { VALUE IS } {value-lit } ]
{ VALUES ARE } { literal-1 [ {THRU } literal-2 ] } ...
{THROUGH}
[ WHEN SET TO FALSE literal-3 ]
Syntax:
For syntax rules associated with a clause, see the clause description below.
Any Length Clause
General Format:
[ ANY LENGTH ]
General Rules:
- Data items described as
ANY LENGTH
are not assigned a length at compile time. - Data items described as
ANY LENGTH
must be described as 01-level data items in theLinkage
Section , and theirPICTURE
clause must have a single A, X, or 9 symbol.
Example:
LINKAGE SECTION.
01 param-1 PIC X ANY LENGTH.
Based Clause
General Format:
[ BASED ]
General Rules:
- Data items described as
BASED
are not assigned storage at compile time. - The
ALLOCATE
statement is used to allocate storage, and initialize data items described asBASED
. For more information, see the ALLOCATE Statement section. - The
FREE
statement is used to free storage assigned to data items described asBASED
. For more information see the FREE Statement section.
Blank When Zero Clause
General Format:
[ BLANK WHEN ZERO ]
General Rules:
- The
BLANK WHEN ZERO
clause may only be applied to data items that areNUMERIC
orNUMERIC EDITED
. - The effect of the
BLANK WHEN ZERO
clause is to store spaces in the data item when the value of the data item is zero. - Data items with a
PICTURE
category that isNUMERIC
which contain theBLANK WHEN ZERO
clause are considered to beNUMERIC EDITED
.
EXTERNAL Clause
General Format:
[ IS EXTERNAL ]
General Rules:
- When a file is declared as
EXTERNAL
, if the file name is indicated as a variable name, in anASSIGN DYNAMIC [file-var]
clause, thenfile-var
should be declared asEXTERNAL
. - Variables declared as
EXTERNAL
must be declared as level 01 or level 77. - If
[file-var]
is not declared asEXTERNAL
, then the default behavior of the COBOL-IT Compiler is to implicitly declare an external variable name, and assign it a name derived from theFD
named in theSELECT
clause. - The convention used is as follows:
Consider the statement:SELECT myfile ASSIGN DYNAMIC file-var...…
77 file-var
pic x(8) value “customer”.
In this case,file-var
is not declared asEXTERNAL
, so COBOL-IT issues the following warning:‘file-var’ declared implicitly EXTERNAL AS
‘FE_file_myfile_ASSIGN’ (-fno-file-auto-external to disable)
.
Creating the implicit name based on the file name guarantees that the programmer will be able to give different names to[file-var]
in different programs, and that they will nonetheless share the same value.
As noted in the Warning message, this functionality may be disabled using the compiler flag-fno-file-auto-external
. However, when disabling this functionality, be aware, that if you have separate programs sharing the sameEXTERNAL
file that also havefile-var
fields, then changes made between the programs will not automatically be shared. Iffile-var
is declared explicitly asEXTERNAL
, then this condition does not apply. - A file declared
EXTERNAL
shares itsOPEN
, andCLOSE
state,READ
/WRITE
buffers, and file pointer state between separately compiled programs within the run unit. - All programs using the file must have the same
SELECT
andFD
declarations for the file, and the same variable describing the name of the file asEXTERNAL
. - The
VALUE
clause can be applied to fields described asEXTERNAL
. When aVALUE CLAUSE
is applied to a field described asEXTERNAL
, the runtime looks in memory for the external symbol. If the symbol is found, having been allocated by a previous run orCALL
’ing program, then theVALUE
clause is ignored. If the symbol is not found, then the runtime allocates the variable, and fills the allocation with theVALUE
clause. In summary, theVALUE
clause can only be applied in the first program allocating the field. When applied in programs other than the first program allocating the field, theVALUE
clause is ignored . - The
-ffile-auto-external
compiler flag affects the way that the compiler treats variables describing file names for files described asEXTERNAL
.
Global Clause
General Format:
[ IS GLOBAL ]
General Rules:
- The
GLOBAL
clause indicates that a data item, and any data items or conditions or indexes subordinate to it, may be accessed by any of the programs in a compilation unit. - The
GLOBAL
clause may only be used with data items having an 01 data level. - The
GLOBAL
clause may be used in the File Section, Working-Storage Section, Local Storage Section, and Linkage Section.
Justified Clause
The JUSTIFIED RIGHT
clause causes a MOVE
of data to an ALPHABETIC
or ALPHANUMERIC
data item to align at the right-most character position of the data element.
General Format:
[ {JUSTIFIED} RIGHT ]
{JUST}
General Rules:
JUST
andJUSTIFIED
are synonyms.- The
JUSTIFIED
clause can only be applied at the elementary data item level. - The
JUSTIFIED RIGHT
clause can only be used onALPHABETIC
andALPHANUMERIC
data items. - The
JUSTIFIED
clause alters the standard alignment rules in the following manner:
Data is aligned at the right-most character position in the data element.
If the value of the sending item is smaller than the maximum value expressible in the receiving item, and there are extra character spaces, the left-most character positions are space-filled. If there are not enough character places in the receiving data item to accommodate the value of the sending item, truncation takes place after the left-most character space has been filled. - The
JUSTIFIED
clause is not applied to the initial settings of variables with theVALUE
clause.
Like Clause
The LIKE
clause allows you to define the PICTURE
, USAGE
, and SIGN
characteristics of a data item by copying them from a previously defined data item. The LIKE
Statement can be used to describe elementary data items at level 01 through level 49.
General Format:
LIKE data-name
Syntax:
data-name
can be an elementary, or group item.
Code Sample:
01 field-1 PIC X(10).
01 field-2 LIKE field-1.
*>In the example above, field-2 is described with the definition PIC X(10).
01 RECORD1.
05 element-1 PIC X(10).
05 element-2 PIC 9(4).
01 RECORD2 LIKE RECORD1.
*> In the example above, RECORD2 is described with the definition :
01 RECORD2.
05 element-1 PIC X(10).
05 element-2 PIC 9(4).
Occurs Clause
General Format:
[ OCCURS { integer TIMES }
{ int-1 TO int-2 TIMES DEPENDING ON identifier-1 }
[ {ASCENDING } KEY IS {key-name} ... ] ...
{DESCENDING}
[ INDEXED BY {occurs-index} ... ] ]
Syntax:
integer
is a positive integer describing the size of the table.int-1
is an integer describing the minimum number of occurrences.int-2
is an integer describing the maximum number of occurrences.int-2
must be greater thanint-1
.identifier-1
is a numeric data item.key-name
is a data name contained within theOCCURS
clause.occurs-index
is an index name.
General Rules:
- The
OCCURS
clause describes the number of occurrences in a table. - A fixed length table is described with the
OCCURS integer TIMES
clause. - A variable length table is described with the
OCCURS int-1 TO int-2 TIMES DEPENDING ON identifier-1
clause. - When describing a variable length table, with the number of occurrences
DEPENDING ON identifier-1
,identifier-1
must be a numeric data item, and must have a value greater than or equal the minimum number of occurrences described byint-1
, and less than or equal the maximum number of occurrences described byint-2
. - If the table being described contains data that is sorted, then including this information in
the description of the table using the
ASCENDING KEY
,DESCENDING KEY
, andINDEX
clauses allows for the use of theSEARCH ALL
statement on the contents of the table. - When using the
ASCENDING KEY IS key-name
clause , key name must be a data item described in the table, and the data in the table must be sorted onkey-name
inASCENDING
order. - When using the
DESCENDING KEY IS key-name
clause ,key-name
must be a data item described in the table, and the data in the table must be sorted onkey-name
inDESCENDING
order. - When multiple instances of
ASCENDING KEY
andDESCENDING KEY
are described, the first instance is considered the primary sort key, the second instance the secondary sort key, and so forth. The sort keys are applied in the order in which they are listed. - The data item referenced in the
INDEXED BY index
clause is a data name described asUSAGE INDEX
. For more information aboutUSAGE INDEX
data items , see the USAGE clause section. - The elements subordinate to the
OCCURS
clause must be referred to in the program with subscripts. - The default behaviour of the compiler is to require that phrases with
OCCURS
clause not be used at the 01-level. To alter this behaviour, modify thedefault.conf
file, as follows:top-level-occurs-clause: ok
Picture Clause
General Format:
[ {PICTURE} IS picture-string ]
{PIC }
Syntax:
picture-string
uses symbols, with notations to indicate repeat symbols, to describe the characteristics of each of the character positions of a data item.- Inside
picture-string
, the following picture symbols are supported, in proper context:
General Rules:
The General Rules for the PICTURE
clause are described below.
Picture Symbols
Classifying Character Types
PIC: 1
Character Type: Boolean character
General Rules:
- Each symbol '1' represents the position of a Boolean character.
- Each symbol '1' adds 1 byte to the size of the item.
PIC 1
may be used withUSAGE DISPLAY
,COMP
,COMP-5
,COMP-X
,BIT
.- When used with
USAGE COMP
,COMP-5
,COMP-X
the minimum number of bytes needed to store the required number of bits is allocated. - When used with
USAGE DISPLAY
, one byte per bit is allocated. - Each byte contains “0” or “1”.
- When using
USAGE BIT
, the exact numbers of bits are used that are allocated in the current bit field . For example, the following declaration allocates 3 bytes:01 bx PIC 1(24) USAGE COMP-5.
- The maximum number of bits allowed is 64.
- Display of a
PIC 1
field will display the bits, for example, “000101
”. PIC 1
fields are numeric and may be used in computations andMOVE
s for their integer value.- Literary binary constants are now supported, for example
VALUE B’1011’
. - Data items described as
PIC 1 USAGE BIT
are allowed to have anOCCURS
clause. For example:05 element-1 PIC 1 USAGE BIT OCCURS 10000.
- Data described as
USAGE BIT
may be initialized at program startup, as indicated by theinitialize-filler:yes
compiler configuration flag, and as indicated by theVALUE
clause.
As an example, theFILLER
in the groupALL-FLAGS
below is initialized toB”1”
wheninitialize-filler:yes
is set in the compiler configuration file:
01 ALL-FLAGS.
03 FILLER PIC 1 BIT
88 ALL-DONE VALUE B”1” FALSE B”0”.
…
INITIALIZE ALL-FLAGS.
…
PIC: 9
Character Type: Numeric digit
General Rules:
- Each symbol '
9
' represents the position of a numeric digit. - For
USAGE DISPLAY
, each symbol ‘9
’ represents a numeric digit, values 0 through 9, and each symbol ‘9
’ adds 1 byte to the size of the item. - For other
USAGE
cases, correlation between the number of ‘9
’s and the size of the item is described in the General Rules of the USAGE clause.
PIC: A
Character Type: Alphabetic character
General Rules:
- Each symbol '
A
' represents the position of an alphabetic character. - Each symbol '
A
' adds 1 byte to the size of the item.
PIC: N
Character Type: National character
General Rules:
- Each symbol '
N
' represents the position of a national character. - Each symbol '
N
' adds 1 byte to the size of the item.
PIC: S
Character Type: Indicates an operational sign
General Rules:
- The symbol '
S
' indicates that internal data storage will include information about the operational sign. - For
USAGE DISPLAY
, each symbol ‘S
’ adds 1 byte to the size of the item when theSIGN SEPARATE
clause is present. - For other
USAGE
cases, the implementation of the ‘S
’ in data storage is described in the General Rules of the USAGE clause section.
PIC: X
Character Type: Alphanumeric character
General Rules:
- Each symbol '
X
' represents the position of an alphanumeric character. - Each symbol '
X
' adds 1 byte to the size of the item.
Replacement Editing Characters
PIC: *
Character Type: Leading digit replaced by * when 0
General Rules:
- Each symbol '
*
' represents the position of a numeric character, and further represents that leading 0’s will be replaced with the “*
” character. - Each symbol '
*
' adds 1 byte to the size of the item.
PIC: Z
Character Type: Leading digit replaced by space when 0
General Rules:
- Each symbol '
Z
' represents the position of a numeric character, and further represents that leading 0’s will be replaced with the space character. - Each symbol '
Z
' adds 1 byte to the size of the item.
Positional Insertion Editing Characters
PIC: ,
Character Type: Position where a comma is inserted
General Rules:
- Each symbol '
,
' (comma) represents the position of the insertion of a “,
” (comma). - Each symbol '
,
' adds 1 byte to the size of the item.
Note
When the DECIMAL-POINT IS COMMA
clause is used in a program, the COMMA
editing character is interpreted as a PERIOD
, and the PERIOD
editing character is interpreted as a COMMA
.
PIC: .
Character Type: Position where a decimal point is inserted
General Rules:
- The symbol '
.
' (period) represents the position of the insertion of a “.
” (period). - Each symbol '
,
' adds 1 byte to the size of the item.
Note
When the DECIMAL-POINT IS COMMA
clause is used in a program, the PERIOD
editing character is interpreted as a COMMA
, and the COMMA
editing character is interpreted as a PERIOD
.
PIC: 0
Character Type: Position where a zero is inserted
General Rules:
- The symbol '
0
' represents the position of the insertion of a “0
” (zero). - Each symbol '
0
' adds 1 byte to the size of the item.
PIC: B
Character Type: Position where a space is inserted
General Rules:
- The symbol '
B
' represents the position of the insertion of a“ ”
(space). - Each symbol '
B
' adds 1 byte to the size of the item.
PIC: /
Character Type: Position where a /
is inserted
General Rules:
- The symbol '
/
' represents the position of the insertion of a “/
” (slash). - Each symbol '
/
' adds 1 byte to the size of the item.
PIC: +
Character Type: Sign control symbol
General Rules:
- The symbol '
+
' represents the position of the insertion of a “+
” (plus sign). - Each symbol '
+
' adds 1 byte to the size of the item.
PIC: -
Character Type: Sign control symbol
General Rules:
- The symbol '
-
' represents the position of the insertion of a “-
” (mins sign). - Each symbol '
-
' adds 1 byte to the size of the item.
PIC: C
CR
Character Type: Sign control symbol
General Rules:
- The symbol '
C
' or ‘CR
’ represents the position of the insertion of a “C
” or “CR
” (CREDIT). The symbols ‘C
’ or ‘CR
’ must be placed at the end of thePICTURE
string. - “
C
” adds 1 byte to the size of the item.
“CR
” adds 2 bytes to the size of the item.
PIC: D
DB
Character Type: Sign control symbol
General Rules:
- The symbol '
D
' or ‘DB
’ represents the position of the insertion of a “D
” or “DB
” (DEBIT). The symbols ‘D
’ or ‘DB
’ must be placed at the end of thePICTURE
string. - “
D
” adds 1 byte to the size of the item.
“DB
” adds 2 bytes to the size of the item.
PIC: $
Character Type: Position where currency symbol is inserted
General Rules:
- The symbol ‘
$
’ represents the position of the insertion of the currency symbol. The currency symbol is either the ‘$
’ symbol, or by the currency symbol named in theCURRENCY
clause in theSPECIAL-NAMES
paragraph. - “
$
” adds 1 byte to the size of the item.
Positioning Scaling Positions
PIC: P
Character Type: Scales a number by a power of 10
General Rules:
- The ‘
P
’ symbol represents the position of a multiplication by a power of 10. Thus,PIC 9PP
represents a number that is stored internally as a single digit (0-9), but represents the numbers 000, 100, 200, … 900.
Similarly,PIC PP9
represents a number that is stored internally as a single digit (0-9), but represents the decimal numbers .000, .001, .002… .009. - The symbol ‘
P
’ can only appear in either the left-most or right-most positions of aPICTURE
string. - An assumed decimal point, marked by the “
V
” symbol, may be used either to the right of the high-order ‘P
’ symbol(s) or to the left of the low-order ‘P
’ symbols. - The “
.
” Symbol may not be used in the same picture string as the ‘P
’ symbol. - When included in a
MOVE
to a numeric field, or a numeric comparison, or a calculation, the data item is represented as though each ‘P
’ symbol were a place-holder containing a 0.
Positioning Assumed Decimal Point
PIC: V
Character Type: Position of an assumed decimal point
General Rules:
- The symbol '
V
' represents the position of an assumed decimal point. - The symbol '
V
' does not add to the size of the item.
Picture Data Categories
A PICTURE
clause defines the subject of the entry to fall into one of the following categories of data:
a. Alphabetic
b. Alphanumeric
c. Alphanumeric Edited
d. Boolean
e. National
f. Numeric
g. Numeric Edited
The descriptions of each of these categories follows:
Category | General Rules |
---|---|
Alphabetic | An Alphabetic Picture String contains “A ” symbols only. |
Alphanumeric | An alphanumeric picture string must have either an “X ” symbol, or some combination of “X ”, “A ”, and “9 ” symbols.A picture string consisting of only “ A ” symbols or only “9 ” symbols is not alphanumeric. |
Alphanumeric Edited | An alphanumeric-edited picture string must have one or more “X” symbols, one or more “A” symbols, and at least one of the insertion symbols “B”, “0”, or “/”. |
Boolean | A boolean picture string must have one or more “I ” symbols. |
National | A national picture string must have one or more “N ” symbols. |
Numeric | A numeric picture string must have one or more “9 ” symbols, and can also contain one or more “P ”, “S ”, or “V ” symbols. When signed, numeric picture strings can contain the “+ ” or “- “ symbol. |
Numeric Edited | A numeric edited picture string contains some combination of one or more of the symbols “9 ” , “* ”,“Z ”, comma, period, “0 ”, “B ”, “/ ”,“+ ”, “- ”,“CR ”, “DB ”, “$ ”,“P ”,“V ”. |
Rules for Alignment of Data
General Rules:
When data is moved into a data element, the rules for alignment of data vary according to the data category of the data element receiving the data.
For numeric data elements with a fixed decimal point:
- Data is aligned on the fixed decimal point.
- Digits to the left and right of the decimal point are moved from the decimal point to the left for integer digits, and from the decimal point to the right for decimal digits.
- If there are not enough decimal places in the receiving data item to accommodate the data to the left of the decimal point, truncation of the high-order bytes takes place .
- If there are not enough decimal places in the receiving data item to accommodate the data to the right of the decimal point, truncation of the low-order bytes takes place.
- Extra decimal places in the receiving data item to the left or the right of the decimal point are zero filled.
- If no decimal point is indicated explicitly, then numeric data items are assigned an implicit decimal point after the right most integer digit.
- Boolean data elements are treated as numeric data elements with an integer value, and with an implicit decimal point after the right most integer digit.
For numeric edited data elements with a fixed decimal point:
- Data alignment rules are the same as for numeric data elements with a fixed decimal point, except that numeric edited data elements may describe replacement characters for leading zeroes.
For alphabetic, alphanumeric, alphanumeric-edited, national data elements:
- Data is aligned at the left most character position in the data element.
- Extra character places in the receiving data item are space filled.
- If there are not enoug h character places in the receiving data item to accommodate the data being sent, truncation takes place after the right most character space is filled.
- Data alignment rules may be altered if the receiving data item has a
JUSTIFIED
clause. Alignment rules for theJUSTIFIED
clause are described in the JUSTIFIED clause section.
Redefines Clause
The REDEFINES
clause causes two data items with different names, and potentially different data descriptions to occupy the same internal memory storage.
General Format:
[ REDEFINES identifier-1 ]
Syntax:
identifier-1
is a data item immediately prec eding the redefining data item.
General Rules:
- The data item that
REDEFINES
identifier-1
must immediately followidentifier-1
. - The data item that
REDEFINES
identifier-1
must have the same level number asidentifier-1
The level number may not be 66, 78, or 88. - If the data item that
REDEFINES
identifier-1
is smaller thanidentifier-1
, it will store data that begins with the first byte ofidentifier-1
, and continues for its full length. The truncation is in the right most bytes ofidentifier-1
. - If the data item that
REDEFINES
identifier-1
is larger thanidentifier-1
, there is potential for a memory access violation as the memory that is defined is only as long asidentifier-1
. - The data item that
REDEFINES
identifier-1
may not contain anyVALUE
clauses, other than those contained in level-88 condition statements.
RENAMES Clause
General Format:
[ RENAMES identifier-1 [ {THRU } identifier-2 ] .
{THROUGH}
Syntax:
identifier-1
is a data element.identifier-2
is a data element declared afteridentifier-1
. All data elements betweenidentifier-1
andidentifier-2
are grouped together under the original data descriptor in the clause.
General Rules:
- The
RENAMES
clause is only used with level-66 data items. - Level-66 data items may only rename items with data levels between 02 and 49 (inclusive). Level-66 data items may not rename level-01 data items, or level-66, level-77, level-78, or level-88 data items.
- The data item that
RENAMES
identifier-1
(thruidentifier-2
) must immediately followidentifier-1
(thruidentifier-2
). - None of the data items in the renamed data item(s) may have variable length.
- When the
THRU
clause is used, the level-66 data item provides a new name for all contiguous data storage beginning atidentifier-1
, up to and includingidentifier-2
.Identifier-2
must be declared afteridentifier-1
. - When the
THRU
clause is used, the level-66 data item is treated as a group item that contains all of the contiguous data elements fromidentifier-1
throughidentifier-2
. THRU
andTHROUGH
are synonyms.
Code Sample:
IDENTIFICATION DIVISION.
PROGRAM-ID. rename1.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 customer-data.
03 customer-name PIC X(25).
03 customer-street-number PIC X(10).
03 customer-street PIC X(25).
66 customer-street-addr RENAMES
customer-street-number THRU customer-street.
77 ws-dummy pic x.
PROCEDURE DIVISION.
0000-MAIN.
MOVE "John Doe" to customer-name.
MOVE "25" to customer-street-number.
MOVE "Main Street" to customer-street.
DISPLAY customer-street-addr line 10 col 10.
ACCEPT ws-dummy line 10 col 50.
STOP RUN.
Sign Clause
The SIGN
clause determines how SIGN information is stored in USAGE DISPLAY
data items that are described with the “S
” symbol.
General Format:
[ [ SIGN IS ] {LEADING } [ SEPARATE CHARACTER ] ]
{TRAILING}
General Rules:
- The
SIGN
clause is only used with numeric data items that have aUSAGE DISPLAY
. - A
SIGN
clause may be described at a group level, in which case it will apply to all of the elementary items within that group. - If an elementary item within that group contains its own
SIGN
clause that is different than theSIGN
clause of the group item, theSIGN
clause of the elementary data item takes precedence over theSIGN
clause of the group item. - When the
SEPARATE CHARACTER
phrase is used, the positive sign is stored as a “+
” character, and the negative sign is stored as a “-
“ character. - When the
SEPARATE CHARACTER
phrase is not used, the negativeSIGN
is encoded, according to whetherLEADING
orTRAILING
is used, as shown in the following table:
Sign Digit Character for:
Positively-signed values Negatively-signed values
Digit | -fsign-ascii | -fsign-ebcdic | -fcarealia-sign | -fsign-ascii | -fsign-ebcdic | -fcarealia-sign |
---|---|---|---|---|---|---|
0 | 0(30) | {(7B) | 0(30) | p(70) | }(7D) | 0(30) |
1 | 1(31) | A(41) | 1(31) | q(71) | J(4A) | !(21) |
2 | 2(32) | B(42) | 2(32) | r(72) | K(4B) | "(22) |
3 | 3(33) | C(43) | 3(33) | s(73) | L(4C) | #(23) |
4 | 4(34) | D(44) | 4(34) | t(74) | M(4D) | $(24) |
5 | 5(35) | E(45) | 5(35) | u(75) | N(4E) | %(25) |
6 | 6(36) | F(46) | 6(36) | v(76) | O(4F) | &(26) |
7 | 7(37) | G(47) | 7(37) | w(77) | P(50) | '(27) |
8 | 8(38) | H(48) | 8(38) | x(78) | Q(51) | ((28) |
9 | 9(39) | I(49) | 9(39) | y(79) | R(52) | )(29) |
Examples (compiled with –fsign-ascii
) :
Picture Clause | Storage |
---|---|
PIC S9(4) SIGN IS TRAILING VALUE -1230 | 123p |
PIC S9(4) SIGN IS TRAILING VALUE -1231 | 123q |
PIC S9(4) SIGN IS TRAILING VALUE -1232 | 123r |
PIC S9(4) SIGN IS TRAILING VALUE 1230 | 1230 |
PIC S9(4) SIGN IS TRAILING VALUE 1231 | 1231 |
PIC S9(4) SIGN IS TRAILING VALUE 1232 | 1232 |
PIC S9(4) SIGN IS LEADING VALUE -0321 | p321 |
PIC S9(4) SIGN IS LEADING VALUE -1321 | q321 |
PIC S9(4) SIGN IS LEADING VALUE -2321 | r321 |
PIC S9(4) SIGN IS LEADING VALUE 0321 | 0321 |
PIC S9(4) SIGN IS LEADING VALUE 1321 | 1321 |
PIC S9(4) SIGN IS LEADING VALUE 2321 | 2321 |
If there is no SIGN
clause, the default is to assign the storage rules for the SIGN IS TRAILING
clause.
Examples (compiled with –fsign-ascii
) :
Picture Clause | Storage |
---|---|
PIC S9(4) VALUE -1230 | 123p |
PIC S9(4) VALUE 1230 | 1230 |
Synchronized Clause
The SYNCHRONIZED
Clause affects the manner in which binary data is stored, with the intention of optimizing the performance.
General Format:
[ {SYNCHRONIZED} [{LEFT } ] ]
{SYNC} [{RIGHT}]
General Rules:
SYNC
andSYNCHRONIZED
are synonyms.- When a data item is
SYNCHRONIZED
, it cannot share any unused space within its natural boundaries with any other data item. SYNCHRONIZED LEFT
causes the data to be aligned to the left-most byte of the natural boundary in which it is stored. Unused space, if there is any, will appear in the right-most bytes of the natural boundary.SYNCHRONIZED RIGHT
causes the data to be aligned to the right most byte of the natural boundary in which it is stored. Unused space, if there is any, will appear in the left-most bytes of the natural boundary.
Typedef Clause
The TYPEDEF
field attribute allows you to define a “user-defined” USAGE
.
General Format:
IS TYPEDEF ]
Syntax:
A data description with the IS TYPEDEF
attribute must have a data level 01 or a data level 77.
General Rules:
- The
TYPEDEF
clause indicates that the data description is a typedef declaration, and not a variable declaration. The data name can then be used with theUSAGE
clause. TYPEDEF
declarations cannot store data.- If the data description with the
TYPEDEF
clause is a level-01 data item, all subordinate data names, including level-66, level-78, and level-88 data names, are part of the typedef declaration. - Subordinate data names must be qualified with the name of the data name using the
USAGE [typedef]
clause. - A data item with
USAGE [ TYPEDEF ]
may be the subject of anOCCURS
.
For example:05 cust-data usage customer-info occurs 1000 times.
TYPEDEF
s haveGLOBAL
scope by default. This behaviour may be changed by use of the-fno-global-typedef
compiler flag.
Code Sample:
*
IDENTIFICATION DIVISION.
PROGRAM-ID. TYPEDEF1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CUSTOMER-INFO IS TYPEDEF.
05 CUSTOMER-ADDRESS.
10 CUSTOMER-STREET-NUM PIC X(5).
10 CUSTOMER-STREEN-NAME PIC X(20).
10 CUSTOMER-CITY PIC X(15).
10 CUSTOMER-STATE PIC X(4).
10 CUSTOMER-ZIP PIC X(5).
01 CUST-DATA USAGE CUSTOMER-INFO.
77 WS-DUMMY PIC X.
PROCEDURE DIVISION.
MAIN.
MOVE "1600" TO CUSTOMER-STREET-NUM OF CUST-DATA.
MOVE "PENNSYLVANIA AVE." TO CUSTOMER-STREEN-NAME OF CUST-DATA.
MOVE "WASHINGTON" TO CUSTOMER-CITY OF CUST-DATA.
MOVE "DC" TO CUSTOMER-STATE OF CUST-DATA.
MOVE "20202" TO CUSTOMER-ZIP OF CUST-DATA.
DISPLAY CUSTOMER-ADDRESS OF CUST-DATA LINE 10 COL 10.
DISPLAY "TYPEDEF1 FINISHED!" LINE 15 COL 10.
ACCEPT WS-DUMMY LINE 15 COL 30.
STOP RUN.
Usage Clause
The USAGE
clause affect the manner in which a data type is stored in memory.
General Format:
[ [ USAGE IS ] { usage-type
} ]
Syntax:
usage-type
may be any of the following:
Column 1 | Column 2 | Column 3 |
---|---|---|
{ BINARY } |
{ BINARY-LONG SIGNED } |
{ COMPUTATIONAL-5 } |
{ PACKED-DECIMAL } |
{ BINARY-LONG UNSIGNED } |
{ COMP-5 } |
{ DISPLAY } |
{ BINARY-SHORT } |
{ COMPUTATIONAL-6 } |
{ INDEX } |
{ BINARY-SHORT SIGNED } |
{ COMP-6 } |
{ POINTER } |
{ BINARY-SHORT UNSIGNED } |
{ COMPUTATIONAL-X } |
{ PROGRAM-POINTER } |
{ COMPUTATIONAL } |
{ COMP-X } |
{ BINARY-C-LONG } |
{ COMP } |
{ FLOAT-SHORT } |
{ BINARY-C-LONG SIGNED } |
{ COMPUTATIONAL-1 } |
{ FLOAT-LONG } |
{ BINARY-C-LONG UNSIGNED } |
{ COMP-1 } |
{ SIGNED-INT } |
{ BINARY-CHAR } |
{ COMPUTATIONAL-2 } |
{ SIGNED-LONG } |
{ BINARY-CHAR SIGNED } |
{ COMP-2 } |
{ SIGNED-SHORT } |
{ BINARY-CHAR UNSIGNED } |
{ COMPUTATIONAL-3 } |
{ UNSIGNED-INT } |
{ BINARY-DOUBLE } |
{ COMP-3 } |
{ UNSIGNED-LONG } |
{ BINARY-DOUBLE SIGNED } |
{ COMPUTATIONAL-4 } |
{ UNSIGNED-SHORT } |
{ BINARY-DOUBLE UNSIGNED } |
{ COMP-4 } |
{ user_typedef } |
{ BINARY-LONG } |
Syntax:
user_typedef
is a field name defined as IS TYPEDEF
.
General Rules:
- If no
USAGE
clause is declared, thenUSAGE DISPLAY
is implied. - If a
USAGE
clause is declared or implied on a group level data item, all subordinate data names inherit theUSAGE
clause declaration. - For General Specifications of all of the
USAGE
types, see Appendix 6.1 Data Memory Allocation. LINK
Usage BINARY
Data Storage:
Data Description | Data Storage |
---|---|
PIC S9(3) USAGE BINARY VALUE -123 | FF 85 |
PIC 9(3) USAGE BINARY VALUE 123 | 00 7B |
General Rules:
BINARY
data is sized according to the number of 9’s in the PICTURE
clause, and according to the setting of the binary-size
compiler configuration flag. For details, see the documentation of the binary-size compiler configuration flag in Compiler Configuration File.
Usage packed-decimal
Data Storage:
Data Description | Data Storage |
---|---|
PIC S9(3) USAGE BINARY VALUE -123 | 12 3D |
PIC S9(3) USAGE BINARY VALUE 123 | 12 3C |
General Rules:
USAGE PACKED DECIMAL
,USAGE COMP-3
, andUSAGE COMPUTATIONAL-3
are synonyms.COMP-3
/PACKED DECIMAL
data allocates 4 bits per “9” in thePICTURE
clause, plus a trailing 4 bits for the sign. To calculate the size of aCOMP-3
/PACKED DECIMAL
data item, add 1 (for the sign) to the number of 9’s in thePICTURE
clause, divide by 2, and if the result is not a whole number, round it up to the next integer.- The
half-byte D
indicates a negative sign, thehalf-byte C
indicates a positive sign.
Usage Display
Usage National
For details on USAGE DISPLAY
and USAGE NATIONAL
data storage, see Rules for Alignment of Data and Sign Clause.
General Rules:
- The
USAGE DISPLAY
clause indicates that a data item is Alphabetic, Alphanumeric, Alphanumeric Edited, Numeric , Numeric Edited , or National. - If no
USAGE
clause is declared, thenUSAGE DISPLAY
is implied.
Usage Index
Data Storage:
Data Description | Data Storage |
---|---|
USAGE INDEX VALUE 0 | 00 00 00 00 |
USAGE INDEX VALUE 1 | 01 00 00 00 |
General Rules:
- The
USAGE INDEX
clause indicates that a data item is an index is being used in table-handling functions. USAGE INDEX
data allocates 32-bits in native format.USAGE INDEX
data does not allow the use of thePICTURE
clause.USAGE INDEX
data does support negative values.
USAGE POINTER
USAGE PROCEDURE-POINTER
USAGE PROGRAM-POINTER
Data Storage:
Data Description | Data Storage |
---|---|
USAGE POINTER (initial) | 00 00 00 00 |
USAGE POINTER (set to address of data-item) | D0 41 11 6C |
USAGE PROCEDURE-POINTER (initial val) | 00 00 00 00 |
USAGE PROCEDURE-POINTER (set ) | 10 10 11 6C |
USAGE PROGRAM-POINTER (initial value) | 00 00 00 00 |
USAGE PROGRAM-POINTER ( set ) | 00 10 11 6C |
General Rules:
- Data items described with
USAGE POINTER
,USAGE PROCEDURE POINTER
, andUSAGE PROGRAM POINTER
are initialized toNULL
when a program is initially loaded into memory. - Data items described with
USAGE POINTER
,USAGE PROCEDURE POINTER
, andUSAGE PROGRAM POINTER
hold unsigned 32-bit binary values on machines with 32-bit architectures, and unsigned 64-bit binary values on machines with 64-bit architectures. - Data items described with
USAGE POINTER
,USAGE PROCEDURE POINTER
, andUSAGE PROGRAM POINTER
may be assigned a data address through the use of theALLOCATE
, orSET
statement, and that memory may be released through the use of theFREE
statement.
Example:SET pointer-var TO ADDRESS OF data-item.
SET procedure-pointer-var TO ENTRY "entry-name-literal".
SET program-pointer-var TO ENTRY "program-id-literal".
- The
USAGE POINTER
clause indicates that a data item is a data pointer, which can hold the address of a data item . - The
USAGE PROGRAM-POINTER
clause indicates that a data item is program pointer, which can hold the address of a program. - The program name from which the
PROGRAM-POINTER
is derived may be either thePROGRAM-ID
of a program, or the entry-name of anENTRY
statement. - The
USAGE PROCEDURE-POINTER
clause indicates that a data item is procedure pointer, which can hold the address of a procedure - The procedure name from which the
PROCEDURE-POINTER
is derived is the entry-name of anENTRY
statement. USAGE POINTER
,PROGRAM-POINTER
, andPROCEDURE-POINTER
do not allow the use of thePICTURE
clause.
Code Sample:
*
...
01 ERROR-PROC-FLAG PIC X COMP-X VALUE 0.
01 ERROR-PROC-ADDR USAGE PROCEDURE-POINTER.
*
...
SET EXIT-PROC-ADDR TO ENTRY "EXIT-PROC".
...
CALL "CBL_EXIT_PROC" USING EXIT-PROC-FLAG,
EXIT-PROC-ADDR.
STOP RUN.
...
ENTRY "EXIT-PROC".
DISPLAY "IN EXIT PROCEDURE".
EXIT PROGRAM.
STOP RUN.
*
USAGE BINARY-C-LONG
BINARY-C-LONG SIGNED
BINARY-C-LONG UNSIGNED
Data Storage:
Data Description | Data Storage |
---|---|
USAGE BINARY-C-LONG (initial) | 00 00 00 00 |
USAGE BINARY-C-LONG VALUE 123. | 7B 00 00 00 |
USAGE BINARY-C-LONG SIGNED (initial) | 00 00 00 00 |
USAGE BINARY-C-LONG SIGNED VALUE -123. | 85 FF FF FF |
USAGE BINARY-C-LONG UNSIGNED (initial) | 00 00 00 00 |
USAGE BINARY-C-LONG UNSIGNED VALUE 123. | 7B 00 00 00 |
General Rules:
- Data items with
USAGE BINARY-C-LONG
are initialized toNULL
when the program is loaded in memory. BINARY-C-LONG
data allocates the same amount of storage as does the C language “long” data type. Depending on the C compiler being used, this could be 32, or 64-bits.BINARY-C-LONG
data does not allow the use of thePICTURE
clause.BINARY-C-LONG
data may be described asSIGNED
orUNSIGNED
.BINARY-C-LONG UNSIGNED
data does not support negative values.BINARY-C-LONG
data has theSIGNED
attribute by default.
Code Sample:
*
IDENTIFICATION DIVISION.
PROGRAM-ID. FIBONACCI.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 IX BINARY-C-LONG VALUE 0.
01 FIRST-NUMBER BINARY-C-LONG VALUE 0.
01 SECOND-NUMBER BINARY-C-LONG VALUE 1.
01 TEMP-NUMBER BINARY-C-LONG VALUE 1.
01 DISPLAY-NUMBER PIC Z(19)9.
*
78 32-BIT-ITERATIONS VALUE 46.
78 64-BIT-ITERATIONS VALUE 90.
PROCEDURE DIVISION.
MAIN.
MOVE FIRST-NUMBER TO DISPLAY-NUMBER.
DISPLAY DISPLAY-NUMBER.
MOVE SECOND-NUMBER TO DISPLAY-NUMBER.
DISPLAY DISPLAY-NUMBER.
PERFORM VARYING IX FROM 1 BY 1 UNTIL IX = 32-BIT-ITERATIONS
ADD FIRST-NUMBER TO SECOND-NUMBER GIVING TEMP-NUMBER
MOVE SECOND-NUMBER TO FIRST-NUMBER
MOVE TEMP-NUMBER TO SECOND-NUMBER
MOVE TEMP-NUMBER TO DISPLAY-NUMBER
DISPLAY DISPLAY-NUMBER
END-PERFORM.
STOP RUN.
USAGE BINARY-CHAR
BINARY-CHAR SIGNED
BINARY-CHAR UNSIGNED
Data Storage:
Data Description | Data Storage |
---|---|
USAGE BINARY-CHAR (initial) | 00 |
USAGE BINARY-CHAR VALUE 123. | 7B |
USAGE BINARY-CHAR SIGNED VALUE -123. | 85 |
USAGE BINARY-CHAR UNSIGNED VALUE 123. | 7B |
General Rules:
- Data items with
USAGE BINARY-CHAR
are initialized toNULL
when the program is loaded in memory. BINARY-CHAR
data designates a single byte using the native storage format.BINARY-CHAR
data does not allow the use of thePICTURE
clause.BINARY-CHAR
data may be described asSIGNED
orUNSIGNED
.BINARY-CHAR UNSIGNED
data does not support negative values.BINARY-CHAR
data has theSIGNED
attribute by default.
USAGE BINARY-DOUBLE
BINARY-DOUBLE SIGNED
BINARY-DOUBLE UNSIGNED
Data Storage:
Data Description | Data Storage |
---|---|
USAGE BINARY-DOUBLE (initial) | 00 00 00 00 00 00 00 00 |
USAGE BINARY-DOUBLE VALUE 123. | 7B 00 00 00 00 00 00 00 |
USAGE BINARY-DOUBLE SIGNED VALUE -123. | 85 FF FF FF FF FF FF FF |
USAGE BINARY-DOUBLE UNSIGNED VALUE 123. | 7B 00 00 00 00 00 00 00 |
General Rules:
- Data items with
USAGE BINARY-DOUBLE
are initialized toNULL
when the program is loaded in memory. BINARY-DOUBLE
data allocates a “traditional” double word of storage (64-bits) using the native storage format.BINARY-DOUBLE
data does not allow the use of thePICTURE
clause.BINARY-DOUBLE
data may be described asSIGNED
orUNSIGNED
.BINARY-DOUBLE UNSIGNED
data does not support negative values.BINARY-DOUBLE
data has theSIGNED
attribute by default.
USAGE BINARY-LONG
BINARY-LONG SIGNED
BINARY-LONG UNSIGNED
Data Storage:
Data Description | Data Storage |
---|---|
USAGE BINARY-LONG (initial) | 00 00 00 00 |
USAGE BINARY-LONG VALUE 123. | 7B 00 00 00 |
USAGE BINARY-LONG SIGNED VALUE -123. | 85 FF FF FF |
USAGE BINARY-LONG UNSIGNED VALUE 123. | 7B 00 00 00 |
General Rules:
- Data items with
USAGE BINARY-LONG
are initialized toNULL
when the program is loaded in memory. BINARY-LONG
data allocates 32-bits of storage using the native storage format.BINARY-LONG
data does not allow the use of thePICTURE
clause.BINARY-LONG
data may be described asSIGNED
orUNSIGNED
.BINARY-LONG UNSIGNED
data does not support negative values.BINARY-LONG
data has theSIGNED
attribute by default.
USAGE BINARY-SHORT
BINARY-SHORT SIGNED
BINARY-SHORT UNSIGNED
Data Storage:
Data Description | Data Storage |
---|---|
USAGE BINARY-SHORT (initial) | 00 00 |
USAGE BINARY-SHORT VALUE 123. | 7B 00 |
USAGE BINARY-SHORT SIGNED VALUE -123. | 85 FF |
USAGE BINARY-SHORT UNSIGNED VALUE 123. | 7B 00 |
General Rules:
- Data items with
USAGE BINARY-SHORT
are initialized toNULL
when the program is loaded in memory. BINARY-SHORT
data allocates 16-bits of storage using the native storage format.BINARY-SHORT
data does not allow the use of thePICTURE
clause.BINARY-SHORT
data may be described asSIGNED
orUNSIGNED
.BINARY-SHORT UNSIGNED
data does not support negative values.BINARY-SHORT
data has theSIGNED
attribute by default.
USAGE BIT
General Rules:
USAGE BIT
allocates a field as a bit field.PIC 1(n)
is the only picture allowed.USAGE BIT
may not redefine or be redefined.- Consecutive
USAGE BIT
fields are packed into the same byte area with a maximum size of 8 bytes (64-Bits). - If a
USAGE BIT
field does not fit in the current byte area because the resulting byte area would be greater than 64-bits, then a new byte area will be allocated. Remaining unused bits of a byte area are left unused.
As an example, a single byte would be allocated to contain these 3 fields b1, b2, and b3.03 b1 PIC 1 USAGE BIT
03 b2 PIC 1(3) USAGE BIT.
03 b3 PIC 1(4) USAGE BIT.
- The byte are a stores bits in memory in “System Native” bit order (like
COMP-5
).
Computational Data Types:
USAGE COMPUTATIONAL
USAGE-COMP
Data Storage:
Data Description | Data Storage |
---|---|
PIC S9(3) USAGE COMPUTATIONAL (initial) | 00 00 |
PIC S9(3) USAGE COMPUTATIONAL VALUE -123. | FF 85 |
PIC S9(3) USAGE COMPUTATIONAL VALUE 123. | 00 7B |
General Rules:
USAGE COMPUTATIONA
L data is sized according to the number of 9’s in thePICTURE
clause, and according to the setting of thebinary-size
compiler configuration flag. For details, see the documentation of thebinary-size
compiler configuration flag in Compiler Configuration File
USAGE COMPUTATIONAL-1
USAGE COMP-1
Data Storage:
Data Description | Data Storage |
---|---|
PIC S9(3) USAGE COMP-1 (initial) | 00 00 00 00 |
PIC S9(3) USAGE COMP -1 VALUE -123. | 00 00 F6 C2 |
PIC S9(3) USAGE COMP-1 VALUE 123. | 00 00 F6 42 |
General Rules:
USAGE COMPUTATIONAL-1
andUSAGE COMP-1
are synonyms.COMP-1
data allocates 32 bits of data, formatted as single precision floating point.COMP-1
data does not allow the use of thePICTURE
clause.COMP-1
data does support negative values.
USAGE COMPUTATIONAL-2
USAGE COMP-2
Data Storage:
Data Description | Data Storage |
---|---|
PIC S9(3) USAGE COMP-2 (initial) | 00 00 00 00 00 00 00 00 |
PIC S9(3) USAGE COMP -2 VALUE -123. | 00 00 00 00 00 C0 5E C0 |
PIC S9(3) USAGE COMP-2 VALUE 123. | 00 00 00 00 00 C0 5E 40 |
General Rules:
USAGE COMPUTATIONAL-2
andUSAGE COMP-2
are synonyms.COMP-2
data allocates 64-bits of data, formatted as double precision floating point.COMP-2
data does not allow the use of thePICTURE
clause.COMP-2
data does support negative values.
USAGE COMPUTATIONAL-3
COMP-3
PACKED-DECIMAL
Data Storage:
Data Description | Data Storage |
---|---|
PIC S9(3) USAGE COMP-3 (initial) | 00 00 |
PIC S9(3) USAGE BINARY VALUE -123 | 12 3D |
PIC S9(3) USAGE BINARY VALUE 123 | 12 3C |
General Rules:
USAGE PACKED-DECIMAL
,USAGE COMP-3
, andUSAGE COMPUTATIONAL-3
are synonyms.USAGE PACKED-DECIMAL
data storage stores two decimal digits per byte, and includes a half-byte for the sign, which is placed in the right-most position.- The
half-byte D
indicates a negative sign, thehalf-byte C
indicates a positive sign. - To calculate the
SIZE
of aUSAGE PACKED-DECIMAL
data item, add 1 to the number of decimal digits in the number (for the sign), divide by 2, and round the result up. Thus, for the number 255, there are three decimal digits- add 1 for the sign giving 4- and divide by 2, giving 2. The number 255, or -255 requires 2 bytes.
USAGE COMPUTATIONAL-4
COMP-4
Data Storage:
Data Description | Data Storage |
---|---|
PIC S9(3) USAGE COMP-4 (initial) | 00 00 |
PIC S9(3) USAGE COMP-4 VALUE -123. | FF 85 |
PIC S9(3) USAGE COMP-4 VALUE 123. | 00 7B |
General Rules:
- Data items with
USAGE COMPUTATIONAL
are initialized toxxxx
when the program is loaded in memory. USAGE COMPUTATIONAL-4
andUSAGE COMP-4
are synonyms.COMP-4
data is sized according to the number of 9’s in thePICTURE
clause, and the setting of thebinary-size
compiler configuration flag or the setting of thepack-comp-4
compiler configuration flag. Ifpack-comp-4
is set toNo
(the default), thenCOMP-4
data follows the same rules asCOMPUTATIONAL
data with regards to sizing. Ifpack-comp-4
is set toYes
, then abinary-size
setting of “1--8
” is assumed for binary-size setting, and the sizing is done accordingly.
USAGE COMPUTATIONAL-5
COMP-5
Data Storage:
Data Description | Data Storage |
---|---|
PIC S9(3) USAGE COMP-5 (initial) | 00 00 |
PIC S9(3) USAGE COMP-5 VALUE -123. | 85 FF |
PIC S9(3) USAGE COMP-5 VALUE 123. | 7B 00 |
General Rules:
USAGE COMPUTATIONAL-5
andUSAGE COMP-5
are synonyms.COMP-5
data is sized according to the number of 9’s in thePICTURE
clause, and according to the setting of thebinary-size
compiler configuration flag.COMP-5
data is stored in native format.
USAGE COMPUTATIONAL-6
COMP-6
Data Storage:
Data Description | Data Storage |
---|---|
PIC S9(3) USAGE COMP-6 (initial) | 00 00 |
PIC S9(3) USAGE COMP-6 VALUE 123. | 01 23 |
General Rules:
USAGE COMPUTATIONAL-6
andUSAGE COMP-6
are synonyms.COMP-6
data allocates 4 bits per “9” in thePICTURE
clause. To calculate the size of aCOMP-6
data item, divide the number of 9’s in thePICTURE
clause by 2, and if the result is not a whole number, round it up to the next integer.COMP-6
data does not allow negative values.
USAGE COMPUTATIONAL-X
COMP-X
Data Storage:
Data Description | Data Storage |
---|---|
PIC 9(3) USAGE COMP-X (initial) | 00 00 |
PIC 9(3) USAGE COMP-X VALUE -123. | FF 85 |
PIC 9(3) USAGE COMP-X VALUE 123. | 00 7B |
General Rules:
COMP-X
data is sized according to the number of 9’s or the number of X’s in thePICTURE
clause.- When the
PICTURE
clause consists of 9’s,COMP-X
data assumes a binary-size setting of “1--8
” in calculating the number of bytes that correspond to the number of 9’s in thePICTURE
clause. - When the
PICTURE
clause consists of X’s, one byte is assigned per X in thePICTURE
clause.
USAGE FLOAT-SHORT
USAGE FLOAT-LONG
Data Storage:
Data Description | Data Storage |
---|---|
PIC 9(3) USAGE FLOAT-SHORT (initial) | 00 00 00 00 |
PIC 9(3) USAGE FLOAT-SHORT VALUE -123. | 00 00 F6 C2 |
PIC S9(3) USAGE FLOAT-SHORT VALUE 123 | 00 00 F6 42 |
PIC 9(3) USAGE FLOAT-LONG (initial) | 00 00 00 00 00 00 00 00 |
PIC 9(3) USAGE FLOAT-LONG VALUE -123. | 00 00 00 00 00 C0 5E C0 |
PIC 9(3) USAGE FLOAT-LONG VALUE -123. | 00 00 00 00 00 C0 5E 40 |
General Rules:
USAGE FLOAT-SHORT
is equivalent toUSAGE COMP-1
.USAGE FLOAT-LONG
is equivalent toUSAGE COMP-2
.
The C Data Types
- The C data types are
SIGNED SHORT
,UNSIGNED SHORT
,SIGNED INT
,UNSIGNED INT
,SIGNED LONG
, andUNSIGNED LONG
. They correspond to the C data types “short
”, “int
”, and “long
”. - The C data types do not allow a PICTURE clause.
USAGE SIGNED-SHORT
UNSIGNED-SHORT
USAGE SIGNED-INT
UNSIGNED-INT
USAGE SIGNED-LONG
UNSIGNED-LONG
Data Storage:
Data Description | Data Storage |
---|---|
USAGE SIGNED-SHORT (initial) | 00 00 |
USAGE UNSIGNED-SHORT VALUE -123. | 85 FF |
USAGE SIGNED-INT VALUE 123 | 7B 00 |
USAGE UNSIGNED-SHORT VALUE 123 | 7B 00 |
USAGE SIGNED-INT VALUE -123 | 85 FF FF FF |
USAGE SIGNED-INT VALUE 123 | 7B 00 00 00 |
USAGE UNSIGNED-INT VALUE 123 | 7B 00 00 00 |
USAGE SIGNED-LONG VALUE -123. | 85 FF FF FF FF FF FF FF |
USAGE SIGNED-LONG VALUE 123 | 7B 00 00 00 00 00 00 00 |
USAGE UNSIGNED-LONG VALUE 123 | 7B 00 00 00 00 00 00 00 |
General Rules:
SIGNED-SHORT
andUNSIGNED-SHORT
data allocate 16-bits of storage using the native storage format.SIGNED-INT
andUNSIGNED-INT
data allocate 32-bits of storage using the native storage format.SIGNED-LONG
andUNSIGNED-LONG
data allocate 64-bits of storage using the native storage format.UNSIGNED-SHORT
,UNSIGNED-LONG
andUNSIGNED-INT
data does not support negative values.
VALUE Clause
The VALUE
clause can be used:
- To set the initial value of a data item in the Working-Storage or Local Storage Section.
- To define a value or range of values associated with a level-88 condition.
- To set the value of a level-78 constant.
General Format:
Format 1:
The Format 1 VALUE
clause is used to initialize data values when the program is initially loaded into memory.
[01-LEVEL TO 49-LEVEL, 77-LEVEL DATA-ITEM ]
[ { VALUE IS } {literal-1 } ] .
Syntax:
literal-1
is a numeric or alphanumeric literal which sets the initial value of the data-item in the Working-Storage Section or Local Storage Section.
Example:
77 cobol-compiler PIC X(8) VALUE “COBOL-IT”.
77 nullterminated-var PIC X(8) VALUE Z”ABCDEFG”.
77 current-year PIC 9(4) VALUE 2011.
General Rules:
- Format 1
VALUE
declarations are ignored in theFILE SECTION
andLINKAGE SECTION
. - Some API calls require that strings being passed to them be null-terminated. Prefixing a string with a
Z
has the effect of null-terminating the string. - If the parent data-item is numeric,
literal-1
must be numeric. If the parent data item is alphanumeric,literal-1
must be alphanumeric. - The
VALUE
declaration may not be applied to a data item with a variable size. In a data item that is subordinate to anOCCURS
clause, theVALUE
clause is applied to every instance of the `OCCURS. - When applied to a group item, the parent date item is considered to be alphanumeric, and the
VALUE
literal must be alphanumeric. - When a group-item contains a Format 1
VALUE
clause, anyVALUE
statements on any of The subordinate data items will be ignored.
Code Sample:
IDENTIFICATION DIVISION.
PROGRAM-ID. VALUE1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
*
77 FILE-STATUS PIC XX VALUE "10".
77 WORK-HOURS PIC 99 VALUE 24.
01 SAMPLE-TABLE.
05 OCCURS 5 TIMES.
10 SAMPLE-ELEMENT PIC X VALUE "Y".
01 ADDRESS-1 VALUE "1600 PENNSYLVANIA AVE".
05 ADDR-1 PIC X(5).
05 ADDR-2 PIC X(13).
05 ADDR-3 PIC X(3).
77 DUMMY PIC X.
PROCEDURE DIVISION.
MAIN.
DISPLAY FILE-STATUS LINE 10 COL 10.
DISPLAY WORK-HOURS LINE 11 COL 10.
DISPLAY SAMPLE-ELEMENT(3) LINE 12 COL 10.
DISPLAY ADDR-2 LINE 13 COL 10.
DISPLAY "VALUE-1 FINISHED!" LINE 15 COL 10.
ACCEPT DUMMY LINE 15 COL 30.
STOP RUN.
Format 2:
The Format 2 VALUE
clause is used to define a value or range of values associated with a level-88 condition.
[ 88-LEVEL DATA-ITEM]
[ { VALUE IS } {literal-2 } ] .
{ VALUES ARE } { literal-3 [ {THRU } literal-4 ] } ...
{THROUGH}
[ WHEN SET TO FALSE literal-5 ]
Syntax:
literal-2
is a numeric or alphanu meric literal which sets the value of the 88-level condition.
Examples:
77 file-status PIC XX.
88 end-of-file VALUE “10”.
77 starting-hour PIC 99.
88 afternoon-hours VALUES ARE 12 THRU 18.
77 decision-flag PIC X.
88 yes-decision VALUE “Y”
WHEN SET TO FALSE “N”.
Code Sample:
IDENTIFICATION DIVISION.
PROGRAM-ID. VALUE2.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
*
77 FILE-STATUS PIC XX.
88 END-OF-FILE VALUE "10".
77 STARTING-HOUR PIC 99.
88 AFTERNOON-HOURS VALUES ARE 12 THRU 18.
77 DECISION-FLAG PIC X.
88 YES-DECISION VALUE "Y"
WHEN SET TO FALSE "N".
77 DUMMY PIC X.
PROCEDURE DIVISION.
MAIN.
MOVE 13 TO STARTING-HOUR.
MOVE 10 TO FILE-STATUS.
MOVE "X" TO DECISION-FLAG.
IF END-OF-FILE
DISPLAY "END-OF-FILE" LINE 9 COL 10
END-IF.
IF AFTERNOON-HOURS
DISPLAY "AFTERNOON!" LINE 10 COL 10
END-IF.
SET YES-DECISION TO FALSE.
DISPLAY "DECISION-FLAG: " LINE 11 COL 10.
DISPLAY DECISION-FLAG LINE 11 COL 25.
General Format:
Format 1:
The Format 1 VALUE
clause is used to initialize data values when the program is initially loaded into memory.
[01-LEVEL TO 49-LEVEL, 77-LEVEL DATA-ITEM ]
[ { VALUE IS } {literal-1 } ] .
DISPLAY "VALUE2 FINISHED!" LINE 15 COL 10.
ACCEPT DUMMY LINE 15 COL 30.
STOP RUN.
General Rules:
- The
VALUE
literal assigned to a condition-name must be of the same data type as the parent data item. THRU
andTHROUGH
are synonyms.- Multiple iterations of
literal-3
may be listed, without the use of theTHRU
clause.
Example:88 EVEN-NUMBERS VALUES ARE 2,4,6,8,10.
If the parent data item is set to any of the values in this list, theIF EVEN-NUMBERS
condition test would test true. - When the
literal-3 THRU literal-4
clause is used, the following rules are used to determine what values are included in theTHRU
statement:Literal-3
is a numeric or alphanumeric literal, and sets the low end of the range.Literal-4
is a numeric or alphanumeric literal, and sets the high end of the range. - If
literal-3
is numeric,literal-4
must be numeric. Ifliteral-3
is alphanumeric,literal-4
must be alphanumeric. In each case,literal-4
must have a value greater thanliteral-3
, as determined by the standard collating sequence. - The
WHEN SET TO FALSE
clause causesliteral-5
to be moved to the parent data item when theSET
statement is used to set the condition name toFALSE
.
Format 3:
The Format 3 VALUE
clause is used to set the value of a level-78 constant.
[ 78-LEVEL DATA-ITEM]
[ { VALUE IS } {literal-6 } ] .
Syntax:
literal-6
is a numeric or alphanumeric literal which sets the value of the value of the constant
named by the 78-level data item.
General Rules:
The data item associated with literal-6
is a named constant. The named constant can be used interchangeably with literal-6
in the program.