In this topic, we described about the below sections -
Specifies the initial values of a data item or the values associated with a condition-name. A VALUE clause used for other than a condition-name entry in the file section or the linkage section, is syntax checked and has no effect on the execution of the program.
VALUE clause has in effect if used in the working-storage section. The data item or condition-name assumes the specified value at the beginning of program execution.
If the initial value is not specified, the value is unpredictable. Values provided in VALUE clause should not be exceeded the length of PICTURE clause. Value clause initializes the data item to the value of literal.
VALUE clause should not be used in data descriptive entries like REDEFINES. VALUE clause should not be used with the group/elementary items declared with JUSTIFIED or SYNCHRONIZED. VALUE clause has two different formats to initialize the items -
- literal value
- condition-name value
Literal value -
Specifies the initial value of a data item. Initialization is independent of any BLANK WHEN ZERO or JUSTIFIED clause. VALUE clause can be specified for an elementary data item or for a group item.
VALUE clause specified for the declaration that contains or is subordinate to an OCCURS clause causes every occurrence of the associated data item to be assigned the specified value.
The editing characters functions in a PICTURE clause are ignored in determining the initial value of the item. However, editing characters are included in determining the size of the item.
For example, if the item is defined as PICTURE +9999.99 and the value is +12.34, then the VALUE clause should be specified with "+0012.34". The VALUE clause must not be specified for the declaration that contains either an EXTERNAL or a REDEFINES clause. This rule does not apply to condition-name entries.
VALUE clause must not be specified for group items, if any subordinate entries contain a JUSTIFIED or SYNCHRONIZED clause. A VALUE clause cannot be specified for external floating-point items. A data item cannot contain a VALUE clause if the prior data item contains an OCCURS clause with the DEPENDING ON phrase.
Rules for literal values -
- A figurative constant can be substituted wherever a literal is specified.
- If the item is numeric, the VALUE clause literal must be numeric.
- If the VALUE clause is specified for an elementary alphabetic, alphanumeric, alphanumeric-edited or numeric-edited item described with usage DISPLAY, the VALUE clause literal must be an alphanumeric literal or a figurative constant.
- If the VALUE clause is specified at the group level for an alphanumeric group, the literal must be an alphanumeric literal or a figurative constant.
- A VALUE clause associated with a COMPUTATIONAL-1 or COMPUTATIONAL-2 items must specify a floating-point literal. In addition, the figurative constant ZERO and both integer and decimal forms of the zero literal can be specified in a floating-point VALUE clause.
condition-name value -
This format associates condition-name with a value, values or range of values. Each condition-name requires a separate level-88 entry. The keywords THROUGH and THRU are equivalent.
A user-specified name that associates with a value. If the conditional variable requires subscripts or indexes, each condition-name must be subscripted or indexed as required for the conditional variable.
Associates the condition-name with a single value.
literal-1 THROUGH literal-2
Associates the condition-name with at least one range of values. If the THROUGH phrase is specified, literal-1 must be less than literal-2.
literal-1, literal-2, ...literal-n
Associates the condition-name with a set of values. If multiple values specified, the values can be in any order.
Below example shows the usage of VALUE clause in COBOL program.