VALUERANGE attribute

The VALUERANGE attribute specifies an inclusive range of values to limit the set of values that a variable, an argument, or a returned value can have.

Read syntax diagramSkip visual syntax diagramVALUERANGE( 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 = '';