java - 从JAVA调用AS400 RPG程序

标签 java ibm-midrange rpg

我正在尝试从JAVA调用AS400系统上的RPG登录程序。问题是每当我提供不正确的参数时,我都会收到响应,例如用户 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());
            }
        }
    }
}

最佳答案

Carefully think about what parameter type,number of parameters are accepting from AS400 RPG program, and use communication only USERID.

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Message;
import com.ibm.as400.access.AS400Text;
import com.ibm.as400.access.ProgramCall;
import com.ibm.as400.access.ProgramParameter;

public class CallingAS400PGM {

private static final String HOST = "192.168.1.1";//AS400 IP
private static final String UID = "UNAME"; //userid
private static final String PWD = "PWORD"; //password

public static void main(String[] args) {
//AS400 RPG progam path
String fullProgramName = "/QSYS.LIB/PBFORM12.LIB/PBFORM12CL.PGM";

AS400 as400 = null;
ProgramParameter[] parmList;//parameter list witch is accepting AS400 RPG program
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
    AS400Text nametext1 = new AS400Text(2);
    AS400Text nametext2 = new AS400Text(200);

    // Create the input parameter // get the exact patameter type and 
    length, if not this not be working  
    parmList[0] = new ProgramParameter(nametext1.toBytes("1"),2);
    parmList[1] = new ProgramParameter(nametext2.toBytes("Ravinath 
    Fernando"),200);
    // Create the output parameter

    programCall = new ProgramCall(as400);
    programCall.setProgram(fullProgramName, parmList);

    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 {
        System.out.println("success");
        /**
         * Else the program is successfull. Process the output, which
         * contains the returned data.
         */
        //use same parameter type which will be return from AS400 program
        AS400Text text1 = new AS400Text(2);
        System.out.println(text1.toObject(parmList[0].getOutputData()));
        AS400Text text2 = new AS400Text(200);
        System.out.println(text2.toObject(parmList[1].getOutputData()));
    }
    as400.disconnectService(AS400.COMMAND);
    //-----------------------
} catch (Exception e) {
    e.printStackTrace();
    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());
    }
}
}
}

关于java - 从JAVA调用AS400 RPG程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49571385/

相关文章:

java - 在 json 的列表字段中显示数据和图像,就像延迟加载黑莓一样

java - 在不使文本变灰的情况下在 JTextField 中设置文本颜色

javascript - AS/400数据队列可以访问node-jt400吗? (javascript)

ibm-midrange - 使用一行设置 %nullind rpg

java - RPG iSeries 从 Java 函数中获取 byte[] 中的 PDF 并将其写入 IFS

java - 每个 war 文件没有 JVM 实例?

java - 如何实现android Activity的代码复用?

shell - 在 IBM i - shell 上将文件列表中的文件存储在 tarball 中

c - 如何防止 C read() 从缓存中读取