z/OS DB2版本13:在大型机批处理环境执行过程中如何检测回滚
返回sqlcode -911的 SQL语句会导致当前工作单元回滚(https://www.ibm.com/docs/en/db2-for-zos/13.0.0?topic=codes-911)。
假设我们有一个主COBOL程序,它调用若干执行DB2访问的例程,其中一个例程中的SQL语句返回 -911。这些例程被编写成向调用它们的程序返回通用错误,并且不可修改。主程序如何知道是否发生了因 -911而导致的回滚?
其实,主程序在例程内部通过一个技巧来检测 -911:当单元工作开始时,它打开一个“伪游标”,调用一个例程;如果某个例程返回错误,它再次打开这个“伪游标”,以判断被调用的例程中的SQL语句是否引发了 -911。
示例
exec sql
declare cs01-for-911
cursor for
select 1
from sysibm.sysdummy1
with ur
end-exec
.
.
**
** start of UOW
**
exec sql
open cs01-for-911
end-exec
.
.
**
** update some tables
**
.
.
exec sql
savepoint SA
end-exec
call routine1 using io-area
if == return code from routine is KO ==
exec sql
open cs01-for-911
end-exec
evaluate sqlcode
when -502
== no -911 inside routine1 because cs01-for-911 is already open ==
== discard any updates of routine1 and keep main program's updates ==
exec sql
rollback to savepoint SA
end-exec
=== write a warning on a log file ==
when zero
=== yes -911 inside routine1 ===
=== ABEND ==
when other
== ABEND ==
end-evaluate
end-if
.
.
exec sql
commit
end-exec
**
** end of UOW
**
.
.
是否有最简单的方法来检测 -911?
谢谢。
解决方案
我建议使用 GET DIAGNOSTICS 语句。
GET DIAGNOSTICS语句提供关于最近执行的SQL语句(除了GET DIAGNOSTICS语句本身之外)所得到的诊断信息。
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。