DB2 SQL代码-7008

时间:2018-11-29 20:06:58

标签: ibm-midrange db2-400 rpgle

我正在使用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无效用于操作”

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

根据文档,我应该在此之后获得原因代码,但我没有。

当我调试程序以确保查询正确时。我在执行之前先取sqlstmt的值,然后按原样尝试在STRSQL中使用该语句,并且效果很好。

文件SBLBRPT也位于库列表中。

我之前已经做过这样的程序,但是还没有遇到此错误,我不确定如何解决。任何帮助将不胜感激

1 个答案:

答案 0 :(得分:5)

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

同样,您在CRTSQLRPGI命令上采用了默认值,即COMMIT(* CHG),并且所涉及的表(文件)未记录日志。

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