The VALUE clause defines the initial value of Working-Storage. It also describes the values associated with conditionals.
Format 1
VALUE IS value-lit
Format 2
{VALUE IS } { low-val [ {THROUGH} high-val ] } ...
{VALUES ARE} {THRU }
[ WHEN SET TO FALSE false-val ]
Format 3
78 user-name VALUE IS {literal-1} [ {+} literal-2 ] .
{NEXT } {-}
{*}
{/}
Syntax Rules
- value-lit is a numeric or non-numeric literal that defines the initial value of a Working-Storage item.
- low-val is a numeric or non-numeric literal that defines the value of a condition, or the lower value of a condition range.
- high-val is a numeric or non-numeric literal that defines the upper value of a condition range. It must be the same type as
low-val and must have a value greater than
low-val.
- false-val is a numeric or non-numeric literal that defines the FALSE value for the corresponding data item.
- literal-1 is a numeric or alphanumeric literal. If
literal-2 is specified, then
literal-1 must be a numeric, non-floating-point literal.
literal-1 can also be a
LENGTH OF expression, as described in Numeric Literals.
- literal-2 is a numeric, non-floating point literal or a
LENGTH OF expression.
- The VALUE clause may not be used for any item whose size is variable.
- A VALUE clause may not be used with an external floating-point data item.
- All literals used in a VALUE clause must have a value which falls within the range of allowed values for the item's PICTURE
clause. Non-numeric literals may not exceed the size of the item. Numeric items must have numeric literals. Alphabetic, alphanumeric,
group, and edited items must have non-numeric literals.
- The words THROUGH and THRU are equivalent.
- The Format 2 VALUE clause may be used only in a condition-name (level 88). Its use is required in this case.
- VALUE clauses may appear in the File Section and the Linkage Section. They have no effect in these sections unless they are
part of condition-name entries (level 88s) or named constants (level 78s).
Their presence in these two sections simplifies the management of COPY libraries. For example, if you plan to use the same
COPY library in Working Storage in program-A and in Linkage in program-B, you need not remove the VALUE clauses in the Linkage
Section.
- The VALUE clause may not be specified for a group item that contains subordinate items with any of the following clauses:
JUSTIFIED, SYNCHRONIZED, or USAGE (other than USAGE DISPLAY).
- A Format 1 VALUE clause may not appear on a data item that is subordinate to a REDEFINES clause.
- A level 78 entry associates a value with the name of a constant, and
user-name is a user-defined word that names the constant.
user-name must be unique, because it may not be qualified.
General Rules
- A Format 1 VALUE clause specifies the initial state of a Working-Storage item or the value of a named constant. A Format 2
VALUE clause defines a condition-name. A Format 3 VALUE clause defines a constant.
- When a VALUE clause is applied to an edited item, that item is treated as if it were alphanumeric. Editing characters in the
PICTURE clause count toward the size of the item but have no effect on initialization. The literals must therefore appear
in edited form.
Initialization (Format 1)
- A Format 1 VALUE clause takes effect only when the program enters its initial state.
- The VALUE clause initializes its data item to the value of
value-lit.
- If no VALUE clause is specified, the initial value of a Working-Storage item is set to spaces, or the value specified with
the
-Dv compile option. This may, or may not, be a legal value for the item.
- When a VALUE clause appears on a data item that is subordinate to an x OCCURS clause, every occurrence of that data item is
initialized to the specified value.
- When a VALUE clause is applied to a group item, that item is initialized as if it were an alphanumeric item. It is not affected
by characteristics of any subordinate items to the group. No subordinate item may contain a VALUE clause within this group.
- The BLANK WHEN ZERO and JUSTIFIED clauses do not affect initialization.
Condition-Name (Format 2)
- The VALUE clause is required in a condition-name entry. The only clauses allowed in a condition-name entry are the level-number
(88), the condition-name itself, and its VALUE clause. See File Section for examples of condition-name entries.
- The characteristics of the condition-name are implicitly the same as those of its condition-variable. The condition-variable
is the immediately preceding completed record description entry.
- The VALUE clause describes the values of the condition-variable that imply a
true state for the associated condition-name. This consists of a single value, a range of values, or a set of both single values
and ranges. For example
VALUES ARE 1, 2, 4 THRU 7 would define a condition-name that was "true" when its associated condition-variable had any of the values
1,
2,
4,
5,
6, and
7.
- The WHEN SET TO FALSE phrase defines the "false" value for the condition-name. The SET statement cannot set the condition-name
to FALSE unless a "false" value is specified here.
Level 78 Constant (Format 3)
- When it is used with a level 78 item, the VALUE clause associates a literal with a user-defined word. The user-defined word
is then called a named constant. A named constant may be used anywhere the corresponding literal may be used. The compiler
replaces each occurrence of the named constant with the literal.
- The literal is constructed as follows:
- If
literal-1 is specified (without
literal-2), then
user-name acts as a synonym for that literal in the remainder of the program.
- If NEXT is specified (without
literal-2), then
user-name acts as an integer numeric constant whose value is the virtual address of the first byte past the end of the immediately
preceding data item. However, if the immediately preceding data item is a group item, then the value is the virtual address
of the beginning of the group item. Note that the effect of synchronization and data alignment may mean that the next data
item does not start at the same virtual address as the first byte past the end of the previous data item. This construct has
undefined effects if the immediately preceding data item is, or is part of, a data item greater than 64KB in size.
Note: The use of NEXT is designed for compatibility with other COBOL compilers. The effects of data alignment and data space segmentation
make this feature difficult to use with standard ACUCOBOL-GT code. Acucorp does not recommend its use except when you are
migrating code that already contains similar syntax. ACUCOBOL-GT provides other techniques for address manipulation (e.g.
POINTER data items) and size computation (e.g. SET TO SIZE OF statement).
- If
literal-2 is specified, then
user-name is an integer numeric constant whose value is the same as it would be without
literal-2 specified, acted upon by the specified operation. For example, the following two level 78s have the same value:
78 THREE VALUE 3.
78 THREE-AGAIN VALUE 1 + 2.
In some cases,
literal-1 and
literal-2 may, themselves, be level 78s. For example:
78 ONE VALUE 1.
78 TWO VALUE ONE + 1.
78 THREE VALUE TWO + 1.
When
literal-2 is used, both
literal-1 and
literal-2 are evaluated as integers, and the arithmetic is done using 32-bit integer arithmetic. The result is always an integer.
- You may use a level 78 named constant as a repeat count in a PICTURE string. This means that, in a PICTURE string, you may
substitute a level 78 for a number in parentheses. In the following example, DATA-1 and DATA-2 are both the same size:
78 LENG-20 VALUE 20.
01 DATA-1 PIC X(20).
01 DATA-2 PIC X(LENG-20).