DB2 SQLCode -7008



我使用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; 

问题是,当我运行这个程序时,我得到了-7008的sqlcode和一条消息文本,上面写着"SBLBRPT NOT VALID FOR OPERATION">

https://www.ibm.com/support/knowledgecenter/en/SSEPEK_11.0.0/codes/src/tpc/n7008.html

根据医生的说法,我应该得到一个原因代码,但我没有。

当我调试程序以确保查询正确时。在执行sqlstmt之前,我获取它的值,并按原样在STRSQL中尝试该语句,它运行良好。

SBLBRPT文件也在库列表中。

我以前做过这样的程序,还没有遇到这个错误,我不确定如何修复它。任何帮助都将非常感谢

原因代码在作业日志中。。。

很可能,您已经使用了CRTSQLRPGI命令的默认值,即COMMIT(*CHG(,并且有问题的表(文件(没有日志记录。

exec sql set option commit=*none;添加到程序中,或将with nc添加到语句中。。。或者在编译时更改选项。

最新更新