从Java调用AS/400 RPG程序 [英] Calling AS/400 RPG Programs from Java

查看:112
本文介绍了从Java调用AS/400 RPG程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Java调用AS/400 RPG程序,但遇到以下错误

com.ibm.as400.data.PcmlException:接收到异常:[com.ibm.as400.access.ObjectDoesNotExistException]/QSYS.LIB/%LIBL%.LIB/GETKURSJAV.PGM:对象不存在.在com.ibm.as400.data.ProgramCallDocument.callProgram(ProgramCallDocument.java:458)在CallRPG.main(CallRPG.java:34)引起原因:com.ibm.as400.access.ObjectDoesNotExistException:/QSYS.LIB/%LIBL%.LIB/GETKURSJAV.PGM:对象不存在.在com.ibm.as400.access.RemoteCommandImplRemote.runProgramOffThread(RemoteCommandImplRemote.java:595)在com.ibm.as400.access.RemoteCommandImplRemote.runProgram(RemoteCommandImplRemote.java:532)在com.ibm.as400.access.ProgramCall.run(ProgramCall.java:780)在com.ibm.as400.data.PcmlProgram.callProgram(PcmlProgram.java:681)在com.ibm.as400.data.PcmlDocument.callProgram(PcmlDocument.java:462)在com.ibm.as400.data.ProgramCallDocument.callProgram(ProgramCallDocument.java:445)...还有1个

这是我的Java代码

  import com.ibm.as400.access.AS400;导入com.ibm.as400.access.AS400Message;导入com.ibm.as400.access.ProgramParameter;导入com.ibm.as400.data.PcmlException;导入com.ibm.as400.data.ProgramCallDocument;公共课程CallRPG {公共静态void main(String [] args){//TODO自动生成的方法存根AS400 as400 = null;字符串主机="10.2.62.7";字符串用户名="USERNAME";字符串密码="PASSWORD";as400 =新的AS400(主机,用户名,密码);if(as400 == null){System.out.println(连接失败");} 别的 {System.out.println(连接成功");}ProgramCallDocument pcml;尝试 {pcml =新的ProgramCallDocument(as400,"getkursjav.pcml");pcml.setValue("GETKURSJAV.CCCKRS","51");pcml.setValue("GETKURSJAV.IDXKRS","5");//调用程序布尔值rc = pcml.callProgram("GETKURSJAV");如果(rc == false){System.out.println(程序失败");} 别的 {int outputData =(int)pcml.getValue("GETKURSJAV.ZRTNKRS");System.out.println(outputData/100000);}} catch(PcmlException pe){System.out.println(捕获的异常");pe.printStackTrace();} 最后 {System.exit(0);}}} 

这是我的pcml文件

 < pcml版本="4.0"><程序名称="GETKURSJAV" path ="/QSYS.LIB/%LIBL%.LIB/GETKURSJAV.PGM"><数据名称="CCCKRS"类型="packed"长度="2" precision ="0"用法=输入"/>< data name ="IDXKRS" type ="packed" length ="2" precision ="0"用法="input"/><数据名称="ZRTNKRS"类型="char"长度="10"用法=输出"/></程序></pcml> 

我的代码有什么问题?我需要在我的Java代码中添加as400 CURLIB和PRGLIB吗?如果是,如何添加库?

解决方案

根据本文,

我会尝试只使用
path ="/QSYS.LIB/%LIBL%/GETKURSJAV.PGM"

I want to call AS/400 RPG Programs from java, but I'm facing an error as below

com.ibm.as400.data.PcmlException: Exception received: [com.ibm.as400.access.ObjectDoesNotExistException] /QSYS.LIB/%LIBL%.LIB/GETKURSJAV.PGM: Object does not exist. at com.ibm.as400.data.ProgramCallDocument.callProgram(ProgramCallDocument.java:458) at CallRPG.main(CallRPG.java:34) Caused by: com.ibm.as400.access.ObjectDoesNotExistException: /QSYS.LIB/%LIBL%.LIB/GETKURSJAV.PGM: Object does not exist. at com.ibm.as400.access.RemoteCommandImplRemote.runProgramOffThread(RemoteCommandImplRemote.java:595) at com.ibm.as400.access.RemoteCommandImplRemote.runProgram(RemoteCommandImplRemote.java:532) at com.ibm.as400.access.ProgramCall.run(ProgramCall.java:780) at com.ibm.as400.data.PcmlProgram.callProgram(PcmlProgram.java:681) at com.ibm.as400.data.PcmlDocument.callProgram(PcmlDocument.java:462) at com.ibm.as400.data.ProgramCallDocument.callProgram(ProgramCallDocument.java:445) ... 1 more

and this is my java code

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Message;
import com.ibm.as400.access.ProgramParameter;
import com.ibm.as400.data.PcmlException;
import com.ibm.as400.data.ProgramCallDocument;

public class CallRPG {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    AS400 as400 = null;

    String host = "10.2.62.7";
    String username = "USERNAME";
    String password = "PASSWORD";

    as400 = new AS400(host, username, password);

    if (as400 == null) {
        System.out.println("Connection Failed");
    } else {
        System.out.println("Connection Success");
    }
    ProgramCallDocument pcml;

    try {
        pcml = new ProgramCallDocument(as400, "getkursjav.pcml");
        pcml.setValue("GETKURSJAV.CCCKRS", "51");
        pcml.setValue("GETKURSJAV.IDXKRS", "5");

        // call the program
        boolean rc = pcml.callProgram("GETKURSJAV");
        if (rc == false) {
            System.out.println("Program failed");
        } else {

            int outputData = (int) pcml.getValue("GETKURSJAV.ZRTNKRS");
            System.out.println(outputData / 100000);            
        }
    } catch (PcmlException pe) {
        System.out.println(" Caught Exception ");
        pe.printStackTrace();
    } finally {
        System.exit(0);
    }

}

}

and this is my pcml file

<pcml version="4.0">
   <program name="GETKURSJAV" path="/QSYS.LIB/%LIBL%.LIB/GETKURSJAV.PGM">
      <data name="CCCKRS" type="packed" length="2" precision="0" usage="input" />
      <data name="IDXKRS" type="packed" length="2" precision="0" usage="input" />
      <data name="ZRTNKRS" type="char" length="10" usage="output" />
   </program>
</pcml>

what's wrong with my code ? Is I need to add as400 CURLIB and PRGLIB to my java code ? if yes, how can I add the libraries ?

解决方案

According to this article, Calling RPG on the AS400 from Java, %LIBL%.LIB is allowed...

But it's not shown specifically on the documentation for PCML program tag

This section of the docs, Integrated file system path names for server objects has

I'd try using just
path="/QSYS.LIB/%LIBL%/GETKURSJAV.PGM"

这篇关于从Java调用AS/400 RPG程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