如何使用ifs_read& IFS_WRITE服务?
最近,我听说了IBM I(以前称为/400或ISERIES)的“新” IFS_READ和IFS_WRITE服务。我找不到他们的文档,而且我发现的大部分内容都一般而言。更详细的少数资源完全集中在RPG上,但我想在Ile Cobol中使用它们。
这是可能的,如果是的话,如何?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ifs_read
和ifs_write
有时很难找到API,以及如何使用它们完全不同的手册,所以让我在将其拉动时,让我搭配你。这两个API都是I服务的DB2。这些文档不在数据库参考主题中,而是在数据库性能和查询优化主题中找到: https://www.ibm.com/docs/docs/docs/en/en/i/7.topic = is-- ifs-read-ifs-read-binary-ifs-read-utf8-table-unctions
您会注意到
ifs_read
服务是表函数,而ifs_write 服务是一个存储的过程,因此要从IFS中读取,您可以使用SELECT,但要写入IFS,您需要使用呼叫。顺便说一句,由于您必须使用呼叫,因此几乎可以轻松地简单地使用
fwrite 和fopen
,fread
,fwrite
fwritefclose
。您只需要为它们创建COBOL链接类型定义即可。我会把它留给您,因为这不是这个问题的话题。因此,下一个问题是我们如何将SQL嵌入COBOL中。这在另一本手册中描述: https://www.ibm.com/docs/en/i/7.4?topic = programproging-coding-sql-statement-sql-statement-in-cobol-applications
conthell you n no Cithell you nour sql you sql
exec-sql
和end-sql
。但是,还有更多。由于表函数可以返回多个行,因此您不能仅使用选择
,因此您需要打开光标,从光标获取,然后关闭光标。类似的内容:
可以在SQL参考中找到SQL语句的语法: https://www.ibm.com/docs/en/i/7.4?topic=Reference-Statements
ifs_write
有些相似,但是您需要放置SQL打电话给循环。现在,您可能会注意到这里没有错误处理。除非您陷入困境,否则SQL会忽略大多数错误,我将把它留给您。
The
IFS_READ
andIFS_WRITE
API's are sometimes difficult to find, and how to use them would be in an entirely different manual, so let me take a crack at pulling it all together for you.Both of these API's are DB2 for i services. The documentation for these are not in the Database reference topic, but in the Database performance and query optimization topic found here: https://www.ibm.com/docs/en/i/7.4?topic=is-ifs-read-ifs-read-binary-ifs-read-utf8-table-functions
You will notice that the
IFS_READ
service is a table function, and theIFS_WRITE
service is a stored procedure, so to read from the IFS, you can use a select, but to write to the IFS, you will need to use a call. Incidentally, since you would have to use a call, you could almost as easily simply use the stream file functions from C which arefopen
,fread
,fwrite
, andfclose
. You just need to create COBOL LINKAGE TYPE definitions for them. I will leave that to you since it is not the topic of this question.So the next question is how do we embed SQL into COBOL. That is described in a different manual: https://www.ibm.com/docs/en/i/7.4?topic=programming-coding-sql-statements-in-cobol-applications
In a nutshell you will surround your sql with
EXEC-SQL
andEND-SQL
. But wait there's more. Since the table function can return multiple rows, you can't just use aSELECT INTO
, you need to open a cursor, fetch from the cursor, then close the cursor.Something like this:
The syntax for SQL statements can be found in the SQL Reference: https://www.ibm.com/docs/en/i/7.4?topic=reference-statements
IFS_WRITE
is somewhat similar, but you will need to put your SQL call in a loop.Now you might notice that there is no error handling here. SQL will ignore most errors unless you trap them, I will leave that to you.