VALUELIST and VALUERANGE attributes

The VALUELIST and VALUERANGE attributes limit the set of values that a variable, an argument, or a returned value can have. The VALUELIST attribute specifies a list of values while the VALUERANGE attribute specifies an inclusive range of values.

VALUELIST attribute

Read syntax diagramSkip visual syntax diagram
>>-VALUELIST-(expression -+----------------+-)-----------------><
                          '-,--expression -'     

The VALUELIST attribute is valid only with computational and ordinal types.

Each expression must:
  1. have a computational type if it is specified with a computational type, or have the same ordinal type if it is specified with an ordinal type.
  2. have a constant value.
  3. only appear once in the list (but can be in any order).

VALUERANGE attribute

Read syntax diagramSkip visual syntax diagram
>>-VALUERANGE-(expression 1,expression 2)----------------------><

The VALUERANGE attribute is valid only with computational and ordinal types. If the computational type is numeric, it must be REAL.

Each expression must:
  1. have a computational type if it is specified with a computational type, or have the same ordinal type if it is specified with an ordinal type.
  2. have a constant value.
  3. be greater than the former expression.

Example

Given the statements:
define alias numeric_month fixed bin(7) valuerange(1,12);

dcl imonth type numeric_month;

dcl cmonth char(3)
          valuelist( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                     'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' );
The variable imonth must hold only a value between 1 and 12 inclusive, and the variable cmonth must hold only one of the 12 specified values.
The VALIDVALUE built-in function can be used to test if a variable has one of the values specified in these attributes. For example, given the statements above, these expressions are equivalent.
VALIDVALUE( imonth )

BETWEEN( imonth, 1, 12 )

( 1 <= imonth ) & ( imonth <= 12 )
The compiler can also use these attributes to optimize code and to check that only one of the restricted set of values is assigned to such a variable. For example, given the statements above, both of these statements are invalid:
 dcl month_due type numeric_month init(0);

 cmonth = '';





Published: 23 December 2018