The VALUE clause defines the value of constants, the initial value of working storage and local storage items, and the values
associated with a condition name.
General Formats for Format 1
General Formats for Format 2
General Formats for Format 3
General Formats for Format 4
Syntax Rules for All Formats
- If a signed numeric literal is specified, the subject of the entry must be a signed numeric data item.
- If the category of the subject of the entry is numeric, all literals in the VALUE clause must be numeric and have a value
that is within the range of values indicated by the PICTURE clause or the USAGE clause. If the usage is other than float-short
or float-long this value must not require truncation of non-zero digits. This value must have the digit zero in each position
that corresponds to a picture character symbol 'P'.
- If the item is of class alphabetic or alphanumeric, literals in the VALUE clause must be alphanumeric literals. Alphanumeric
literals in the VALUE clause of an elementary item must not exceed the size indicated by an explicit PICTURE clause. Alphanumeric
literals in the VALUE clause of an alphanumeric group item must not exceed the size of the group item.
- If the item is of class national, literals in the VALUE clause must be national literals. National literals in the VALUE clause
of an elementary item must not exceed the size indicated by an explicit PICTURE clause. National literals in the VALUE clause
of a national group item must not exceed the size of the group item.
Syntax Rules for Formats 1 and 4
- The VALUE clause must not be specified in a data description entry that contains a REDEFINES clause or in an entry that is
subordinate to an entry containing a REDEFINES clause.
- If the VALUE clause is specified at the group level, the literal must be of the same category as the group item or must be
a figurative constant that is permitted in a MOVE statement to a receiving item of that category. The VALUE clause cannot
be specified at subordinate levels within this group.
- If a VALUE clause is specified at the group level, subordinate items within that group must not be described with a JUSTIFIED
or SYNCHRONIZED clause, and all data items subordinate to an alphanumeric group item must be explicitly or implicitly described
with USAGE DISPLAY.
Syntax Rules for Format 3
- All identifiers must have been defined before the declaration of the level 78 item. If either identifier-1 or identifier-3
(LENGTH parameters) is a group item, the definition of that group must have been completed before the level 78 declaration,
by the appearance of another data item at the same or lower level number.
Syntax Rules for Format 4
- In Format 4 (level 78) the VALUE clause may be omitted if the item is specified in an ENUM definition.
- A data description entry that contains the VALUE clause must contain an OCCURS clause or be subordinate to a data description
entry that contains an OCCURS clause.
- Subscript-1 and subscript-2 must be integer numeric literals.
- In one FROM phrase, there must be one subscript-1 specified for each OCCURS clause for the subject of the entry or superordinate
to that entry, specified in the same order as a subscripted reference to the subject of the entry would be specified. Each
instance of subscript-1 must not exceed the maximum number of occurrences specified in the OCCURS clause associated with that
instance.
- If the TO phrase is specified, there must be one subscript-2 specified for each OCCURS clause for the subject of the entry
or superordinate to that entry, specified in the same order as a subscripted reference to the subject of the entry would be
specified. Each instance of subscript-2 must not exceed the maximum number of occurrences specified in the OCCURS clause associated
with that instance. The specification of subscript-2 in one TO phrase must be such that the table element associated with
subscript-2 is the same occurrence or a successive occurrence of the table element associated with the corresponding subscript-1.
Syntax Rules for Format 5
- Format 5 must be used only in conjunction with USAGE CONDITION-VALUE.
General Rules for Formats 1, 2 and 4
- The VALUE clause must not conflict with other clauses in the data description of the item or in the data description within
the hierarchy of the item. The following rules apply:
- If the literal defines the value of a data item, the literal is aligned in the data item according to the standard alignment
rules. (See the topic
Standard Alignment Rules in the chapter
Concepts of the COBOL Language.)
- If the category of the item is alphabetic, alphanumeric, alphanumeric edited or numeric edited all literals in the VALUE clause
must be nonnumeric. The literal is aligned in the data item as if the data item had been described as alphanumeric. (See the
topic
Standard Alignment Rules in the chapter
Concepts of the COBOL Language.) Editing characters in the PICTURE clause are included in determining the size of the data item (see the topic
The PICTURE Clause) but have no effect on initialization of the data item. Therefore, the programmer is responsible for specifying the value
of a literal associated with an edited data item in edited form.
If the item is numeric edited, the value can be a numeric literal or a nonnumeric literal. If the value is a numeric literal,
the value contained in the item will be the same as if the numeric literal were moved to the numeric edited item.
- Initialization takes place independent of any BLANK WHEN ZERO or JUSTIFIED clause that can be specified.
General Rules for Data-Item (Format 1)
- Rules governing the use of the VALUE clause in data item entries differ with the respective sections of the Data Division:
- In the Working-Storage Section
and Local-Storage Section,
the VALUE clause can be used to specify the initial value of a data item, in which case the clause causes the item to assume
the specified value at the time the runtime element is placed into its initial state. If the VALUE clause is not used in an
item's description, the initial value of that data item is undefined.
- In the File Section and the Linkage Section,
and Local-Storage Section,
the VALUE clause can be used in data item entries, but it takes effect only when an INITIALIZE statement that applies to the
entries is executed.
-
- If the VALUE clause is specified in an entry at the group level the group area is initialized without consideration for the
individual elementary or group items contained within this group.
- The figurative constant NULL can be specified in the VALUE clause only if the data item is defined with USAGE POINTER or
USAGE PROCEDURE-POINTER. This is the only value you can specify in the VALUE clause for such an item. The effect is to set
the pointer in such a way that it is guaranteed not to point to any data item.
- A VALUE clause specified in a data description entry that contains an OCCURS clause, or in an entry that is subordinate to
an OCCURS clause, causes every occurrence of the associated data item to be assigned the specified value.
- If a VALUE clause is specified in a data description entry of a data item which is associated with a variable occurrence data
item, the initialization of the data item behaves as if the value of the data item referenced by the DEPENDING ON phrase in
the OCCURS clause specified for the variable occurrence data item is set to the maximum number of occurrences as specified
by that OCCURS clause. A data item is associated with a variable occurrence data item in any of the following cases:
- It is a group data item which contains a variable occurrence data item.
- It is a variable occurrence data item.
- It is a data item that is subordinate to a variable occurrence data item.
If a VALUE clause is associated with the data item referenced by a DEPENDING ON phrase, that value is considered to be placed
in the data item after the variable occurrence data item is initialized.
- A data item of class object is initialized to null. The initial value takes effect when VALUE clauses take effect and when
storage for the data item is allocated.
- A data item of class pointer is initialized to null. The initial value takes effect when VALUE clauses take effect and when
storage for the data item is allocated.
Condition-name Rules (Format 2)
- In a condition-name entry, the VALUE clause is required. The VALUE clause and the condition-name itself are the only two
clauses permitted in the entry. The characteristics of a condition-name are implicitly those of its conditional variable.
- Format 2 can be used only in connection with condition-names. Wherever the THRU phrase is used, literal-2 must be less than
literal-3.
- The FALSE phrase is meaningful only if the associated condition-name is referenced in a SET condition-name TO FALSE statement.
(See the topic
The SET Statement.)
Constant-Name Rules (Format 3)
- Constant-expression-1 has the following format:
- Format 3 can be used only in a constant-name entry.
- If literal-5 is specified and not followed by an operator, the characteristic of the constant-name is that of literal-5. Otherwise,
the characteristic of the constant-name is that of an integer.
- Any number of arithmetic or logical operators can be used. The result is evaluated using integer arithmetic in strict left
to right order unless parentheses are used. A parenthesized expression is evaluated in strict left to right order before its
use in the overall expression. That is, all operators other than parentheses have the same precedence in a constant-expression.
The expression result is computed in 64-bits. (When the DIALECT"RM" directive is in effect, the expression result is computed
in 32-bits.) If any intermediate result is less than zero, the final value is undefined. A constant-name may be used in place
of integer-1.
- The logical operations AND, OR, EXCLUSIVE OR and NOT act on the binary representation in a bit-wise manner.
- LENGTH of identifier-1 or identifier-3 is the size of the storage allocated for identifier-1 or identifier-3, respectively.
If the identifier is a group item, the length includes all subordinate data items. SIZE can also be used as a synonym of LENGTH
in a constant-expression.
- If literal-1 or literal-2 is a figurative constant, LENGTH OF is calculated as 1.
- If literal-1 or literal-2 is a numeric literal other than a floating point literal, LENGTH OF is the result of the number
of digits in the numeric literal, including leading zeroes; the sign and decimal point are not counted, if specified. If literal-1
or literal-2 is a floating point numeric literal, LENGTH OF is the result of a sign character (whether specified or not),
the digits of the mantissa and exponent (excluding leading zeroes), the decimal point, the "E" or "e" character, and the exponent
sign (whether specified or not).
- The value returned by NEXT is the offset at which the next byte of storage occurs after the previous data declaration. (It
is not the offset of the start of the next data declaration.) If that data declaration was of a table defined with an OCCURS
clause, the value returned by NEXT is the offset at which the next byte of storage occurs after the first element of the table.
- START of identifier-2 or identifier-4 is the offset at which identifier-2 or identifier-4, respectively, begins.
- For rules 21 and 22, the offset is defined as follows:
- If the identifier is part of an EXTERNAL record or a LINKAGE record, the offset is calculated from the start of the associated
01-level;
- If the identifier is defined in the Local-Storage Section, the offset is calculated from the start of the Local-Storage Section;
- Otherwise the offset is calculated from the start of the Data Division.
- Offsets are not portable across different COBOL implementations and no reliance should be placed on particular values outside
this compilation unit.
- DATE-COMPILED gives the integer value representing the date the compilation started as YYYYMMDD, where YYYY is the year,
MM is the month of the year, and DD is the day of the month.
Table Rules (Format 4)
- A format 2 VALUE clause initializes a table element to the value of literal-6. The table element initialized is identified
by subscript-1. Consecutive table elements are initialized, in turn, to the value of successive occurrences of literal-6.
Consecutive table elements are referenced by incrementing by 1 the subscript that represents the least inclusive dimension
of the table. When any reference to a subscript, prior to incrementing it, is equal to the maximum number of occurrences specified
by its corresponding OCCURS clause, that subscript is set to 1 and the subscript for the next most inclusive dimension of
the table is incremented by 1.
- If the TO phrase is specified, all occurrences of literal-6 are reused, in the order specified, as a source during the initialization
described in the immediately preceding rule. This repetition is done until the table element identified by subscript-2 is
initialized.
- If the TO phrase is not specified, it is as if the TO phrase were specified with each subscript-2 as the maximum number of
occurrences of the table associated with each corresponding subscript-1.
- If multiple specifications of the FROM phrase reference the same table element, the value defined by the last specified FROM
phrase in the VALUE clause is assigned to the table element.
Format 5
- If the TRUE phrase is specified, the associated condition-value data item is set to true. If the FALSE phrase is specified,
the associated condition-value data item is set to false.
Examples
- An example of using the NEXT phrase of the VALUE clause is provided in the section
NEXT Phrase of CONSTANT-NAMES.