RDOHELP72.HLB  —  DEFINE_VIEW, Examples
    Example 1

    You can define a view from a single relation:

    DEFINE VIEW EMP_NAME OF E IN EMPLOYEES.
       E.FIRST_NAME.
       E.MIDDLE_INITIAL.
       E.LAST_NAME.
    END EMP_NAME VIEW.

    This command file specifies a view definition derived from a
    single relation, referring to three of its fields.

    Example 2

    You can also define a view using more than one relation:

    DEFINE VIEW CURRENT_SALARY
       OF SH IN SALARY_HISTORY CROSS
          E IN EMPLOYEES OVER EMPLOYEE_ID WITH
               SH.SALARY_END MISSING.
         E.LAST_NAME.
         E.FIRST_NAME.
         E.EMPLOYEE_ID.
         SH.SALARY_START.
         SH.SALARY_AMOUNT.
    END VIEW.

    This command file defines a view from the EMPLOYEES and SALARY_
    HISTORY relations. It uses the RSE to join the relations and
    limit the view to current salaries. Then it lists the fields
    required from each relation. These fields are referred to in
    the view definition as is, using the same field names as in the
    relation definition.

    Example 3

    You can give local field names to a view:

    DEFINE VIEW EMP_JOB OF E IN EMPLOYEES
      CROSS JH IN JOB_HISTORY OVER EMPLOYEE_ID
      CROSS J IN JOBS OVER JOB_CODE
      WITH JH.JOB_END MISSING.
        CURRENT_ID FROM E.EMPLOYEE_ID.
        CURRENT_NAME FROM E.LAST_NAME.
        CURRENT_JOB FROM J.JOB_TITLE.
        SUPERVISOR FROM JH.SUPERVISOR_ID.
    END EMP_JOB VIEW.

    The definition in this command file does the following:

    o  Joins the EMPLOYEES relation to JOB_HISTORY. This join links
       employees to job history records.

    o  Joins JOB_HISTORY to JOBS. This join lets the view contain job
       titles, instead of job codes.

    o  Uses the MISSING value expression. This clause specifies that
       only the current job history records, where the JOB_END field
       is empty, should be included in the view.

    o  Derives the view field names from the source relations but
       gives them local names.

 The following query uses the view defined in the preceding example:

    &RDB& START_TRANSACTION READ_ONLY
    &RDB& FOR CE IN EMP_JOB
            GET
              ID = CE.CURRENT_ID;
              NAME = CE.CURRENT_NAME;
              JOB = CE.CURRENT_JOB;
              SUPER = CE.SUPERVISOR;
            END_GET
    &RDB& END_FOR
    &RDB& COMMIT

    Example 4

    The COMPUTED BY field calculates the field in the view using a
    field or fields from a component relation:

    DEFINE VIEW SS_DEDUCTION OF E IN EMPLOYEES
      CROSS SH IN SALARY_HISTORY OVER EMPLOYEE_ID
      WITH SH.SALARY_END MISSING.
        E.EMPLOYEE_ID.
        E.SOCIAL_SECURITY.
        SH.SALARY_AMOUNT.
        SS_AMOUNT COMPUTED BY (SH.SALARY_AMOUNT * 0.065).
    END SS_DEDUCTION VIEW.

    This view definition computes a new "virtual" field from the
    SALARY_AMOUNT field of SALARY_HISTORY.
Close Help