VMS Help  —  RDML72  Statements  MATCHING  Examples
    The following programs demonstrate the use of the MATCHING
    conditional expression and the SORTED clause. These programs
    create a record stream containing all the records in the
    EMPLOYEES relation in which the field LAST_NAME begins with the
    letter "R". Then the programs sort the record stream in ascending
    numerical order of the employee IDS. These programs print, in
    numerical order, the employee ID, followed by the last name and
    first name for all the records in the record stream.

1  –  C Example

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

    DECLARE_VARIABLE match_string SAME AS EMPLOYEES.LAST_NAME;

    main()
    {
    read_string(match_string,"R*",sizeof(match_string));

    READY PERS;
    START_TRANSACTION READ_ONLY;

    FOR E IN EMPLOYEES
       WITH E.LAST_NAME MATCHING match_string
       SORTED BY E.EMPLOYEE_ID
          printf ("%s  %s  %s",E.EMPLOYEE_ID,
                               E.LAST_NAME,
                               E.FIRST_NAME);
    END_FOR;

    COMMIT;
    FINISH;
    }

2  –  Pascal Example

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

    var
      match_string: VARYING [10] OF CHAR;
    begin

    match_string := 'R*';

    READY PERS;
    START_TRANSACTION READ_ONLY;

    FOR E IN EMPLOYEES
       WITH E.LAST_NAME MATCHING match_string
       SORTED BY E.EMPLOYEE_ID
          writeln (E.EMPLOYEE_ID,'     ', E.LAST_NAME, E.FIRST_NAME);
    END_FOR;

    COMMIT;
    FINISH;
    end.
Close Help