Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java ProgramCall.run hangs

Tags:

java

rpg

jtopen

Busy trying to Call RPG function from Java and got this example from JamesA. But now I am having trouble, here is my code:

AS400 system = new AS400("MachineName");
ProgramCall program = new ProgramCall(system);    
    try
    {
        // Initialise the name of the program to run.
        String programName = "/QSYS.LIB/LIBNAME.LIB/FUNNAME.PGM";
        // Set up the 3 parameters.
        ProgramParameter[] parameterList = new ProgramParameter[2];
        // First parameter is to input a name.
        AS400Text OperationsItemId = new AS400Text(20);
        parameterList[0] = new ProgramParameter(OperationsItemId.toBytes("TestID"));
        AS400Text CaseMarkingValue = new AS400Text(20);
        parameterList[1] = new ProgramParameter(CaseMarkingValue.toBytes("TestData"));

        // Set the program name and parameter list.         
        program.setProgram(programName, parameterList);
        // Run the program.
        if (program.run() != true)
        {
            // Report failure.
            System.out.println("Program failed!");
            // Show the messages.
            AS400Message[] messagelist = program.getMessageList();
            for (int i = 0; i < messagelist.length; ++i)
            {
                // Show each message.
                System.out.println(messagelist[i]);
            }
        }
        // Else no error, get output data.
        else
        {
            AS400Text text = new AS400Text(50);
            System.out.println(text.toObject(parameterList[1].getOutputData()));
            System.out.println(text.toObject(parameterList[2].getOutputData()));
        }
    }
    catch (Exception e)
    {
        //System.out.println("Program " + program.getProgram() + " issued an exception!");
        e.printStackTrace();
    }
    // Done with the system.
    system.disconnectAllServices();

The application Hangs at this lineif (program.run() != true), and I wait for about 10 minutes and then I terminate the application.

Any idea what I am doing wrong?

Edit
Here is the message on the job log:

Client request - run program QSYS/QWCRTVCA.
Client request - run program LIBNAME/FUNNAME.
File P6CASEL2 in library *LIBL not found or inline data file missing. Error message CPF4101 appeared during OPEN.
Cannot resolve to object YOBPSSR. Type and Subtype X'0201' Authority

FUNNAME insert a row into table P6CASEPF through a view called P6CASEL2. P6CASEL2 is in a different library lets say LIBNAME2. Is there away to maybe set the JobDescription?

like image 714
ZioN Avatar asked Jan 26 '26 13:01

ZioN


2 Answers

Are you sure FUNNAME.PGM is terminating and not hung with a MSGW? Check QSYSOPR for any messages.


Class ProgramCall:

NOTE: When the program runs within the host server job, the library list will be the initial library list specified in the job description in the user profile.

like image 79
James Allman Avatar answered Jan 28 '26 02:01

James Allman


So I saw that my problem is that my library list is not setup, and for some reason, the user we are using, does not have a Job Description. So to over come this I added the following code before calling the program.run()

CommandCall command = new CommandCall(system);
command.run("ADDLIBLE LIB(LIBNAME)");
command.run("ADDLIBLE LIB(LIBNAME2)");

This simply add this LIBNAME, and LIBNAME2 to the user's library list.

like image 33
ZioN Avatar answered Jan 28 '26 03:01

ZioN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!