Skip to content

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:

  1. Data items described as ANY LENGTH are not assigned a length at compile time.
  2. Data items described as ANY LENGTH must be described as 01-level data items in the Linkage Section , and their PICTURE 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:

  1. Data items described as BASED are not assigned storage at compile time.
  2. The ALLOCATE statement is used to allocate storage, and initialize data items described as BASED. For more information, see the ALLOCATE Statement section.
  3. The FREE statement is used to free storage assigned to data items described as BASED. For more information see the FREE Statement section.

Blank When Zero Clause

General Format:

[ BLANK WHEN ZERO ]

General Rules:

  1. The BLANK WHEN ZERO clause may only be applied to data items that are NUMERIC or NUMERIC EDITED.
  2. 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.
  3. Data items with a PICTURE category that is NUMERIC which contain the BLANK WHEN ZERO clause are considered to be NUMERIC EDITED.

EXTERNAL Clause

General Format:

[ IS EXTERNAL ]

General Rules:

  1. When a file is declared as EXTERNAL, if the file name is indicated as a variable name, in an ASSIGN DYNAMIC [file-var] clause, then file-var should be declared as EXTERNAL.
  2. Variables declared as EXTERNAL must be declared as level 01 or level 77.
  3. If [file-var] is not declared as EXTERNAL, then the default behavior of the COBOL-IT Compiler is to implicitly declare an external variable name, and assign it a name derived from the FD named in the SELECT clause.
  4. 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-var is not declared as EXTERNAL, 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 same EXTERNAL file that also have file-var fields, then changes made between the programs will not automatically be shared. If file-var is declared explicitly as EXTERNAL, then this condition does not apply.
  5. A file declared EXTERNAL shares its OPEN, and CLOSE state, READ/WRITE buffers, and file pointer state between separately compiled programs within the run unit.
  6. All programs using the file must have the same SELECT and FD declarations for the file, and the same variable describing the name of the file as EXTERNAL.
  7. The VALUE clause can be applied to fields described as EXTERNAL. When a VALUE CLAUSE is applied to a field described as EXTERNAL, the runtime looks in memory for the external symbol. If the symbol is found, having been allocated by a previous run or CALL’ing program, then the VALUE clause is ignored. If the symbol is not found, then the runtime allocates the variable, and fills the allocation with the VALUE clause. In summary, the VALUE clause can only be applied in the first program allocating the field. When applied in programs other than the first program allocating the field, the VALUE clause is ignored .
  8. The -ffile-auto-external compiler flag affects the way that the compiler treats variables describing file names for files described as EXTERNAL.

Global Clause

General Format:

[ IS GLOBAL ]

General Rules:

  1. 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.
  2. The GLOBAL clause may only be used with data items having an 01 data level.
  3. 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:

  1. JUST and JUSTIFIED are synonyms.
  2. The JUSTIFIED clause can only be applied at the elementary data item level.
  3. The JUSTIFIED RIGHT clause can only be used on ALPHABETIC and ALPHANUMERIC data items.
  4. 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.
  5. The JUSTIFIED clause is not applied to the initial settings of variables with the VALUE 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:

  1. integer is a positive integer describing the size of the table.
  2. int-1 is an integer describing the minimum number of occurrences.
  3. int-2 is an integer describing the maximum number of occurrences. int-2 must be greater than int-1.
  4. identifier-1 is a numeric data item.
  5. key-name is a data name contained within the OCCURS clause.
  6. occurs-index is an index name.

General Rules:

  1. The OCCURS clause describes the number of occurrences in a table.
  2. A fixed length table is described with the OCCURS integer TIMES clause.
  3. A variable length table is described with the OCCURS int-1 TO int-2 TIMES DEPENDING ON identifier-1 clause.
  4. 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 by int-1, and less than or equal the maximum number of occurrences described by int-2.
  5. 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, and INDEX clauses allows for the use of the SEARCH ALL statement on the contents of the table.
  6. 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 on key-name in ASCENDING order.
  7. 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 on key-name in DESCENDING order.
  8. When multiple instances of ASCENDING KEY and DESCENDING 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.
  9. The data item referenced in the INDEXED BY index clause is a data name described as USAGE INDEX. For more information about USAGE INDEX data items , see the USAGE clause section.
  10. The elements subordinate to the OCCURS clause must be referred to in the program with subscripts.
  11. 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 the default.conf file, as follows:
    top-level-occurs-clause: ok

Picture Clause

General Format:

       [ {PICTURE} IS picture-string ] 
         {PIC }

Syntax:

  1. picture-string uses symbols, with notations to indicate repeat symbols, to describe the characteristics of each of the character positions of a data item.
  2. 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 with USAGE 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 and MOVEs 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 an OCCURS 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 the initialize-filler:yes compiler configuration flag, and as indicated by the VALUE clause.
    As an example, the FILLER in the group ALL-FLAGS below is initialized to B”1” when initialize-filler:yes is set in the compiler configuration file:
       01 ALL-FLAGS.
              03 FILLER PIC 1 BIT
                     88 ALL-DONE VALUE B1 FALSE B0.
       
       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 the SIGN 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 the PICTURE 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 the PICTURE 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 the CURRENCY clause in the SPECIAL-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 a PICTURE 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 the JUSTIFIED 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:

  1. The data item that REDEFINES identifier-1 must immediately follow identifier-1.
  2. The data item that REDEFINES identifier-1 must have the same level number as identifier-1 The level number may not be 66, 78, or 88.
  3. If the data item that REDEFINES identifier-1 is smaller than identifier-1, it will store data that begins with the first byte of identifier-1, and continues for its full length. The truncation is in the right most bytes of identifier-1.
  4. If the data item that REDEFINES identifier-1 is larger than identifier-1, there is potential for a memory access violation as the memory that is defined is only as long as identifier-1.
  5. The data item that REDEFINES identifier-1 may not contain any VALUE clauses, other than those contained in level-88 condition statements.

RENAMES Clause

