Use a host variable value expression to pass data between a
calling program and Oracle Rdb. A host variable is a program
variable.
1 – Examples
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.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;
}
1.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.
2 – Format
(B)0[mC-host-variable =
VMS-name qwqqqqqqwwwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwwq>
mq> * qjxtqqq> . qqq> field-identifier qqqqqux
xx xx
xtqqq> [ qwq> expression qwqq> ] qqqux
xx mqqqqqqq , <qqqqqj xx
xx xx
xmqqq> "->" qqqq> field-identifier qqqqjx
mqqqqqqqq<qqqqqqqqqqqqqqqqqqqqqqqqq<qqqqqqj
The C pointer operator is shown in quotes to distinguish it from
the arrows that show the logical flow of the syntax. Do not use
quotes around the pointer operator in your programs.
(B)0[mPascal-host-variable =
VMS-name qwqqwqqqqqqqqqqqqqqqqqqq>qqqqqqqqqqqqqqqqqqqqqwqqwqqq>
x tqqq> . qqq> field-identifier qqqqqqqqu x
x x x x
x tqqq> [ qwq> expression qqqwqq> ] qqu x
x x mqqqqqqqq , <qqqqqj x x
x x x x
x mqqq> ^ qwqqqqqqqqqqqqq>qqqqqqqqqwqqqqqqj x
x mq> field-identifier qqj x
x x
mqqqqqqqqqq<qqqqqqqqqqqqqqqqqqqqqqqq<qqqqqqqqqqqj
2.1 – Format arguments
VMS-name A valid OpenVMS name.
field-indentifier A valid host language field identifier.
expression An expression that evaluates to a valid
host language array element.
"->" The C pointer symbol. It is shown in
quotes to distinguish it from the arrows
that show the logical flow of the syntax.
Do not use quotes around the pointer
symbol in your program.