The following programs demonstrate the use a host variable value
expression as a transaction handle. These programs declare the
host variable, EMP_UPDATE. The programs use EMP_UPDATE to qualify
the transaction in the START_TRANSACTION expression, the record
selection expression, and the COMMIT statement. The record
selection expression modifies the record with the specified ID
number in the EMPLOYEES relation. The COMMIT statement, also
qualified with the transaction handle, ensures that the modified
record is stored in the database.
Note that the C program uses the pad_string function to read
in the values for the STORE statement. This function pads the
values stored in each field with the correct number of trailing
blanks to ensure that the length of the values stored match the
text size of the field. For more information on pad_string, see
Appendix B of the "RDML Reference Manual".
1 – C Example
#include <stdio.h>
DATABASE PERS = FILENAME "PERSONNEL";
extern void pad_string();
main()
{
int EMP_UPDATE = 0;
READY PERS;
START_TRANSACTION (TRANSACTION_HANDLE EMP_UPDATE) READ_WRITE;
FOR (TRANSACTION_HANDLE EMP_UPDATE) E IN EMPLOYEES
WITH E.EMPLOYEE_ID = "00178"
MODIFY E USING
pad_string("Brannon", E.LAST_NAME, sizeof(E.LAST_NAME));
END_MODIFY;
END_FOR;
COMMIT(TRANSACTION_HANDLE EMP_UPDATE);
FINISH;
}
2 – Pascal Example
program trhand (input,output);
DATABASE PERS = FILENAME 'PERSONNEL';
var EMP_UPDATE : [volatile] integer := 0;
begin
READY PERS;
START_TRANSACTION (TRANSACTION_HANDLE EMP_UPDATE) READ_WRITE;
FOR (TRANSACTION_HANDLE EMP_UPDATE) E IN EMPLOYEES
WITH E.EMPLOYEE_ID = '00178'
MODIFY E USING
E.LAST_NAME := 'Brannon';
END_MODIFY;
END_FOR;
COMMIT (TRANSACTION_HANDLE EMP_UPDATE);
FINISH;
end.