我正在使用sqlrgple程序将选定数量的记录插入到文件中,然后输出给用户。见下面的代码片段
// Build SQL statement according to the parameters passed
if rpttype = 'O';
sqlstmt = 'Insert into fqrylibpgm/sblbrpt ' +
'(shclno, shscdt, shcmdt, shcust, ' +
'ttlonl, ttlofl, ttltvl) ' +
'Select shclno, shscdt, shcmdt, shcust, '+
'coalesce(sum(cast(((tbontm * 0.01) * tbonbr)' +
' as dec(8,2))),0), ' +
'coalesce(sum(cast(((tboftm * 0.01) * tbofbr)' +
' as dec(8,2))),0), ' +
'coalesce(sum(cast(((tbtvtm * 0.01) * tbtvbr)' +
' as dec(8,2))),0) ' +
'from r50files/sbschd '+
'left join r50modsdta/sbsctc on tbcmp = shcmp and ' +
'tbcust = shcust and tbclno = shclno ';
elseif rpttype = 'C';
sqlstmt = 'Insert into fqrylibpgm/sblbrpt ' +
'(shclno, shscdt, shcmdt, shcust, ' +
'ttlonl, ttlofl, ttltvl) ' +
'Select shclno, shscdt, shcmdt, shcust, '+
'coalesce(sum(cast(((tbontm * 0.01) * tbonbr)' +
' as dec(8,2))),0), ' +
'coalesce(sum(cast(((tboftm * 0.01) * tbofbr)' +
' as dec(8,2))),0), ' +
'coalesce(sum(cast(((tbtvtm * 0.01) * tbtvbr)' +
' as dec(8,2))),0) ' +
'from r50files/sbhshd '+
'left join r50modsdta/sbhstc on tbcmp = shcmp and ' +
'tbcust = shcust and tbclno = shclno ';
endif;
// Only for Rentals location
sqlstmt += 'where shloc = 1202 ';
// Scheduled Date Filter
sqlstmt += 'and (shscdt >= ' + %char(scdtfr) +
' and shscdt <= ' + %char(scdtto) + ') ';
//Completed Date Filter
sqlstmt += 'and (shcmdt >= ' + %char(cmdtfr) +
' and shcmdt <= ' + %char(cmdtto) + ') ';
// Group Clause to get Sum
sqlstmt += ' group by shclno, shscdt, shcmdt, ' +
' shcust ';
sqlstmt += ' order by shclno';
// Execute SQL Insert statement
exec sql prepare sqlsel from :sqlstmt;
exec sql execute sqlsel;
// Get SQL return codes (use to debug)
exec sql GET DIAGNOSTICS CONDITION 1
:rsqlcode = DB2_RETURNED_SQLCODE,
:rmsgtext = MESSAGE_TEXT;
exec sql commit; 问题是,当我运行这个程序时,我得到了一个sqlcode -7008和一条消息文本,上面写着"SBLBRPT对操作无效“。
11.0.0/codes/src/tpc/n7008.html
根据文档,我应该得到一个后面的原因代码,但我没有。
当我调试程序以确保查询正确时。在执行sqlstmt之前,我使用sqlstmt的值,然后按原样在STRSQL中尝试该语句,它可以正常工作。
文件SBLBRPT也在库列表中。
我以前做过这样的程序,还没有遇到这个错误,我不知道如何修复它。如能提供任何协助,将不胜感激。
发布于 2018-11-29 21:11:43
原因代码在作业日志里..。
很可能,您已经接受了CRTSQLRPGI命令的缺省值,即提交(*CHG),并且没有记录表(文件)。
在程序中添加一个exec sql set option commit=*none;,或者将with nc添加到statement...or中,在编译时更改该选项。
https://stackoverflow.com/questions/53546767
复制相似问题