【发布时间】:2018-10-25 06:43:09
【问题描述】:
大家好,
我正在编写一个程序来构建一个报告,我在其中构建 SQL 语句以将选定的记录插入到文件中,然后插入之后我想对文件进行简单的更新以更改某些记录中的选择字段。
问题是在插入运行后,每当我尝试更新文件时,我都会收到记录或文件正在使用错误。
我尝试使用 sqlrpgle 以及 I/O 读取和设置函数以编程方式更新它,我什至尝试在运行程序后更新 STRSQL 中的文件,但我都遇到了同样的错误。
我怀疑我没有正确关闭某些东西,但我不确定是什么。
代码如下
// Assign SQL Query
sqlstmt = 'insert into jallib/orhsrpt ('+
'oacctd, oacmp, oaord, oacust, o8type, ' +
'o8text, o8date, o8time ) ' +
'select oacctd, oacmp, oaord, oacust, ' +
'o8type, o8text, o8date, o8time ' +
'from r50files.vcohead ' +
'join r50files.vcopkct ' +
'on oacmp = o8cmp and oaord = o8ord ' +
'where oacmp = 1 ' +
'and o8type not in (' +
'''C'',''a'',''H'',''E'',''F'', '+
'''A'',''1'',''N'',''M'') ' +
'and oacctd = ' + curdate +
' order by oaord, o8time ';
// Prepare for multiple sql statements
exec sql
Set Option Commit = *NONE;
// Clear output file before executing SQL
exec sql
Delete from jallib/orhsrpt;
if sqlcode < *zeros;
errmsg = 'Delete of file failed';
endif;
// Execute SQL Insert statement
exec sql prepare sqlsel from :sqlstmt;
exec sql execute sqlsel;
if sqlcode < *zeros;
errmsg = 'Insert of file failed';
endif;
// Update file data
exec sql
Set Option clossqlcsr = *ENDMOD;
exec sql
Update jallib/orhsrpt
set o8text = 'Order Invoiced'
where o8type = 'I'
STRSQL报错如下
JALLIB 类型 *FILE 中的行或对象 ORHSRPT 正在使用中。
【问题讨论】:
-
您是否在插入后使用显式提交语句尝试过这个?
标签: sql db2 ibm-midrange rpgle