0

When i call RPG program from java i am able to pass the input parameters and trying to get back output value from same input field when its come to java its getting NullPointerException . here is my sample code. Please suggest a solution.

    try{                
        AS400 sys=new AS400("domain","user","password");

        ProgramParameter[] parmList = new ProgramParameter[2];           
        AS400ZonedDecimal laonNumner = new AS400ZonedDecimal(10,0);
        AS400ZonedDecimal loanAmt = new AS400ZonedDecimal(10,3);             

        parmList[0] = new ProgramParameter(laonNumner.toBytes(12345));
        parmList[1] = new ProgramParameter(loanAmt.toBytes(6789));

        String pgmName = "/QSYS.LIB/VTEST.LIB/TESTRPG.PGM";
        ProgramCall pgm = new ProgramCall(sys,pgmName,parmList);

        CommandCall command = new CommandCall(sys);
        command.run("ADDLIBLE LIB(VTEST)");         
        System.out.println("status :"+pgm.isRunning());

        if (pgm.run()!=true) {
            System.out.println("failure");

            AS400Message[] messageList = pgm.getMessageList();
            System.out.println(messageList.length);
            for (int i=0; i < messageList.length; i++)
            {
                System.out.print  ( messageList[i].getID() );
                System.out.print  ( ": " );
                System.out.println( messageList[i].getText() );
            } 
        }else{
            System.out.println("success" );                
            Double loanNo = laonNumner.toDouble(parmList[0].getOutputData());
            Double loanAmount = laonNumner.toDouble(parmList[1].getOutputData());

            System.out.println("Loan number"+ loanNo);
            System.out.println("Loan number"+ loanAmount);
        }

        System.out.println("status :"+pgm.isRunning());
        sys.disconnectAllServices();

        }catch(Exception e) {
            System.out.println(e.toString());
        }   

output:

status :false
success
java.lang.NullPointerException
Sionnach733
  • 4,686
  • 4
  • 36
  • 51

1 Answers1

0

You have in/out parms so you want to call the setOutputLength() method on your ProgramParameter objects before calling the program.

parmList[0] = new ProgramParameter(laonNumner.toBytes(12345));
parmList[0].setOutputLength(50)
parmList[1] = new ProgramParameter(loanAmt.toBytes(6789));
parmList[1].setOutputLength(50)