The following programs demonstrate the use of the MODIFY statement with a host variable. These programs: o Declare a host variable, badge, with the same data type and attributes as EMPLOYEES.EMPLOYEE_ID o Prompt for a value for badge o Change the status code for the employee with the specified badge The C program uses the read_string function to prompt for and receive a value for badge. For more information on read_string, see Appendix B of the "RDML Reference Manual".
1 – C Example
#include <stdio.h> DATABASE PERS = FILENAME "PERSONNEL"; extern void read_string(); static DECLARE_VARIABLE badge SAME AS EMPLOYEES.EMPLOYEE_ID; main() { read_string ("Employee ID: ", badge, sizeof(badge)); READY PERS; START_TRANSACTION READ_WRITE; FOR E IN EMPLOYEES WITH E.EMPLOYEE_ID = badge MODIFY E USING strcpy(E.STATUS_CODE,"1"); END_MODIFY; END_FOR; ROLLBACK; FINISH; }
2 – Pascal Example
program modify_with_host (input,output); DATABASE PERS = FILENAME 'PERSONNEL'; var DECLARE_VARIABLE badge SAME AS EMPLOYEES.EMPLOYEE_ID; begin write ('Employee ID: '); readln (badge); READY PERS; START_TRANSACTION READ_WRITE; FOR E IN EMPLOYEES WITH E.EMPLOYEE_ID = badge MODIFY E USING E.STATUS_CODE := '1'; END_MODIFY; END_FOR; ROLLBACK; FINISH; end.