简体   繁体   English

从Java访问iSeries上的RPG

[英]Accessing RPG on iSeries from Java

Has anyone had good experiences of talking direct to RPG programs running on a V5R4 iSeries machine from Java? 有没有人有过直接谈论从Java运行在V5R4 iSeries机器上的RPG程序的好经验? If so, what are the recommendations of the community, and what pitfalls should I try to avoid? 如果是这样,社区的建议是什么,我应该避免哪些陷阱?

From the various pieces of literature and spike solutions I have attempted it looks as though we can use ProgramCallBeans (either through PCML or xPCML), talking to the DataQueues (for asynchronous comms), or even JNI. 从我试过的各种文献和尖峰解决方案看起来好像我们可以使用ProgramCallBeans(通过PCML或xPCML),与DataQueues(用于异步通信),甚至是JNI。

I'm looking for something that's robust, performant, quick to develop, easy to maintain, and easy to test (aren't we all!?!). 我正在寻找一些强大,高效,快速开发,易于维护和易于测试的东西(不是我们所有人!?!)。

I suggest using IBM's Java Toolbox for Java. 我建议使用IBM的Java Toolbox for Java。 Put the JT400.jar into your classpath (or JT400Ntv.jar if the Java is running on the iSeries). 将JT400.jar放入类路径(如果Java在iSeries上运行,则为JT400Ntv.jar)。 I've used both the ProgramCall class and the CommandCall classes. 我已经使用了ProgramCall类和CommandCall类。

The com.ibm.as400.access.CommandCall class is easy to use. com.ibm.as400.access.CommandCall类很容易使用。 It has a simple constructor that you pass a com.ibm.as400.access.AS400 class to. 它有一个简单的构造函数,您可以将com.ibm.as400.access.AS400类传递给它。 Then just use the run method like this: 然后只需使用这样的run方法:

CommandCall command = new CommandCall(as400);
command.run("CPYF FROMFILE(BLAH) TOFILE(BLAHBLAH) CRTFILE(*YES)");

Of course, you wouldn't use that particular CL command, but you get the idea. 当然,你不会使用那个特定的CL命令,但你明白了。 When using the CommandCall class, it's always a good idea to process any messages that came from the command. 使用CommandCall类时,处理来自命令的任何消息始终是个好主意。 In the one program I use this for, I display the messages to the user in a textbox on their screen like this: 在我使用的一个程序中,我在屏幕上的文本框中向用户显示消息,如下所示:

AS400Message[] messageList = command.getMessageList();
for (int i=0;i < messageList.length;i++) {
String sMessageText = messageList[i].getText();
    sMessage+=sMessageText + "\n";
}

The com.ibm.as400.access.ProgramCall class takes more work, but it allows you to access the returned parameters. com.ibm.as400.access.ProgramCall类需要更多工作,但它允许您访问返回的参数。 I use this one more often because I'm usually calling existing RPG worker programs that return values. 我经常使用这个,因为我通常会调用返回值的现有RPG工作程序。 For this, define a com.ibm.as400.access.ProgramParameter array. 为此,请定义com.ibm.as400.access.ProgramParameter数组。 When you pass parameters to a program from Java, remember to convert them to AS/400-friendly values using a class like com.ibm.as400.access.AS400Text. 将参数传递给Java中的程序时,请记住使用com.ibm.as400.access.AS400Text等类将它们转换为AS / 400友好值。 The details of the ProgramCall command are better researched using IBM's documentation: http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/rzahh/page1.htm 使用IBM的文档可以更好地研究ProgramCall命令的详细信息: http//publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic = / rzahh / page1.htm

You should look at JTOpen . 你应该看看JTOpen It is fairly easy to use that to do what you want to do. 使用它来做你想做的事情相当容易。 Here is an example someone has put together: program call to as400 using jtopen 这是一个人放在一起的例子: 使用jtopen程序调用as400

We just use JDBC and stored procedures. 我们只使用JDBC和存储过程。 The stored procedure calls the RPG instead of running SQL. 存储过程调用RPG而不是运行SQL。 I'm not an RPG programmer, but it seems like a very simple interface. 我不是RPG程序员,但它看起来像一个非常简单的界面。 DataQueues are OK, but they aren't as robust as something like JMS (no guaranteed delivery). DataQueues没问题,但它们不像JMS那样强大(没有保证交付)。

It is quite simple to call java methods directly from RPG. 直接从RPG调用java方法非常简单。 I am not sure exactly what you are trying to do, I have made calls directly to java methods several times. 我不确定你要做什么,我已经多次直接调用java方法。

For an example of how this is done. 有关如何完成此操作的示例。 Take a look at RPGMail . 看看RPGMail You can look at the source and see how Aaron used RPG to connect to JavaMail. 您可以查看源代码,了解Aaron如何使用RPG连接到JavaMail。

I've had some success with PCML documents. 我在PCML文档上取得了一些成功。 I decided to use PCML since encoding the commandcall into a string when passing parameters to an RPG program can get really ugly. 我决定使用PCML,因为在将参数传递给RPG程序时将commandcall编码为字符串会变得非常难看。

PCML allows you to somewhat transparently pass java data types to an rpg program as a parameter. PCML允许您稍微透明地将java数据类型作为参数传递给rpg程序。 The drawback is that the xml in the PCML doc becomes a static interface and must be updated if the program is ever updated. 缺点是PCML文档中的xml成为静态接口,如果程序更新,则必须更新。 With the right build tools, it might be pretty straightforward to automate the update of the pcml xml, but right now I'm doing this manually. 使用正确的构建工具,自动更新pcml xml可能非常简单,但是现在我手动执行此操作。

I've used this approach when the rpg program needs to be called from java, and the logic flow is controlled by the java program. 当需要从java调用rpg程序时,我使用了这种方法,逻辑流程由java程序控制。

In a case where the logic flow was controlled by an rpg program, I've used dataqueues for both synchronous and asynchronous calls to java. 在逻辑流程由rpg程序控制的情况下,我使用数据队列来同步和异步调用java。 This required writing a significant amount of code to standardize on how to read and write to dataqueues in a coordinated manner from different programming languages 这需要编写大量代码来标准化如何以不同编程语言的协调方式读取和写入数据队列

Hmm, I'm new here and would vote KC Baltz answer up, but cannot yet. 嗯,我是新来的,会投票给KC Baltz回答,但还不能。 Stored procedures are the way to go. 存储过程是要走的路。 I've used JT open to call programs natively and found issues with the number of parms that could be passed, issues with data types, etc. Once you have an SQL procedure wrapper around your program you'll find the Java support for SQL to be far superior than the java support for native 400 calls. 我已经使用JT open来本地调用程序,并发现可以传递的parms数量问题,数据类型问题等等。一旦你有一个SQL程序包装你的程序,你会发现SQL的Java支持远远优于java支持原生400调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM