Jav*_*Ali 0 rpgle db2-400 ibm-midrange
我正在使用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;
Run Code Online (Sandbox Code Playgroud)
问题是当我运行这个程序时,我得到一个-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到语句...或在编译时更改选项.
| 归档时间: |
|
| 查看次数: |
439 次 |
| 最近记录: |