【发布时间】:2025-12-17 02:55:01
【问题描述】:
我正在尝试从 JAVA 调用 AS400 系统上的 RPG Logon 程序。问题是每当我提供不正确的参数时,我都会收到响应,例如用户 ID 不正确,密码不正确。当我给程序提供不正确的路径时,我确实收到“对象不存在”的响应。但是,当所有参数都正确时,我没有得到任何响应,并且 java 程序继续运行而没有结束。有什么问题?代码如下:
import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Message;
import com.ibm.as400.access.AS400SecurityException;
import com.ibm.as400.access.ErrorCompletingRequestException;
import com.ibm.as400.access.ObjectDoesNotExistException;
import com.ibm.as400.access.ProgramCall;
import com.ibm.as400.access.ProgramParameter;
import java.beans.PropertyVetoException;
import java.io.IOException;
/**
* Test program to test the RPG call from Java.
*/
public class CallingAS400PGM {
private static final String HOST = "xxxxxx";
private static final String UID = "yyyyyyy";
private static final String PWD = "zzzzzzz";
public static void main(String[] args) {
String input = "testuser";
String fullProgramName = "/QSYS.lib/SEOBJP10.lib/LOGON.pgm";
AS400 as400 = null;
byte[] inputData;
byte[] outputData;
ProgramParameter[] parmList;
ProgramCall programCall;
try {
// Create an AS400 object
as400 = new AS400(HOST, UID, PWD);
// Create a parameter list
// The list must have both input and output parameters
parmList = new ProgramParameter[2];
// Convert the Strings to IBM format
inputData = input.getBytes("IBM285");
// Create the input parameter
parmList[0] = new ProgramParameter(inputData);
// Create the output parameter
//Prarameterised Constructor is for the OUTPUT LENGTH. here it is 10
parmList[1] = new ProgramParameter(10);
/**
* Create a program object specifying the name of the program and
* the parameter list.
*/
programCall = new ProgramCall(as400);
programCall.setProgram(fullProgramName, parmList);
// Run the program.
if (!programCall.run()) {
/**
* If the AS/400 is not run then look at the message list to
* find out why it didn't run.
*/
AS400Message[] messageList = programCall.getMessageList();
for (AS400Message message : messageList) {
System.out.println(message.getID() + " - " + message.getText());
}
} else {
/**
* Else the program is successfull. Process the output, which
* contains the returned data.
*/
System.out.println("CONNECTION IS SUCCESSFUL");
outputData = parmList[1].getOutputData();
String output = new String(outputData, "IBM285").trim();
System.out.println("Output is " + output);
}
} catch (PropertyVetoException | AS400SecurityException | ErrorCompletingRequestException | IOException | InterruptedException | ObjectDoesNotExistException e) {
System.err.println(":: Exception ::" + e.toString());
} finally {
try {
// Make sure to disconnect
if (as400 != null) {
as400.disconnectAllServices();
}
} catch (Exception e) {
System.err.println(":: Exception ::" + e.toString());
}
}
}
}
【问题讨论】:
-
您没有在
LOGON.PGM上向我们提供任何信息。您确定是 Java 没有结束地运行,还是LOGON正在运行并等待某些东西,也许是用户输入。我在 Java 中没有看到任何循环 -
嘿伙计们,这确实是由于 LOGON.pgm 正在等待一些输入。我使用了 PCML 方法来传递输入,并且能够成功调用程序。谢谢@jmarkmurphy
-
@Bazooka 使用了哪个 jar,能否请您提供用于实现此目的的 jar 列表,我们需要从 Java 调用 RPG 程序
标签: java ibm-midrange rpg