0

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 ?

jmarkmurphy
  • 11,030
  • 31
  • 59
rafitio
  • 550
  • 3
  • 15
  • 36

1 Answers1

1

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"

Charles
  • 21,637
  • 1
  • 20
  • 44
  • hi, thanks for your help. I've been change the path to `path="/QSYS.LIB/%LIBL%/GETKURSJAV.PGM"` the error has not shown, but now the result is blank. – rafitio Sep 08 '17 at 07:58
  • outputdata is an INT in the java, yet a CHAR is returned from the RPG...perhaps that is part of your issue? – Charles Sep 08 '17 at 13:42
  • I've been change the output to CHAR, but the result still blank. – rafitio Sep 12 '17 at 03:58
  • What should it return? Are you sure the RPG program returns that? Probably should post the RPG code in a separate question . – Charles Sep 12 '17 at 13:09
  • hi, the problem solved. I've been add the `ADDLIBLE LIB` on my java code. thanks – rafitio Sep 14 '17 at 12:17