I suggest using the IBM Java Toolbox for Java. Put JT400.jar in your classpath (or JT400Ntv.jar if Java is running on iSeries). I used both the ProgramCall class and the CommandCall classes.
The com.ibm.as400.access.CommandCall class is easy to use. It has a simple constructor by which you pass the class com.ibm.as400.access.AS400. Then just use the run method as follows:
CommandCall command = new CommandCall(as400); command.run("CPYF FROMFILE(BLAH) TOFILE(BLAHBLAH) CRTFILE(*YES)");
Of course, you will not use this particular CL command, but you will get this idea. When using the CommandCall class, it is always useful to handle any messages coming from the command. In one program, I use this, I display messages to the user in a text box on their screen as follows:
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 does more work, but allows access to the returned parameters. I use this even more often because I usually call existing RPG work programs that return values. To do this, define an array com.ibm.as400.access.ProgramParameter. When you pass parameters to a program from Java, be sure to convert them to values โโcompatible with AS / 400 using the com.ibm.as400.access.AS400Text class. The details of the ProgramCall team are better explored using IBM documentation: http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/rzahh/page1.htm
Tracy probst
source share