DEFINE ORDINAL

Attention: This topic applies to a feature that is in Early Adopter Program (EAP) release status. We intend to provide the finalized feature in a future release. Please contact OpenText Support for Micro Focus Products if you require further clarification.

Purpose

Represents a set of named ordered values via a named type.

Syntax

DEFINE ORDINAL ordinal_type_name {member_name [VALUE(integer)]
  [,...]} [{PRECISION | PREC}] (integer) [SIGNED | UNSIGNED]

Parameters

ordinal_type_name
The named type that represents the set of ordinal values. Use this name only in DECLARE statements with the ORDINAL attribute. When used elsewhere, the name is treated like any other non-ordinal name.
member_name
The name of a member within the set of ordinal values.
VALUE
The value of a particular member within the set of ordinal values. When omitted for the first member, the default value used is 0 (zero). When omitted for any other member, the value used is that of the next greater integer.

The value assigned or assumed for the VALUE attribute must be a signed or unsigned integer, and may be specified as an XN constant. It must strictly increase.

PRECISION | PREC
Specifies the precision for the ordinal value. The maximum precision allowed is the same as that of FIXED BINARY data items. However, the actual maximum precision applied is 31 for SIGNED, and 32 for UNSIGNED. For UNSIGNED, the maximum value allowed is 2147483647. If omitted, the range of ordinal values determines the precision.
SIGNED
Indicates that ordinal values can be negative. When omitted, SIGNED is applied when any ordinal values within the range are negative.
UNSIGNED
Indicates that ordinal values cannot be negative.

Examples

Example 1
define ordinal Subjects (Mathematics,   /* 0, starting value is zero when VALUE not specified */
                         Literature,    /* 1 */
                         Science,       /* 2 */
                         History);      /* 3 */

define ordinal Math (Algebra VALUE(101),  /* 101*/
                     Geometry,            /* 102 */
                     Calculus VALUE(301)); /* 301 */
Example 2
define ordinal Subjects (Arithmetic,    /* 0, starting value is zero when VALUE not specified */
                         Literature,    /* 1 */
                         Science,       /* 2 */
                         History);      /* 3 */

dcl x ordinal Subjects;

   do x = first(:Subjects:) upthru last(:Subjects:);
       put skip list (ordinalname(x));
   end;

Prints:

MATHEMATICS
LITERATURE
SCIENCE
HISTORY
Example 3
Declare subject  ORDINAL Subjects;

Declare course TYPE Math;   /* ORDINAL & TYPE keywords are interchangeable */

     subject = Mathematics;
     course = Calculus;

     if subject = Mathematics then
         if course = Calculus then
             put skip list ('At the upper Limit!');


     subject = Algebra; /* illegal assignment, mismatched ordinal types */

     if subject = course then /* illegal comparison, mismatched ordinal types */
          put skip;;

Restrictions

Unsupported type functions include BIND, CAST, NEW, RESPEC, SIZE, and VALUE.