VMS Help  —  RDML72  Statements  Relation Clause, Examples
    The following programs demonstrate the use of the relation clause
    with a FOR loop. These programs declare a context variable E for
    EMPLOYEES. This allows the programs to reference records from the
    EMPLOYEES relation by using the variable E in the host language
    print statements.

1  –  C Example

    #include <stdio.h>
    DATABASE PERS = FILENAME "PERSONNEL";

    main()
    {
    READY PERS;
    START_TRANSACTION READ_ONLY;

    FOR E IN EMPLOYEES
       printf ("%s  %s  %s\n", E.LAST_NAME,
                               E.EMPLOYEE_ID,
                               E.SEX);
    END_FOR;

    COMMIT;
    FINISH;
    }

2  –  Pascal Example

    program context_variable (input,output);
    DATABASE PERS = FILENAME 'PERSONNEL';

    begin
    READY PERS;
    START_TRANSACTION READ_ONLY;

    FOR E IN EMPLOYEES
       writeln (E.LAST_NAME, ' ', E.EMPLOYEE_ID, ' ', E.SEX);
    END_FOR;

    COMMIT;
    FINISH;
    end.
Close Help