Use the database field value expression to reference database fields in record selection expressions and in other value expressions.
1 – Examples
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.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; }
1.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.
2 – Format
(B)0[mdb-field-expr qqq> context-var qqq> . qqq> field-name qqq>
2.1 – Format arguments
context-var A context variable. A temporary name that you associate with a relation. You define a context variable in a relation clause. For more information see the entry on Context Variables. field-name The name of a field in a relation. For example, once you have defined E as the context variable for the EMPLOYEES relation, E.LAST_NAME is a value expression that refers to a value from the LAST_NAME field of EMPLOYEES.