General Format:

       [ RENAMES identifier-1 [ {THRU   } identifier-2 ] . 
                                {THROUGH}

Syntax:

  1. identifier-1 is a data element.
  2. identifier-2 is a data element declared after identifier-1. All data elements between identifier-1 and identifier-2 are grouped together under the original data descriptor in the clause.

General Rules:

  1. The RENAMES clause is only used with level-66 data items.
  2. 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.
  3. The data item that RENAMES identifier-1 (thru identifier-2) must immediately follow identifier-1 (thru identifier-2).
  4. None of the data items in the renamed data item(s) may have variable length.
  5. When the THRU clause is used, the level-66 data item provides a new name for all contiguous data storage beginning at identifier-1, up to and including identifier-2. Identifier-2 must be declared after identifier-1.
  6. 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 from identifier-1 through identifier-2.
  7. THRU and THROUGH 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:

  1. The SIGN clause is only used with numeric data items that have a USAGE DISPLAY.
  2. 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.
  3. If an elementary item within that group contains its own SIGN clause that is different than the SIGN clause of the group item, the SIGN clause of the elementary data item takes precedence over the SIGN clause of the group item.
  4. When the SEPARATE CHARACTER phrase is used, the positive sign is stored as a “+” character, and the negative sign is stored as a “-“ character.
  5. When the SEPARATE CHARACTER phrase is not used, the negative SIGN is encoded, according to whether LEADING or TRAILING 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:

  1. SYNC and SYNCHRONIZED are synonyms.
  2. When a data item is SYNCHRONIZED, it cannot share any unused space within its natural boundaries with any other data item.
  3. 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.
  4. 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:

  1. 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 the USAGE clause.
  2. TYPEDEF declarations cannot store data.
  3. 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.
  4. Subordinate data names must be qualified with the name of the data name using the USAGE [typedef] clause.
  5. A data item with USAGE [ TYPEDEF ] may be the subject of an OCCURS.
    For example:
    05 cust-data usage customer-info occurs 1000 times.
  6. TYPEDEFs have GLOBAL 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:

  1. If no USAGE clause is declared, then USAGE DISPLAY is implied.
  2. If a USAGE clause is declared or implied on a group level data item, all subordinate data names inherit the USAGE clause declaration.
  3. 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:

  1. USAGE PACKED DECIMAL, USAGE COMP-3, and USAGE COMPUTATIONAL-3 are synonyms.
  2. COMP-3/PACKED DECIMAL data allocates 4 bits per “9” in the PICTURE clause, plus a trailing 4 bits for the sign. To calculate the size of a COMP-3/PACKED DECIMAL data item, add 1 (for the sign) to the number of 9’s in the PICTURE clause, divide by 2, and if the result is not a whole number, round it up to the next integer.
  3. The half-byte D indicates a negative sign, the half-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:

  1. The USAGE DISPLAY clause indicates that a data item is Alphabetic, Alphanumeric, Alphanumeric Edited, Numeric , Numeric Edited , or National.
  2. If no USAGE clause is declared, then USAGE 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:

  1. The USAGE INDEX clause indicates that a data item is an index is being used in table-handling functions.
  2. USAGE INDEX data allocates 32-bits in native format.
  3. USAGE INDEX data does not allow the use of the PICTURE clause.
  4. 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:

  1. Data items described with USAGE POINTER, USAGE PROCEDURE POINTER, and USAGE PROGRAM POINTER are initialized to NULL when a program is initially loaded into memory.
  2. Data items described with USAGE POINTER, USAGE PROCEDURE POINTER, and USAGE 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.
  3. Data items described with USAGE POINTER, USAGE PROCEDURE POINTER, and USAGE PROGRAM POINTER may be assigned a data address through the use of the ALLOCATE, or SET statement, and that memory may be released through the use of the FREE 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".
  4. The USAGE POINTER clause indicates that a data item is a data pointer, which can hold the address of a data item .
  5. The USAGE PROGRAM-POINTER clause indicates that a data item is program pointer, which can hold the address of a program.
  6. The program name from which the PROGRAM-POINTER is derived may be either the PROGRAM-ID of a program, or the entry-name of an ENTRY statement.
  7. The USAGE PROCEDURE-POINTER clause indicates that a data item is procedure pointer, which can hold the address of a procedure
  8. The procedure name from which the PROCEDURE-POINTER is derived is the entry-name of an ENTRY statement.
  9. USAGE POINTER, PROGRAM-POINTER, and PROCEDURE-POINTER do not allow the use of the PICTURE 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:

  1. Data items with USAGE BINARY-C-LONG are initialized to NULL when the program is loaded in memory.
  2. 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.
  3. BINARY-C-LONG data does not allow the use of the PICTURE clause.
  4. BINARY-C-LONG data may be described as SIGNED or UNSIGNED.
  5. BINARY-C-LONG UNSIGNED data does not support negative values.
  6. BINARY-C-LONG data has the SIGNED 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:

  1. Data items with USAGE BINARY-CHAR are initialized to NULL when the program is loaded in memory.
  2. BINARY-CHAR data designates a single byte using the native storage format.
  3. BINARY-CHAR data does not allow the use of the PICTURE clause.
  4. BINARY-CHAR data may be described as SIGNED or UNSIGNED.
  5. BINARY-CHAR UNSIGNED data does not support negative values.
  6. BINARY-CHAR data has the SIGNED 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:

  1. Data items with USAGE BINARY-DOUBLE are initialized to NULL when the program is loaded in memory.
  2. BINARY-DOUBLE data allocates a “traditional” double word of storage (64-bits) using the native storage format.
  3. BINARY-DOUBLE data does not allow the use of the PICTURE clause.
  4. BINARY-DOUBLE data may be described as SIGNED or UNSIGNED.
  5. BINARY-DOUBLE UNSIGNED data does not support negative values.
  6. BINARY-DOUBLE data has the SIGNED 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:

  1. Data items with USAGE BINARY-LONG are initialized to NULL when the program is loaded in memory.
  2. BINARY-LONG data allocates 32-bits of storage using the native storage format.
  3. BINARY-LONG data does not allow the use of the PICTURE clause.
  4. BINARY-LONG data may be described as SIGNED or UNSIGNED.
  5. BINARY-LONG UNSIGNED data does not support negative values.
  6. BINARY-LONG data has the SIGNED 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:

  1. Data items with USAGE BINARY-SHORT are initialized to NULL when the program is loaded in memory.
  2. BINARY-SHORT data allocates 16-bits of storage using the native storage format.
  3. BINARY-SHORT data does not allow the use of the PICTURE clause.
  4. BINARY-SHORT data may be described as SIGNED or UNSIGNED.
  5. BINARY-SHORT UNSIGNED data does not support negative values.
  6. BINARY-SHORT data has the SIGNED attribute by default.

USAGE BIT

General Rules:

  1. USAGE BIT allocates a field as a bit field.
  2. PIC 1(n) is the only picture allowed.
  3. USAGE BIT may not redefine or be redefined.
  4. Consecutive USAGE BIT fields are packed into the same byte area with a maximum size of 8 bytes (64-Bits).
  5. 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.
  6. 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:

  1. USAGE COMPUTATIONAL 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 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:

  1. USAGE COMPUTATIONAL-1 and USAGE COMP-1 are synonyms.
  2. COMP-1 data allocates 32 bits of data, formatted as single precision floating point.
  3. COMP-1 data does not allow the use of the PICTURE clause.
  4. 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:

  1. USAGE COMPUTATIONAL-2 and USAGE COMP-2 are synonyms.
  2. COMP-2 data allocates 64-bits of data, formatted as double precision floating point. COMP-2 data does not allow the use of the PICTURE 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:

  1. USAGE PACKED-DECIMAL, USAGE COMP-3, and USAGE COMPUTATIONAL-3 are synonyms.
  2. 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.
  3. The half-byte D indicates a negative sign, the half-byte C indicates a positive sign.
  4. To calculate the SIZE of a USAGE 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:

  1. Data items with USAGE COMPUTATIONAL are initialized to xxxx when the program is loaded in memory.
  2. USAGE COMPUTATIONAL-4 and USAGE COMP-4 are synonyms.
  3. COMP-4 data is sized according to the number of 9’s in the PICTURE clause, and the setting of the binary-size compiler configuration flag or the setting of the pack-comp-4 compiler configuration flag. If pack-comp-4 is set to No (the default), thenCOMP-4 data follows the same rules as COMPUTATIONAL data with regards to sizing. If pack-comp-4 is set to Yes, then a binary-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:

  1. USAGE COMPUTATIONAL-5 and USAGE COMP-5 are synonyms.
  2. COMP-5 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.
  3. 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:

  1. USAGE COMPUTATIONAL-6 and USAGE COMP-6 are synonyms.
  2. COMP-6 data allocates 4 bits per “9” in the PICTURE clause. To calculate the size of a COMP-6 data item, divide the number of 9’s in the PICTURE 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:

  1. COMP-X data is sized according to the number of 9’s or the number of X’s in the PICTURE clause.
  2. 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 the PICTURE clause.
  3. When the PICTURE clause consists of X’s, one byte is assigned per X in the PICTURE 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:

  1. USAGE FLOAT-SHORT is equivalent to USAGE COMP-1.
  2. USAGE FLOAT-LONG is equivalent to USAGE COMP-2.

The C Data Types

  1. The C data types are SIGNED SHORT, UNSIGNED SHORT, SIGNED INT, UNSIGNED INT, SIGNED LONG, and UNSIGNED LONG. They correspond to the C data types “short”, “int”, and “long”.
  2. 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:

  1. SIGNED-SHORT and UNSIGNED-SHORT data allocate 16-bits of storage using the native storage format.
  2. SIGNED-INT and UNSIGNED-INT data allocate 32-bits of storage using the native storage format.
  3. SIGNED-LONG and UNSIGNED-LONG data allocate 64-bits of storage using the native storage format.
  4. UNSIGNED-SHORT, UNSIGNED-LONG and UNSIGNED-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 ZABCDEFG.
       77 current-year             PIC 9(4) VALUE 2011.

General Rules:

  1. Format 1 VALUE declarations are ignored in the FILE SECTION and LINKAGE SECTION.
  2. 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.
  3. If the parent data-item is numeric, literal-1 must be numeric. If the parent data item is alphanumeric, literal-1 must be alphanumeric.
  4. The VALUE declaration may not be applied to a data item with a variable size. In a data item that is subordinate to an OCCURS clause, the VALUE clause is applied to every instance of the `OCCURS.
  5. When applied to a group item, the parent date item is considered to be alphanumeric, and the VALUE literal must be alphanumeric.
  6. When a group-item contains a Format 1 VALUE clause, any VALUE 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:

  1. 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:

  1. The VALUE literal assigned to a condition-name must be of the same data type as the parent data item.
  2. THRU and THROUGH are synonyms.
  3. Multiple iterations of literal-3 may be listed, without the use of the THRU 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, the IF EVEN-NUMBERS condition test would test true.
  4. When the literal-3 THRU literal-4 clause is used, the following rules are used to determine what values are included in the THRU 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.
  5. If literal-3 is numeric, literal-4 must be numeric. If literal-3 is alphanumeric, literal-4 must be alphanumeric. In each case, literal-4 must have a value greater than literal-3, as determined by the standard collating sequence.
  6. The WHEN SET TO FALSE clause causes literal-5 to be moved to the parent data item when the SET statement is used to set the condition name to FALSE.

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.

Back to top