The following programs demonstrate the use of the database field value expression. These programs use the database field value expression, FOR J IN JOBS, to declare the context variable J. This allows the programs to use the clause, J.JOB_CODE, to mean JOBS.JOB_CODE. The programs search the field JOB_CODE for the string "APGM". Any record that contains the specified string becomes part of the record stream. These programs then use J to qualify the fields in the host language print statements. The job title, minimum salary and the maximum salary for each record in the record stream are printed.
1 – C Example
#include <stdio.h> DATABASE PERS = FILENAME "PERSONNEL"; main() { READY PERS; START_TRANSACTION READ_ONLY; FOR J IN JOBS WITH J.JOB_CODE = "APGM" printf ("%s", J.JOB_TITLE); printf (" $%f", J.MINIMUM_SALARY); printf (" $%f\n", J.MAXIMUM_SALARY); END_FOR; COMMIT; FINISH; }
2 – Pascal Example
program fld_value (input,output); DATABASE PERS = FILENAME 'PERSONNEL'; begin READY PERS; START_TRANSACTION READ_ONLY; FOR J IN JOBS WITH J.JOB_CODE = 'APGM' writeln (J.JOB_TITLE, ' $', J.MINIMUM_SALARY: 10 : 2, ' $', J.MAXIMUM_SALARY: 10 : 2); END_FOR; COMMIT; FINISH; end.