The following programs demonstrate the use of the
DECLARE_VARIABLE clause to declare a program variable. These
programs:
o Declare the variable, badge, to have the same data type and
size attributes as EMPLOYEE_ID in the EMPLOYEES relation.
o Use this variable for interactive processing. Note that the
interactive portion of the programs appear before the READY
statement. This keeps locks on the database to a minimum.
o Select the record from the EMPLOYEES relation that has the
same value for EMPLOYEE_ID as is stored in badge.
o Modify the STATUS_CODE field of this record
Note that the C program uses the read_string function to prompt
for and receive a value for badge. For more information on this
function 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.