DB2 SQLCode -7008

DB2 SQLCode -7008

我正在使用 sqlrgple 程序将 select 条记录插入一个文件,然后我将其输出给用户。请参阅下面的代码片段

// 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) 并且所讨论的 table(文件)未记录。

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