Format 2
This format associates a value, values, or ranges of values with a condition-name. Each such condition-name requires a separate level-88 entry. Level-number 88 and the condition-name are not part of the format-2 VALUE clause itself. They are included in the format only for clarity.
- condition-name-1
- A user-specified name that associates a value with a conditional
variable. If the associated conditional variable requires subscripts
or indexes, each procedural reference to the condition-name must be
subscripted or indexed as required for the conditional variable.
Condition-names are tested procedurally in condition-name conditions (see Conditional expressions).
- literal-1
- Associates the condition-name with a single value.
The class of literal-1 must be a valid class for assignment to the associated conditional variable.
- literal-1 THROUGH literal-2
- Associates the condition-name with at least one range of values.
When the THROUGH phrase is used, literal-1 must
be less than literal-2. For details, see Rules for condition-name entries.
literal-1 and literal-2 must be of the same class. The class of literal-1 and literal-2 must be a valid class for assignment to the associated conditional variable.
When literal-1 and literal-2 are DBCS literals, the range of DBCS values specified by the THROUGH phrase is based on the binary collating sequence of the hexadecimal values of the DBCS characters.
When literal-1 and literal-2 are NATIONAL literals, the range of national character values specified by the THROUGH phrase is based on the binary collating sequence of the hexadecimal values of the national characters represented by the literals.
When literal-1 and literal-2 are UTF-8 literals, the range of UTF-8 character values specified by the THROUGH phrase is based on the binary collating sequence of the hexadecimal values of the UTF-8 characters represented by the literals.
If the associated conditional variable is of class DBCS, literal-1 and literal-2 must be DBCS literals. The figurative constant SPACE or the figurative constant ALL DBCS-literal can be specified.
If the associated conditional variable is of class NATIONAL, literal-1 and literal-2 must be either both national literals or both alphanumeric literals for a given condition-name. The figurative constants ZERO, SPACE, QUOTE, HIGH-VALUE, LOW-VALUE, symbolic-character, ALL national-literal, or ALL literal can be specified.
If the associated conditional variable is of class UTF-8, literal-1 and literal-2 must be either both UTF-8 literals or both alphanumeric literals for a given condition-name. The figurative constants ZERO, SPACE, QUOTE, HIGH-VALUE, LOW-VALUE, symbolic-character, ALL utf-8-literal, or ALL literal can be specified.
- WHEN SET TO FALSE
- Allows specification of a FALSE condition value. This value is moved to the associated conditional variable when the SET TO FALSE statement is executed for the associated condition-name.
- literal-3
- When a condition-name is referenced in a SET TO FALSE statement,
the value of literal-3 from the FALSE phrase is
placed in the associated conditional variable.Note: The true values of a conditional variable are all the values associated with its condition-names, and all other values are false values. The WHEN SET TO FALSE phrase specifies just one of possibly many false values. The purpose is to define a single value to be used by the SET TO FALSE statement. When a condition-name condition is tested, all the non-true values give a false result, not just the one false value defined by the WHEN SET TO FALSE phrase.
Rules for condition-name entries
There are certain rules for condition-name entries.
The rules are:
- The VALUE clause is required in a condition-name entry, and must be the only clause in the entry. Each condition-name entry is associated with a preceding conditional variable. Thus every level-88 entry must always be preceded either by the entry for the conditional variable or by another level-88 entry when several condition-names apply to one conditional variable. Each such level-88 entry implicitly has the PICTURE characteristics of the conditional variable.
- A
space, a separator comma, or a separator semicolon must separate successive
operands.
Each entry must end with a separator period.
- The keywords THROUGH and THRU are equivalent.
- The condition-name entries associated with a particular conditional
variable must immediately follow the conditional variable entry. The
conditional variable can be any elementary data description entry
except the following ones:
- Another condition-name
- A RENAMES clause (level-66 item)
- An item described with USAGE IS INDEX
- An item described with USAGE POINTER, USAGE PROCEDURE-POINTER, USAGE FUNCTION-POINTER, or USAGE OBJECT REFERENCE
- Condition-names can be specified both at the group level and at subordinate levels within an alphanumeric group, national group or UTF-8 group.
- When the condition-name is specified for an alphanumeric
group data description entry:
- The value of literal-1 (or literal-1 and literal-2) must be specified as an alphanumeric literal or figurative constant.
- The group can contain items of any usage.
- When the condition-name is specified for a national
group data description entry:
- The value of literal-1 (or literal-1 and literal-2) must be specified as an alphanumeric literal, a national literal, or a figurative constant.
- The group can contain only items of usage national, as specified for the GROUP-USAGE clause.
- When the condition-name is specified
for a UTF-8 group data description entry:
- The value of literal-1 (or literal-1 and literal-2) must be specified as an alphanumeric literal, a UTF-8 literal, or a figurative constant.
- The group can contain only items of usage UTF-8, as specified for the GROUP-USAGE clause.
- When the condition-name is associated with an alphanumeric group
data description entry or a national group data description entry or a UTF-8 group data description entry:
- The size of each literal value must not exceed the sum of the sizes of all the elementary items within the group.
- No element within the group can contain a JUSTIFIED or SYNCHRONIZED clause.
- Relation tests implied by the definition of a condition-name are performed in
accordance with the rules referenced in the following table.
Table 1. Relation test references for condition-names Type of conditional variable Relation condition rules Alphanumeric group item Group comparisons National group item (treated as elementary data item of class national) National comparisons Elementary data item of class alphanumeric Alphanumeric comparisons Elementary data item of class national National comparisons Elementary data item of class numeric Numeric comparisons Elementary data item of class DBCS DBCS comparisons Elementary data item of class UTF-8 UTF-8 comparisons - A VALUE clause that specifies a national literal can be associated with a condition-name defined only for a data item of class national.
- A VALUE clause that specifies a DBCS literal can be associated with a condition-name defined only for a data item of class DBCS.
- The literals in a condition-name entry for an elementary
data item of class national or a national group item must be either
national literals or alphanumeric literals, and literal-1 and literal-2 must
be of the same class. For alphanumeric groups or elementary data items
of other classes, the type of literal must be consistent with the
data type of the conditional variable. In the following example:
- CITY-COUNTY-INFO, COUNTY-NO, and CITY are conditional variables.
The PICTURE associated with COUNTY-NO limits the condition-name value to a two-digit numeric literal.
The PICTURE associated with CITY limits the condition-name value to a three-character alphanumeric literal.
- The associated condition-names are level-88 entries.
Any values for the condition-names associated with CITY-COUNTY-INFO cannot exceed five characters.
Because this is an alphanumeric group item, the literal must be alphanumeric.
05 CITY-COUNTY-INFO. 88 BRONX VALUE "03NYC". 88 BROOKLYN VALUE "24NYC". 88 MANHATTAN VALUE "31NYC". 88 QUEENS VALUE "41NYC". 88 STATEN-ISLAND VALUE "43NYC". 10 COUNTY-NO PICTURE 99. 88 DUTCHESS VALUE 14 WHEN FALSE IS 99. 88 KINGS VALUE 24. 88 NEW-YORK VALUE 31. 88 RICHMOND VALUE 43. 10 CITY PICTURE X(3). 88 BUFFALO VALUE "BUF". 88 NEW-YORK-CITY VALUE "NYC". 88 POUGHKEEPSIE VALUE "POK". 05 POPULATION...
- CITY-COUNTY-INFO, COUNTY-NO, and CITY are conditional variables.
Example
IDENTIFICATION DIVISION.
PROGRAM-ID. LEVEL88.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 YEAR.
05 YEAR-INIT PIC 9(4).
88 YEAR-VALID VALUE 2000 THRU 2023.
88 YEAR-INVALID VALUE 0001 THRU 1999
2024 THRU 9999.
PROCEDURE DIVISION.
DISPLAY 'Enter a year:'.
ACCEPT YEAR.
IF YEAR-VALID
DISPLAY 'YEAR:' YEAR
ELSE
DISPLAY 'INVALID YEAR'
END-IF.
STOP RUN.
The following is the output, if the input for YEAR is
1999:INVALID YEAR