RDOHELP72.HLB  —  DEFINE_RELATION, Examples
    Example 1

    The following example uses DEFINE RELATION to create a relation:

    DEFINE RELATION DEPARTMENTS.
       DEPARTMENT_CODE.
       DEPARTMENT_NAME.
       MANAGER_ID BASED ON ID_NUMBER.
    END DEPARTMENTS RELATION.

    This statement names the new relation, DEPARTMENTS, and specifies
    its fields.

    o  DEPARTMENT_CODE and DEPARTMENT_NAME are already defined. The
       relation definition simply uses their names.

    o  MANAGER_ID is a local name, but it points to an existing
       global field definition. If the definition of ID_NUMBER
       changes, MANAGER_ID changes also.

    Example 2

    The following example defines global fields in the DEFINE
    RELATION statement:

    DEFINE RELATION FAMILY
          DESCRIPTION IS /* Family information */.
      /* Employee ID * /
             EMPLOYEE_ID BASED ON ID_NUMBER
             QUERY_NAME FOR DTR IS "EMP".
      /* Married?  M or S */
             MARITAL_STATUS
                   DATATYPE TEXT SIZE 1
                   VALID IF MARITAL_STATUS = "M" OR
                            MARITAL_STATUS = "S".
      /* Number of dependents */
             NUMBER_DEPENDENTS
                   DATATYPE SIGNED WORD SCALE 0.
      /* Amount of IRS withholding */
             WITHHOLDING
                   COMPUTED BY 0.20 / NUMBER_DEPENDENTS.
    END FAMILY RELATION.

    This DEFINE RELATION statement defines several new fields:

    o  The DESCRIPTION clause and the other text fields provide
       commentary for the relation definition and for each field.

    o  EMPLOYEE_ID is a local name for the global ID_NUMBER field.
       The QUERY_NAME clause overrides any QUERY_NAME clause on ID_
       NUMBER.

    o  MARITAL_STATUS uses the DATATYPE clause. Therefore, MARITAL_
       STATUS becomes a global field definition. MARITAL_STATUS is
       entered in the list of global fields for the database, and
       other relations can use it by name.

    o  NUMBER_DEPENDENTS also becomes a global field definition.

    o  WITHHOLDING is a local field, defined in terms of NUMBER_
       DEPENDENTS.

    Example 3

    The following example copies a shareable relation definition from
    the data dictionary into the database:

    DEFINE RELATION EMP_INFO
      FROM PATHNAME 'DISK1:[DICTIONARY]CORP.PERS.EMP_INFO'.
Close Help