从 Java 调用 AS400 RPG

发布于 2024-08-18 12:59:03 字数 1473 浏览 1 评论 0原文

我对AS400和RPG的了解非常有限。但我们有一个要求,需要从 Java 类调用 RPG 程序。所以我发现我们可以通过JTOpen来实现。但我坚持声明 ProgramParameter 列表。我有以下关于RPG程序的信息

程序名称:ZM30000R 参数: 分支 7,0(数字)
账户类型2(01-支票,02储蓄)
帐号 20(字符)
错误代码7(字符) DR/CR 指示符 1(字符 D、C)

但不知道输入和输出是什么。如何声明ProgramParameter?我已经做了如下。我也无法进行测试,因为我没有与这些系统的连接。

          // Create AS400 Text objects for the different lengths
          // of parameters you are sending in.
          AS400Text branchTxt = new AS400Text(7);
          AS400Text accntTypeTxt = new AS400Text(2);
          AS400Text accntNumberTxt = new AS400Text(20);
          AS400Text errorCodeTxt = new AS400Text(7);
          AS400Text DCIndicatorTxt = new AS400Text(1);            
          
          // declare and instantiate  your parameter list.
          ProgramParameter[] parmList = new ProgramParameter[5];
          
          // assign values to your parameters using the AS400Text class to convert to bytes
          // the second parameter is an integer which sets the length of your parameter output
          parmList[0] = new ProgramParameter( branchTxt.toBytes(branch),7);
          parmList[1] = new ProgramParameter( accntTypeTxt.toBytes(accntTypeTxt),2);      
          parmList[2] = new ProgramParameter( accntNumberTxt.toBytes(accntNumberTxt),20);      
          parmList[3] = new ProgramParameter( errorCodeTxt.toBytes(""),7);      
          parmList[4] = new ProgramParameter( DCIndicatorTxt.toBytes(indicator),5);

I have a very limited knowledge on AS400 and RPG. But we have a requirement where we need to invoke a RPG program from a Java class. So I found that we can achieve it through JTOpen. But I am stuck at declaring the ProgramParameter list. I have the following information about RPG Program

Program name: ZM30000R
Parameters:
Branch 7,0 (Numeric)
Account type 2 (01-cheque,02 savings)
Account Number 20 (character)
Error code 7 (character)
DR/CR indicater 1 (character D,C)

But no clue about what is the input and output. How to declare the ProgramParameter? I have done as below. I cannot test as well because I don't have connectivity to these systems.

          // Create AS400 Text objects for the different lengths
          // of parameters you are sending in.
          AS400Text branchTxt = new AS400Text(7);
          AS400Text accntTypeTxt = new AS400Text(2);
          AS400Text accntNumberTxt = new AS400Text(20);
          AS400Text errorCodeTxt = new AS400Text(7);
          AS400Text DCIndicatorTxt = new AS400Text(1);            
          
          // declare and instantiate  your parameter list.
          ProgramParameter[] parmList = new ProgramParameter[5];
          
          // assign values to your parameters using the AS400Text class to convert to bytes
          // the second parameter is an integer which sets the length of your parameter output
          parmList[0] = new ProgramParameter( branchTxt.toBytes(branch),7);
          parmList[1] = new ProgramParameter( accntTypeTxt.toBytes(accntTypeTxt),2);      
          parmList[2] = new ProgramParameter( accntNumberTxt.toBytes(accntNumberTxt),20);      
          parmList[3] = new ProgramParameter( errorCodeTxt.toBytes(""),7);      
          parmList[4] = new ProgramParameter( DCIndicatorTxt.toBytes(indicator),5);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

酒浓于脸红 2024-08-25 12:59:03

嗯,仅通过参数的描述我就知道了。分行、账户类型和账号均为 IN。您需要该信息来进行财务预订或交易。错误代码显然是 OUT。根据我对金融系统的经验,API 返回预订金额的方式是合理正常的。通常人们会使用该符号,但在金融系统中,(D)ebit 或 (C)redit 是更好的方式。

该API很可能是金融系统的API。如果这是真的,那么我就错过了这笔钱。您确定您有完整的描述吗?

请注意,第一个参数是数字。你不走运。 iSeries 和 RPG 对数字类型的宽容程度不太高。可以从位、分区、打包、十进制、整数、浮点等中进行选择。如果 RPG 确实是 RPG 而不是 ILE RPG,那么您可以将其归结为分区、打包和字节。

我假设您可以访问 iSeries。然后就可以观看程序调用、调试信息和转储信息。如果您必须进行“反复试验”,这将对您有所帮助。如果没有通道,路就会很艰难。如果程序调用不成功,您将在 java 类中收到错误。但如果没有来自 iSeries 的信息,您将很难确定真正的错误。因此,确实需要访问。

Well, I do have a clue just by the description of the parameters. Branch, account type and account number are IN. You need that information for a financial booking or transaction. The error code is appearently OUT. In my experience with financial systems it's reasonable normal that the API returns the way the amount is booked. Normally one would use the sign, but in financial systems the (D)ebit or (C)redit is the better way.

