[英]Call AS400 RPG from SQL Server returning parameter
In my SQL Server instance I have a linked server to AS400.在我的 SQL 服务器实例中,我有一个到 AS400 的链接服务器。
I want to exec a CLP program that takes 2 parameters, a numeric(8,0)
as input and an alphanumeric(3)
as output.我想执行一个 CLP 程序,它需要 2 个参数,一个
numeric(8,0)
作为输入,一个alphanumeric(3)
作为 output。
These are SQL commands that I use to do it:这些是我用来执行此操作的 SQL 命令:
DECLARE @Ret varchar(3)
DECLARE @Date varchar(8)
SET @Date = '20200721'
SET @Ret = ' '
EXEC ('CALL IASP01.WUTL.WUTL46(''' + @Date + ''', ''?'')', @Ret) AT AS400
SELECT @Ret
The command is executed without errors, but no results are returned.该命令执行没有错误,但没有返回任何结果。
The second parameter is a varchar(3)
param because AS400 expects an alphanumeric parameter to return result but it's always empty.第二个参数是
varchar(3)
参数,因为 AS400 需要一个字母数字参数来返回结果,但它始终为空。
Can anyone help me?谁能帮我?
Thanks in advance提前致谢
UPDATE:更新:
I also tried to create a simple CLP that accepts only 1 parameter and modifies its value.我还尝试创建一个仅接受 1 个参数并修改其值的简单 CLP。 Following is the simple CLP code:
以下是简单的 CLP 代码:
PGM PARM(&DATA)
DCL VAR(&DATA) TYPE(*DEC) LEN(8 0)
CHGVAR VAR(&DATA) VALUE(20200722)
ENDPGM
It's a very simple program that accepts a numeric(8,0) parameter and modifies it's value.这是一个非常简单的程序,它接受一个 numeric(8,0) 参数并修改它的值。
And here's the Sql Server code that I use to execute DB2 RPG:这是我用来执行 DB2 RPG 的 Sql 服务器代码:
declare @P1 numeric(8, 0) select @P1 = 00000000声明@P1 数字(8, 0) select @P1 = 00000000
exec ('CALL.<RPG_Name>(''?'')', @P1 OUTPUT) AT AS400 select @P1 exec ('CALL.<RPG_Name>(''?'')', @P1 OUTPUT) AT AS400 select @P1
The execution succeeded without errors.执行成功,没有错误。 After this call, the @P1 variable contains the initial value and not the modified value, so I'm not able to get the "return" value in Sql Server after this call.
在此调用之后,@P1 变量包含初始值而不是修改后的值,因此在此调用之后我无法在 Sql 服务器中获取“返回”值。 How can I do it?
我该怎么做?
Or how can I return a value from CLP to Sql Server?或者如何将 CLP 中的值返回到 Sql 服务器?
Thanks谢谢
Try creating a stored procedure definition in DB2.尝试在 DB2 中创建存储过程定义。 I am surprised it works at all without that, but maybe DB2 is smart enough to call the program on a call with default parameter definitions.
如果没有它,我很惊讶它完全可以工作,但也许 DB2 足够聪明,可以使用默认参数定义调用程序。 Unfortunately the default parameter definitions are Input only.
不幸的是,默认参数定义仅为输入。
You can find documentation in the Knowledge Base .您可以在知识库中找到文档。 But it goes something like this:
但它是这样的:
CREATE PROCEDURE SIMPLE_CLP
(INOUT DATA DECIMAL(8, 0))
LANGUAGE CL
PARAMETER STYLE GENERAL
DETERMINISTIC
NO SQL
EXTERNAL NAME 'SIMPLE_CLP';
Then you should be able to use INOUT parameters.然后你应该能够使用 INOUT 参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.