Calling AS/400 RPG Programs from Java

2.3k views Asked by At

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 ?

1

There are 1 answers

5
Charles On

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 enter image description here

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