AS400 RPG程序没有返回任何内容

时间:2013-07-02 13:21:16

标签: c# ibm-midrange

我有以下代码。该程序刚退出,没有从通话中返回任何值。有什么想法吗?

AS400System system = new AS400System();
system.Define(ConfigurationManager.AppSettings["AS400Server"]);
system.UserID = ConfigurationManager.AppSettings["AS400User"];
system.Password = ConfigurationManager.AppSettings["AS400Password"];
system.IPAddress = "10.98.1.21";
system.Connect(cwbcoServiceEnum.cwbcoServiceRemoteCmd);



if(system.IsConnected(cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 1) {
    Program program = new Program();
    program.LibraryName = "P2PTST";
    program.ProgramName = "AUI0XFR";
    program.system = system;
    program.system.Signon();

    string paramStatus = "A";
    Int64 paramStockItem = Int64.Parse(t.EtagNumber);
    Guid paramGuid = Guid.NewGuid();
    string paramReturn;

    StringConverter stringConverter = new StringConverter();
    ProgramParameters parameters = new ProgramParameters();
    parameters.Append("ApiIGuid", cwbrcParameterTypeEnum.cwbrcInout, 38);
    parameters.Append("StockItemNumber", cwbrcParameterTypeEnum.cwbrcInout, 20);
    parameters.Append("ItemStatus", cwbrcParameterTypeEnum.cwbrcInout, 1);
    parameters.Append("ReturnCode", cwbrcParameterTypeEnum.cwbrcInout, 7);

    parameters["ApiIGuid"].Value = stringConverter.ToBytes(paramGuid.ToString().PadRight(38, ' '));
    parameters["StockItemNumber"].Value = stringConverter.ToBytes(paramStockItem.ToString().PadRight(20, ' '));
    parameters["ItemStatus"].Value = stringConverter.ToBytes(paramStatus.ToString());

    try{
        program.Call(parameters);
        paramReturn = stringConverter.FromBytes(parameters["ReturnCode"].Value);

        system.Disconnect(cwbcoServiceEnum.cwbcoServiceAll);
    }
    catch (Exception ex)
    {
       Console.WriteLine(ex);
    }
}

1 个答案:

答案 0 :(得分:0)

我们刚刚完成了这个并遇到了同样的问题,因此决定创建并使用存储过程在.NET中完成此任务。因为我们担心让400方分配代码来创建存储过程,所以它最终很快就可以在PC端创建程序,然后是我们的远程命令,所以不需要对其进行额外的更改。 400方。

我的环境是Win7 x64,运行VS2012 C#,CAX V7.1,并导入IBM.Data.DB2.iSeries和System.Data;

我需要System.Data作为参数。这最终对于获取数据至关重要!

我发送400两个参数,filesetID和一个名字。我找回了一个号码和一个uuid。 (但他们都是人物!)

它看起来像这样:

    public void RemoteCmd(ref PicMeta pm)
    {
    iDB2Connection cn;
        try
        {
            using (cn = new iDB2Connection("DataSource=<servername/IP>; UserID="<user>"; Password="<pass>";"))
            {
                cn.Open();
                using (iDB2Command cm = cn.CreateCommand())
                {
                    //Place a try/catch here, so it will create the procedure the first time, or any time it has been removed from the 400.  If already set, it will fail, and you'll go directly to the remote command.  
                    try
                    {
                         //Here we create a procedure and execute or continue.
                         cm.CommandText = "CREATE PROCEDURE LIBRARY.SP_PICGETID(INOUT FSET CHAR (1 ), INOUT UNIT CHAR (6 ), INOUT NEXTID CHAR (3 ), INOUT UUID CHAR (36 ))  LANGUAGE RPGLE NOT DETERMINISTIC NO SQL CALLED ON NULL INPUT EXTERNAL NAME LIBRARY.PICGETID PARAMETER STYLE GENERAL";
                         cm.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        Console.Out.WriteLine(ex.Message);
                    }

                    //Continue - create and call the command     
                    //ParameterDirection needs "using System.Data;"
                    cm.CommandTimeout = 0;
                    cm.CommandType = System.Data.CommandType.StoredProcedure;
                    cm.CommandText = "LIBRARY.SP_PICGETID";

                    iDB2Parameter p = new iDB2Parameter();
                    p.ParameterName = "FSET";
                    p.Direction = ParameterDirection.Input;
                    p.iDB2DbType = iDB2DbType.iDB2Char;
                    p.Size = 1;
                    p.iDB2Value = pm.fileset;
                    cm.Parameters.Add(p);

                    p = new iDB2Parameter();
                    p.ParameterName = "UNIT";
                    p.Direction = ParameterDirection.Input;
                    p.iDB2DbType = iDB2DbType.iDB2Char;
                    p.Size = 6;
                    p.iDB2Value = pm.unit;
                    cm.Parameters.Add(p);

                    p = new iDB2Parameter();
                    p.ParameterName = "NEXTID";
                    p.Direction = ParameterDirection.InputOutput;
                    p.iDB2DbType = iDB2DbType.iDB2Char;
                    p.Size = 3;
                    p.iDB2Value = "";
                    cm.Parameters.Add(p);

                    p = new iDB2Parameter();
                    p.ParameterName = "GUUID";
                    p.Direction = ParameterDirection.InputOutput;
                    p.iDB2DbType = iDB2DbType.iDB2Char;
                    p.Size = 36;
                    p.iDB2Value = "";
                    cm.Parameters.Add(p);

                    cm.ExecuteNonQuery();

                    iDB2ParameterCollection pc = cm.Parameters;

                    //We get our Out parameters here 
                    pm.nextid = pc["NEXTID"].Value.ToString();
                    pm.uuid = pc["GUUID"].Value.ToString();
                }
                cn.Close();
            }
        }
        catch (Exception e)
        {
            Console.Out.WriteLine(e.Message);
        }
        return;
    }

希望这有帮助!

相关问题