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 LENGTHare not assigned a length at compile time. - Data items described as
ANY LENGTHmust be described as 01-level data items in theLinkageSection , and theirPICTUREclause 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
BASEDare not assigned storage at compile time. - The
ALLOCATEstatement is used to allocate storage, and initialize data items described asBASED. For more information, see the ALLOCATE Statement section. - The
FREEstatement 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 ZEROclause may only be applied to data items that areNUMERICorNUMERIC EDITED. - The effect of the
BLANK WHEN ZEROclause is to store spaces in the data item when the value of the data item is zero. - Data items with a
PICTUREcategory that isNUMERICwhich contain theBLANK WHEN ZEROclause 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-varshould be declared asEXTERNAL. - Variables declared as
EXTERNALmust 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 theFDnamed in theSELECTclause. - The convention used is as follows:
Consider the statement:SELECT myfile ASSIGN DYNAMIC file-var...…77 file-varpic x(8) value “customer”.
In this case,file-varis 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 sameEXTERNALfile that also havefile-varfields, then changes made between the programs will not automatically be shared. Iffile-varis declared explicitly asEXTERNAL, then this condition does not apply. - A file declared
EXTERNALshares itsOPEN, andCLOSEstate,READ/WRITEbuffers, and file pointer state between separately compiled programs within the run unit. - All programs using the file must have the same
SELECTandFDdeclarations for the file, and the same variable describing the name of the file asEXTERNAL. - The
VALUEclause can be applied to fields described asEXTERNAL. When aVALUE CLAUSEis 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 theVALUEclause is ignored. If the symbol is not found, then the runtime allocates the variable, and fills the allocation with theVALUEclause. In summary, theVALUEclause can only be applied in the first program allocating the field. When applied in programs other than the first program allocating the field, theVALUEclause is ignored . - The
-ffile-auto-externalcompiler 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
GLOBALclause 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
GLOBALclause may only be used with data items having an 01 data level. - The
GLOBALclause 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:
JUSTandJUSTIFIEDare synonyms.- The
JUSTIFIEDclause can only be applied at the elementary data item level. - The
JUSTIFIED RIGHTclause can only be used onALPHABETICandALPHANUMERICdata items. - The
JUSTIFIEDclause 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
JUSTIFIEDclause is not applied to the initial settings of variables with theVALUEclause.
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:
integeris a positive integer describing the size of the table.int-1is an integer describing the minimum number of occurrences.int-2is an integer describing the maximum number of occurrences.int-2must be greater thanint-1.identifier-1is a numeric data item.key-nameis a data name contained within theOCCURSclause.occurs-indexis an index name.
General Rules:
- The
OCCURSclause describes the number of occurrences in a table. - A fixed length table is described with the
OCCURS integer TIMESclause. - A variable length table is described with the
OCCURS int-1 TO int-2 TIMES DEPENDING ON identifier-1clause. - When describing a variable length table, with the number of occurrences
DEPENDING ON identifier-1,identifier-1must 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, andINDEXclauses allows for the use of theSEARCH ALLstatement on the contents of the table. - When using the
ASCENDING KEY IS key-nameclause , key name must be a data item described in the table, and the data in the table must be sorted onkey-nameinASCENDINGorder. - When using the
DESCENDING KEY IS key-nameclause ,key-namemust be a data item described in the table, and the data in the table must be sorted onkey-nameinDESCENDINGorder. - When multiple instances of
ASCENDING KEYandDESCENDING KEYare 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 indexclause is a data name described asUSAGE INDEX. For more information aboutUSAGE INDEXdata items , see the USAGE clause section. - The elements subordinate to the
OCCURSclause must be referred to in the program with subscripts. - The default behaviour of the compiler is to require that phrases with
OCCURSclause not be used at the 01-level. To alter this behaviour, modify thedefault.conffile, as follows:top-level-occurs-clause: ok
Picture Clause
General Format:
[ {PICTURE} IS picture-string ]
{PIC }
Syntax:
picture-stringuses 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 1may be used withUSAGE DISPLAY,COMP,COMP-5,COMP-X,BIT.- When used with
USAGE COMP,COMP-5,COMP-Xthe 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 1field will display the bits, for example, “000101”. PIC 1fields are numeric and may be used in computations andMOVEs for their integer value.- Literary binary constants are now supported, for example
VALUE B’1011’. - Data items described as
PIC 1 USAGE BITare allowed to have anOCCURSclause. For example:05 element-1 PIC 1 USAGE BIT OCCURS 10000. - Data described as
USAGE BITmay be initialized at program startup, as indicated by theinitialize-filler:yescompiler configuration flag, and as indicated by theVALUEclause.
As an example, theFILLERin the groupALL-FLAGSbelow is initialized toB”1”wheninitialize-filler:yesis 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
USAGEcases, 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 SEPARATEclause is present. - For other
USAGEcases, 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 thePICTUREstring. - “
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 thePICTUREstring. - “
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 theCURRENCYclause in theSPECIAL-NAMESparagraph. - “
$” 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 9PPrepresents a number that is stored internally as a single digit (0-9), but represents the numbers 000, 100, 200, … 900.
Similarly,PIC PP9represents 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 aPICTUREstring. - 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
MOVEto 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
JUSTIFIEDclause. Alignment rules for theJUSTIFIEDclause 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
REDEFINESidentifier-1must immediately followidentifier-1. - The data item that
REDEFINESidentifier-1must have the same level number asidentifier-1The level number may not be 66, 78, or 88. - If the data item that
REDEFINESidentifier-1is 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
REDEFINESidentifier-1is 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
REDEFINESidentifier-1may not contain anyVALUEclauses, other than those contained in level-88 condition statements.
RENAMES Clause
General Format:
[ RENAMES identifier-1 [ {THRU } identifier-2 ] .
{THROUGH}
Syntax:
identifier-1is a data element.identifier-2is a data element declared afteridentifier-1. All data elements betweenidentifier-1andidentifier-2are grouped together under the original data descriptor in the clause.
General Rules:
- The
RENAMESclause 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
RENAMESidentifier-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
THRUclause 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-2must be declared afteridentifier-1. - When the
THRUclause is used, the level-66 data item is treated as a group item that contains all of the contiguous data elements fromidentifier-1throughidentifier-2. THRUandTHROUGHare 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
SIGNclause is only used with numeric data items that have aUSAGE DISPLAY. - A
SIGNclause 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
SIGNclause that is different than theSIGNclause of the group item, theSIGNclause of the elementary data item takes precedence over theSIGNclause of the group item. - When the
SEPARATE CHARACTERphrase is used, the positive sign is stored as a “+” character, and the negative sign is stored as a “-“ character. - When the
SEPARATE CHARACTERphrase is not used, the negativeSIGNis encoded, according to whetherLEADINGorTRAILINGis 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:
SYNCandSYNCHRONIZEDare synonyms.- When a data item is
SYNCHRONIZED, it cannot share any unused space within its natural boundaries with any other data item. SYNCHRONIZED LEFTcauses 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 RIGHTcauses 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
TYPEDEFclause indicates that the data description is a typedef declaration, and not a variable declaration. The data name can then be used with theUSAGEclause. TYPEDEFdeclarations cannot store data.- If the data description with the
TYPEDEFclause 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. TYPEDEFs haveGLOBALscope by default. This behaviour may be changed by use of the-fno-global-typedefcompiler 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
USAGEclause is declared, thenUSAGE DISPLAYis implied. - If a
USAGEclause is declared or implied on a group level data item, all subordinate data names inherit theUSAGEclause declaration. - For General Specifications of all of the
USAGEtypes, 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-3are synonyms.COMP-3/PACKED DECIMALdata allocates 4 bits per “9” in thePICTUREclause, plus a trailing 4 bits for the sign. To calculate the size of aCOMP-3/PACKED DECIMALdata item, add 1 (for the sign) to the number of 9’s in thePICTUREclause, divide by 2, and if the result is not a whole number, round it up to the next integer.- The
half-byte Dindicates a negative sign, thehalf-byte Cindicates 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 DISPLAYclause indicates that a data item is Alphabetic, Alphanumeric, Alphanumeric Edited, Numeric , Numeric Edited , or National. - If no
USAGEclause is declared, thenUSAGE DISPLAYis 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 INDEXclause indicates that a data item is an index is being used in table-handling functions. USAGE INDEXdata allocates 32-bits in native format.USAGE INDEXdata does not allow the use of thePICTUREclause.USAGE INDEXdata 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 POINTERare initialized toNULLwhen a program is initially loaded into memory. - Data items described with
USAGE POINTER,USAGE PROCEDURE POINTER, andUSAGE PROGRAM POINTERhold 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 POINTERmay be assigned a data address through the use of theALLOCATE, orSETstatement, and that memory may be released through the use of theFREEstatement.
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 POINTERclause indicates that a data item is a data pointer, which can hold the address of a data item . - The
USAGE PROGRAM-POINTERclause indicates that a data item is program pointer, which can hold the address of a program. - The program name from which the
PROGRAM-POINTERis derived may be either thePROGRAM-IDof a program, or the entry-name of anENTRYstatement. - The
USAGE PROCEDURE-POINTERclause indicates that a data item is procedure pointer, which can hold the address of a procedure - The procedure name from which the
PROCEDURE-POINTERis derived is the entry-name of anENTRYstatement. USAGE POINTER,PROGRAM-POINTER, andPROCEDURE-POINTERdo not allow the use of thePICTUREclause.
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-LONGare initialized toNULLwhen the program is loaded in memory. BINARY-C-LONGdata 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-LONGdata does not allow the use of thePICTUREclause.BINARY-C-LONGdata may be described asSIGNEDorUNSIGNED.BINARY-C-LONG UNSIGNEDdata does not support negative values.BINARY-C-LONGdata has theSIGNEDattribute 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-CHARare initialized toNULLwhen the program is loaded in memory. BINARY-CHARdata designates a single byte using the native storage format.BINARY-CHARdata does not allow the use of thePICTUREclause.BINARY-CHARdata may be described asSIGNEDorUNSIGNED.BINARY-CHAR UNSIGNEDdata does not support negative values.BINARY-CHARdata has theSIGNEDattribute 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-DOUBLEare initialized toNULLwhen the program is loaded in memory. BINARY-DOUBLEdata allocates a “traditional” double word of storage (64-bits) using the native storage format.BINARY-DOUBLEdata does not allow the use of thePICTUREclause.BINARY-DOUBLEdata may be described asSIGNEDorUNSIGNED.BINARY-DOUBLE UNSIGNEDdata does not support negative values.BINARY-DOUBLEdata has theSIGNEDattribute 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-LONGare initialized toNULLwhen the program is loaded in memory. BINARY-LONGdata allocates 32-bits of storage using the native storage format.BINARY-LONGdata does not allow the use of thePICTUREclause.BINARY-LONGdata may be described asSIGNEDorUNSIGNED.BINARY-LONG UNSIGNEDdata does not support negative values.BINARY-LONGdata has theSIGNEDattribute 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-SHORTare initialized toNULLwhen the program is loaded in memory. BINARY-SHORTdata allocates 16-bits of storage using the native storage format.BINARY-SHORTdata does not allow the use of thePICTUREclause.BINARY-SHORTdata may be described asSIGNEDorUNSIGNED.BINARY-SHORT UNSIGNEDdata does not support negative values.BINARY-SHORTdata has theSIGNEDattribute by default.
USAGE BIT
General Rules:
USAGE BITallocates a field as a bit field.PIC 1(n)is the only picture allowed.USAGE BITmay not redefine or be redefined.- Consecutive
USAGE BITfields are packed into the same byte area with a maximum size of 8 bytes (64-Bits). - If a
USAGE BITfield 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 BIT03 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 COMPUTATIONAL data is sized according to the number of 9’s in thePICTUREclause, and according to the setting of thebinary-sizecompiler configuration flag. For details, see the documentation of thebinary-sizecompiler 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-1andUSAGE COMP-1are synonyms.COMP-1data allocates 32 bits of data, formatted as single precision floating point.COMP-1data does not allow the use of thePICTUREclause.COMP-1data 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-2andUSAGE COMP-2are synonyms.COMP-2data allocates 64-bits of data, formatted as double precision floating point.COMP-2data does not allow the use of thePICTUREclause.COMP-2data 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-3are synonyms.USAGE PACKED-DECIMALdata 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 Dindicates a negative sign, thehalf-byte Cindicates a positive sign. - To calculate the
SIZEof aUSAGE PACKED-DECIMALdata 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 COMPUTATIONALare initialized toxxxxwhen the program is loaded in memory. USAGE COMPUTATIONAL-4andUSAGE COMP-4are synonyms.COMP-4data is sized according to the number of 9’s in thePICTUREclause, and the setting of thebinary-sizecompiler configuration flag or the setting of thepack-comp-4compiler configuration flag. Ifpack-comp-4is set toNo(the default), thenCOMP-4data follows the same rules asCOMPUTATIONALdata with regards to sizing. Ifpack-comp-4is set toYes, then abinary-sizesetting 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-5andUSAGE COMP-5are synonyms.COMP-5data is sized according to the number of 9’s in thePICTUREclause, and according to the setting of thebinary-sizecompiler configuration flag.COMP-5data 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-6andUSAGE COMP-6are synonyms.COMP-6data allocates 4 bits per “9” in thePICTUREclause. To calculate the size of aCOMP-6data item, divide the number of 9’s in thePICTUREclause by 2, and if the result is not a whole number, round it up to the next integer.COMP-6data 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-Xdata is sized according to the number of 9’s or the number of X’s in thePICTUREclause.- When the
PICTUREclause consists of 9’s,COMP-Xdata assumes a binary-size setting of “1--8” in calculating the number of bytes that correspond to the number of 9’s in thePICTUREclause. - When the
PICTUREclause consists of X’s, one byte is assigned per X in thePICTUREclause.
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-SHORTis equivalent toUSAGE COMP-1.USAGE FLOAT-LONGis 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-SHORTandUNSIGNED-SHORTdata allocate 16-bits of storage using the native storage format.SIGNED-INTandUNSIGNED-INTdata allocate 32-bits of storage using the native storage format.SIGNED-LONGandUNSIGNED-LONGdata allocate 64-bits of storage using the native storage format.UNSIGNED-SHORT,UNSIGNED-LONGandUNSIGNED-INTdata 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
VALUEdeclarations are ignored in theFILE SECTIONandLINKAGE SECTION. - Some API calls require that strings being passed to them be null-terminated. Prefixing a string with a
Zhas the effect of null-terminating the string. - If the parent data-item is numeric,
literal-1must be numeric. If the parent data item is alphanumeric,literal-1must be alphanumeric. - The
VALUEdeclaration may not be applied to a data item with a variable size. In a data item that is subordinate to anOCCURSclause, theVALUEclause 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
VALUEliteral must be alphanumeric. - When a group-item contains a Format 1
VALUEclause, anyVALUEstatements 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-2is 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
VALUEliteral assigned to a condition-name must be of the same data type as the parent data item. THRUandTHROUGHare synonyms.- Multiple iterations of
literal-3may be listed, without the use of theTHRUclause.
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-NUMBERScondition test would test true. - When the
literal-3 THRU literal-4clause is used, the following rules are used to determine what values are included in theTHRUstatement:Literal-3is a numeric or alphanumeric literal, and sets the low end of the range.Literal-4is a numeric or alphanumeric literal, and sets the high end of the range. - If
literal-3is numeric,literal-4must be numeric. Ifliteral-3is alphanumeric,literal-4must be alphanumeric. In each case,literal-4must have a value greater thanliteral-3, as determined by the standard collating sequence. - The
WHEN SET TO FALSEclause causesliteral-5to be moved to the parent data item when theSETstatement 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.