0

I am new to JT400. I am trying to invoke a test program in AS400 through JT400. Here is my code

public class TestRpg {

public static void main(String[] args){

    try{

        AS400 sys=new AS400("mydomain","username","password");  

        String number="asdf <= Return value from Java Input";
        String lnsts="";
        String amount="";
        String lnofcd="";

        AS400Text txt80 = new AS400Text(80);
        AS400Text txt50 = new AS400Text(50);

        ProgramParameter[] parmList = new ProgramParameter[4];

        parmList[0] = new ProgramParameter( txt80.toBytes(number),80);
        parmList[1] = new ProgramParameter( txt50.toBytes(lnsts),50);
        parmList[2] = new ProgramParameter( txt80.toBytes(amount),80);
        parmList[3] = new ProgramParameter( txt50.toBytes(lnofcd),50);


        ProgramCall pgm = new ProgramCall(sys,"/QSYS.LIB/mylib.LIB/testrpg.PGM",parmList);

        if (pgm.run()!=true) {
            System.out.println("executed");
        }else{
            System.out.println("Output Data 0: " + (String)txt80.toObject( parmList[0].getOutputData() ) );
            System.out.println("Output Data 1: " + (String)txt50.toObject( parmList[1].getOutputData() ) );
            System.out.println("Output Data 2: " + (String)txt80.toObject( parmList[2].getOutputData() ) );
            System.out.println("Output Data 3: " + (String)txt50.toObject( parmList[3].getOutputData() ) );
            sys.disconnectService(AS400.COMMAND);
        }

            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() );
            } 
            sys.disconnectService(AS400.COMMAND);

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

    }

I had debug the code it's not giving any response after executing pgm.run(). It is not even showing any exception. Programme is just holding at pgm.run() and not returning any thing.

As per the comments I got, I want to include the scenario I am trying to work on. In AS400 when we execute the testrpg.pgm program, it displays a screen with four input fields and some function keys to perform operations. My intention is to invoke f2 function key of that program from JT400. Is the approach I am following is the right way? Please suggest me

Raju Rudru
  • 1,102
  • 12
  • 19
  • "invoke f2 function key". That is an interactive program and it will not work as all program calls happen in batch. – Thorbjørn Ravn Andersen Feb 26 '14 at 07:04
  • @ThorbjørnRavnAndersen can you please suggest me, how can I do this. Thanks for your input – Raju Rudru Feb 26 '14 at 07:13
  • 2
    Have the RPG/COBOL programmers create a program that does what F2 does in the current program and invoke that. Otherwise you need to look into running a 5250 emulator simulating a user interacting with the system where you can control keypresses. http://tn5250j.sourceforge.net/ might be a usable project for that. – Thorbjørn Ravn Andersen Feb 26 '14 at 07:16

2 Answers2

4

All program calls happen in batch so your program is most likely in MSGW on the server. Find it with wrkactjob and investigate the message it is waiting for, and give the appropriate action.

This is typically due to incorrectly formed parameters.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • 1
    Also make sure the RPG program does not try to open a display file. As Thorbjørn says, the RPG program is running in batch. – Buck Calabro Feb 25 '14 at 14:15
  • Also note that you need a CCSID on the AS400Text constructor which you can get from a connected AS400 object. If you don't provide one, jt400 will guess. The guess will be wrong at very inconvenient times. – Thorbjørn Ravn Andersen Feb 25 '14 at 14:31
1

This is a common misunderstanding, so just for clarification for other readers: Calling a Cobol/RPG program from Java is batch, just the same as calling the Cobol/RPG program from a Cobol/RPG/CL.

How to begin: Create a program which you can call from CL:

... declare and fill MYFIELD1, MYFIELD2 ...
CALL PGM(MYPGM) PARM(&MYFIELD1 &MYFIELD2)
... 

If this works, it will also work from Java using jt400, if you:

  • call the right AS400 using correct credentials
  • call the right program in the right library
  • use the right number and lentgh of parameters

In case of crash as described (waiting forever), DSPMSG QSYSOPR will show an open message, like "MCH0801 = wrong number of parameters". D=Dump will create a spoolfile where you see which incoming parameters are filled with which content, or you see "undefined".

Bruce Martin
  • 10,358
  • 1
  • 27
  • 38