Noncursor Template for Handling Deadlock
This template assumes your transactions do not contain a cursor.
exec sql whenever not found continue;
exec sql whenever sqlwarning continue;
exec sql whenever sqlerror goto err;
/* branch on error */
start:
exec sql insert into ...
exec sql update ...
exec sql select ...
exec sql commit;
goto end;
err:
exec sql whenever sqlerror call sqlprint;
if (sqlca.sqlcode = E_GEC2EC_SERIALIZATION) then
goto start;
else if (sqlca.sqlcode < 0) then
exec sql inquire_sql (:err_msg = errortext);
exec sql rollback;
print 'Error', err_msg;
end if;
end: