我希望将游标和数据结构传递给一个过程,然后该过程使用sql游标中的下一行填充该结构。这个是可能的吗?下面是我试图实现的一个模板。
*****************************************************
*
* Fetch the next row from a cursor
*
* @param cursor - the name of the cursor
* @param structure - the data structure to hold the fields
*****************************************************
pfetchNextRow B
DfetchNextRow PI N
d cursor 32767A varying const
d structure DS ???????
/free
exec sql
fetch next from :cursor into :structure
;
if (sqlstate = SQL_SUCCESS);
return *on;
else;
exec sql
close :cursor;
return *off;
endif;
/end-free
pfetchNextRow E我应该如何传递游标,以及如何定义数据结构参数?
发布于 2011-12-22 19:35:22
我不知道你是否在其他网站上收到了答案,但其他人可能需要它。
游标“全局”存在,但只存在于声明它们的模块中,您不需要将其传递给此模块中的过程,您声明的游标始终可用,直到它关闭或作业结束。
您可以这样做(仅当您在同一模块中时):
P SQLprep_mC B EXPORT
D SQLprep_mc PI Like(g_retCode)
D strInSQL Like(string_MAX_V)
/Free
exec SQL
SET OPTION
CLOSQLCSR = *ENDACTGRP;
exec sql prepare p1 from :strINsql ;
//.... declare and open
/End-Free
P SQLprep_mC E
P SQLfetch_mC_st B EXPORT
D SQLfetch_mC_st PI Like(g_retCode)
D Row LikeDs(dsSql_0)
D NullI Like(sqlNI_0) Dim(DSSql0_nFields)
D Rowmc_b DS LikeDs(dsSql_0) Based(pNull1)
D Rowmc DS LikeDs(dsSql_0)
D pNUll1 s * inz(%ADDR(Rowmc))
D SQLind s Like(sqlNI_0) Based(pNull2)
D NullImc S like(SQLind) Dim(DSSql_nFields)
D pNull2 s * inz(%ADDR(NullImc))
/free
exec SQL fetch next from mC into :Rowmc :NullImc ;
Row = Rowmc ;
NullI = NullImc ;
/end-free
P SQLfetch_mC_st E 这两个过程使用相同的游标"mC“,并且在相同的模块中。第一次准备、声明和打开游标,第二次读取RowMC中的行。
正如您所看到的,用于fetch的DS是基于的,NULLindicator数组也是如此。
所有的Like和LikeDS参数都在复制文件中定义为模板,如下所示:
D comfraf e DS extname(comfra00f) QUALIFIED TEMPLATE
D dsSql_0 DS Qualified TEMPLATE
D cid like(comfraf.cid )
D ccap like(comfraf.ccap )
D sqlNI_0 s 5I 0 TEMPLATE 希望这能对某些人有所帮助。
发布于 2011-06-15 21:25:49
我不确定您是否可以动态定义游标。问这个问题的一个好地方是在RPG400-L上。在这个列表中,RPG编译器团队的一些成员经常回答这样的问题。
https://stackoverflow.com/questions/6354156
复制相似问题