%RANGE (lower-limit : upper-limit)

%RANGE is used with the IN operator. %RANGE does not return a value, and it cannot be specified anywhere other than following the IN operator.

When the IN operator is used with %RANGE, it determines whether the first operand is in the range specified by %RANGE.

The expression using the IN operator with %RANGE is true if the first operand of the IN operator is greater than or equal to the first operand of %RANGE and less than or equal to the second operand of %RANGE.

The first operand of the IN operator cannot be an array.

The operands of %RANGE must be able to be compared to each other and to the first operand of the IN operator. For example, if the first operand of the IN operator has type date, the operands of %RANGE must also have type date.

The following two statements are equivalent:

IF x IN %RANGE(y1 : y2);

IF x >= y1 AND x <= y2;
If the first operand of the IN operator has type alphanumeric, graphic, or UCS-2, the operands of %RANGE must also have type alphanumeric, graphic, or UCS-2. If the first operand of the IN operator has type date, the operands of %RANGE must also have type date. If the
Warning: Comparisons in Unicode or ASCII differ from comparisons in EBCDIC. See Unexpected results when comparing data with different data types or CCSIDs.
If the operands of IN %RANGE are pointers, the result is meaningless unless all the pointers point to related storage. In the following example, P1, P2 and P3 are all pointers to sections of variable STRING. It is meaningful to use the IN operator with %RANGE for these pointers.

DCL-S string CHAR(1000);
DCL-S p1 POINTER;
DCL-S p2 POINTER;
DCL-S p3 POINTER;

p1 = %ADDR(string) + 10;
p2 = %ADDR(string) + 50;
p3 = %ADDR(string) + 75;

IF p2 IN %RANGE(p1 : p3);
   DSPLY ('true');
ENDIF;