The API is very likely the API of a financial system. If that is true, then I'm missing the amount. Are you sure you've the complete description?

Notice that the first parameter is numeric. You're not in luck. The iSeries and RPG are not very forgiving about the type of a numeric. One can choose from Bit, Zoned, Packed, Decimal, Integer, Float and so on. If the RPG is really RPG instead of ILE RPG, then you can bring that down to Zoned, Packed and Byte.

I assume you've access to the iSeries. Then you can watch the program call, debug information and dump information. That will help you if you have to do "trial and error". If you don't have access, the road will be very hard. You'll receive an error in your java class if the program call is not succesfull. But it will be hard to identify the real error without the information from the iSeries yourself. Therefore, access is really required.

oО清风挽发oО 2024-08-25 12:59:03

您的样本大部分都在正确的轨道上。但你的分支参数是数字。因此,您应该使用 AS400ZonedDecimal 而不是 AS400Text:

AS400ZonedDecimal branchNbr = new AS400ZonedDecimal(7,0)

RPG 程序可能需要打包而不是分区。没什么大不了的,只需使用 AS400PackedDecimal 即可。

当您构造 ProgramParameter 对象时,构造函数的要求会有所不同,具体取决于它们是程序的输入参数还是输出参数。对于输入参数,只需传递 toBytes() 结果即可。无需包含长度。对于仅输出参数,只需传递长度。

我同意罗伯特的回答,即缺少一些信息,但他对错误代码输出的假设似乎是有效的。但是,我猜测输入了 DCIndicator 参数,因为您的示例传递了一个值。对于错误代码参数,在程序调用之后,您需要提取该值并对其执行某些操作。根据您已经掌握的内容,程序调用的工作方式如下。请注意,我指定了库名称“MyLibrary”。这是出于示例目的。您必须确定您的程序对象位于哪个库中。

ProgramCall pgm = new ProgramCall(as400, QSYSObjectPathName.toPath("MyLibrary","ZM30000R","PGM"), parmList);
if (pgm.run() == true) {
    String sErrorCode = (String) errorCodeTxt.toObject(parmList[3].getOutputData());

    //Do something with your output data.
}
else {
    AS400Message[] messageList = pgm.getMessageList();
    for (int i=0; i<messageList.length; i++) {
        String sMessageID = messageList[i].getID();
        String sMessageText = messageList[i].getText();

        //Do something with the error messages
    }
}

还需要考虑库列表。 RPG 程序是否期望某些库出现在库列表中?如果是这样,您应该在调用程序之前发出 CommandCalls 将库添加到库列表中。

Your sample is mostly on the right track. But your branch parameter is numeric. So you should use AS400ZonedDecimal instead of AS400Text:

AS400ZonedDecimal branchNbr = new AS400ZonedDecimal(7,0)

The RPG program may be expecting packed instead of zoned. No big deal, just use AS400PackedDecimal instead.

As you construct your ProgramParameter object, your constructor requirements are different depending on if they are input or output parameters to your program. For input parameters, just pass the toBytes() results. There is no need to include the length. For output-only parameters, just pass the length.

I agree with Robert's answer that there is some missing information, but his assumptions on the outputness of the error code seems valid. I would guess, however, that the DCIndicator parameter is input since your sample passes a value. For the error code parameter, after your program call, you'll need to extract the value and do something with it. Given what you have already, here is how the program call would work. Take note that I specified a library name of "MyLibrary". That is for example purposes. You will have to determine which library your program object is in.

ProgramCall pgm = new ProgramCall(as400, QSYSObjectPathName.toPath("MyLibrary","ZM30000R","PGM"), parmList);
if (pgm.run() == true) {
    String sErrorCode = (String) errorCodeTxt.toObject(parmList[3].getOutputData());

    //Do something with your output data.
}
else {
    AS400Message[] messageList = pgm.getMessageList();
    for (int i=0; i<messageList.length; i++) {
        String sMessageID = messageList[i].getID();
        String sMessageText = messageList[i].getText();

        //Do something with the error messages
    }
}

Something else to consider is library lists. Does the RPG program expect certain libraries to be in the library list? If so, you should issue CommandCalls to add the libraries to the library list before calling the program.

你的背包 2024-08-25 12:59:03

FWIW:调用 IBM i 主机程序和应用程序要容易得多。使用 PCML 而不是 ProgramCall 的服务程序。

编译器甚至会为您生成 PCML 文档。

请参阅 http://javadoc.midrange.com/jtopen/com /ibm/as400/data/ProgramCallDocument.html 了解详细信息。

FWIW: It's a lot easier to call IBM i host programs & service programs using PCML rather than ProgramCall.

The compilers will even generate the PCML document for you.

See http://javadoc.midrange.com/jtopen/com/ibm/as400/data/ProgramCallDocument.html for details.

旧人 2024-08-25 12:59:03

如果您没有连接,那么您确实无法执行所要求的操作。你如何测试它?参数是数字还是字符?

If you don't have connectivity, then you really can't do what is asked. How do you test it? Is there numeric parameters or are they all character?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文