In a C program, transfer a certain amount of commission (COMM) from one employee (EMPNO) to another in the EMPLOYEE table. Subtract the amount from one row and add it to the other. Use the COMMIT statement to ensure that no permanent changes are made to the database until both operations are completed successfully.
void main () { EXEC SQL BEGIN DECLARE SECTION; decimal(5,2) AMOUNT; char FROM_EMPNO[7]; char TO_EMPNO[7]; EXEC SQL END DECLARE SECTION; EXEC SQL INCLUDE SQLCA; EXEC SQL WHENEVER SQLERROR GOTO SQLERR; ... EXEC SQL UPDATE EMPLOYEE SET COMM = COMM - :AMOUNT WHERE EMPNO = :FROM_EMPNO; EXEC SQL UPDATE EMPLOYEE SET COMM = COMM + :AMOUNT WHERE EMPNO = :TO_EMPNO; FINISHED: EXEC SQL COMMIT WORK; return; SQLERR: ... EXEC SQL WHENEVER SQLERROR CONTINUE; /* continue if error on rollback */ EXEC SQL ROLLBACK WORK; return; }
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.