CDDLHELP.HLB  —  VARIANTS OF field
  Names a tag variable whose value at run time determines which of  the
  VARIANT fields is the current VARIANT.

1  –  Parameters

  var_field_name

       The tag variable field, whose value determines the selection  of
       the current VARIANT at run time.

  low_value, high_value

      Values to be compared to the value of the  tag  variable  at  run
      time to determine the current VARIANT.

  field description statement

       A definition of the field characteristics  for  the  subordinate
       fields of each VARIANT.

2  –  Syntax Rules

   o  The VARIANT field description block can be repeated.

   o  The tag variable must be an elementary field fixed in the  record
      and  not part of an array, and it must precede the VARIANTS field
      description statement.  It cannot be an unnamed field.

   o  You must fully qualify the tag variable's field name if it is not
      unique  within the record.  A fully qualified field name consists
      of an elementary field name preceded by the  field  names  of  as
      many  of  its  direct  ancestors  as  you  need  to  specify  the
      elementary field uniquely.  You must separate each element  of  a
      fully qualified field name from the next with a period.

      Once the elementary field name is identified  uniquely,  you  can
      omit  any  remaining ancestors' field names.  Furthermore, if the
      tag variable's name is not unique within the record, none of  the
      ancestors in its fully qualified name can be unnamed fields.

   o  You must include a tag value clause for VARIANT.

   o  At run time, the values (low_value and high_value...) you specify
      are  compared  to  the value of the tag variable to determine the
      current VARIANT.

   o  Tag  value  specifications  must   conform   to   the   following
      conditions:

       -  The tag values low_value, high_value...  must be legal values
          as  defined by the tag variable's data type.  For example, if
          the tag variable is a TEXT field,  the  tag  values  must  be
          quoted literals.

       -  The values of high_value must be greater than or equal to the
          values  of  low_value  in  the collating sequence of the data
          type.

       -  The range of values in one VARIANT must not overlap the range
          of values in any other VARIANT.

   o  The compiler ignores commas, but you can use  them  to  make  tag
      value specifications easier to read.

   o  The CDDL compiler does not check that the tag values you  specify
      are legal.  If you specify invalid values, you will receive error
      messages when you refer to the VARIANT field in an application.

3  –  Usage Notes

   o  The tag value clause specifies a value or set of values  for  the
      tag variable in each VARIANT of a VARIANTS field collection.  The
      tag variable can then be used at run time  to  find  the  current
      VARIANT.

   o  Languages that do not support tag variables ignore the tag  value
      clause.   For  more information on language support of CDD record
      definitions, refer to the documentation for the language you  are
      using.

   o  Each variant begins on the same byte in the  record,  subject  to
      individual  alignment options.  The length of the longest VARIANT
      in the collection determines the overall length of  the  VARIANTS
      field description.

   o  Be sure that the VARIANT collection you define  conforms  to  the
      requirements  of  the  language  or  language processor that will
      access the record definition.

   o  VAX DATATRIEVE requires each VARIANT to contain a STRUCTURE field
      description statement at the top of the VARIANT.

4  –  Example

  In the following example, RECORD_IDENTIFIER is the tag variable.  The
  value  of  RECORD_IDENTIFIER  at run time determines which VARIANT is
  current according to the translation table in the descriptive text.

  STOCK STRUCTURE.
      /* RECORD_IDENTIFIER determines field type:
           S --> In-stock record.
           B --> Back-order record.
           O --> Out-of-stock record. */
      RECORD_IDENTIFIER          DATATYPE IS TEXT
                                 SIZE IS 1 CHARACTER.
      VARIANTS OF RECORD_IDENTIFIER.
          VARIANT VALUE IS "S".
              IN_STOCK STRUCTURE.
                  PRODUCT_NO     DATATYPE IS TEXT
                                 SIZE IS 8 CHARACTERS.
                  DATE_ORDERED   DATATYPE IS DATE.
                  STATUS_CODE    DATATYPE IS BYTE.
                  QUANTITY       DATATYPE IS LONGWORD
                                 ALIGNED ON LONGWORD.
                  LOCATION       ARRAY 1:4
                                 DATATYPE IS TEXT
                                 SIZE IS 30 CHARACTERS.
                  UNIT_PRICE     DATATYPE IS LONGWORD SCALE -2.
              END IN_STOCK STRUCTURE.
          END VARIANT.
          VARIANT VALUE IS "B".
              BACK_ORDER STRUCTURE.
                  PRODUCT_NO     DATATYPE IS TEXT
                                 SIZE IS 8 CHARACTERS.
                  DATE_ORDERED   DATATYPE IS DATE.
                  STATUS_CODE    DATATYPE IS BYTE.
                  QUANTITY       DATATYPE IS LONGWORD
                                 ALIGNED ON LONGWORD.
                  SUPPLIER       ARRAY 1:4
                                 DATATYPE IS TEXT
                                 SIZE IS 30 CHARACTERS.
                  UNIT_PRICE     DATATYPE IS LONGWORD
                                 SCALE -2.
              END BACK_ORDER STRUCTURE.
          END VARIANT.

          VARIANT VALUE IS "O".
              OUT_OF_STOCK STRUCTURE.
                  PRODUCT_NO         DATATYPE IS TEXT
                                     SIZE IS 8 CHARACTERS.
                  DATE_LAST_SOLD     DATATYPE IS DATE.
              END OUT_OF_STOCK STRUCTURE.
          END VARIANT.
      END VARIANTS.
  END STOCK STRUCTURE.
Close Help