0

I have a very limitied (0) knowledge on AS400 and RPG. But we have a urgent requirement where we need to invoke a RPG program from a java class. So I found that we can achieve it through JTOpen. But I am stuck at declaring the ProgramParameter list. I have the following information about RPG Program

Program name: ZM30000R Parameters: Branch 7,0 (Numeric)
Account type 2 (01-cheque,02 savings)
Account Number 20 (character)
Error code 7 (character) DR/CR indicater 1 (character D,C)

But no clue about what is the intput and output .How to declare the ProgramParameter. I have done as below. I cannot test as well because I dont have connectivity to these systems.

// Create AS400 Text objects for the different lengths
          // of parameters you are sending in.
          AS400Text branchTxt = new AS400Text(7);
          AS400Text accntTypeTxt = new AS400Text(2);
          AS400Text accntNumberTxt = new AS400Text(20);
          AS400Text errorCodeTxt = new AS400Text(7);
          AS400Text DCIndicatorTxt = new AS400Text(1);            

          // declare and instantiate  your parameter list.
          ProgramParameter[] parmList = new ProgramParameter[5];

          // assign values to your parameters using the AS400Text class to convert to bytes
          // the second parameter is an integer which sets the length of your parameter output
          parmList[0] = new ProgramParameter( branchTxt.toBytes(branch),7);
          parmList[1] = new ProgramParameter( accntTypeTxt.toBytes(accntTypeTxt),2);      
          parmList[2] = new ProgramParameter( accntNumberTxt.toBytes(accntNumberTxt),20);      
          parmList[3] = new ProgramParameter( errorCodeTxt.toBytes(""),7);      
          parmList[4] = new ProgramParameter( DCIndicatorTxt.toBytes(indicator),5);

Any help will be really highly useful.

Thanks and Regards,

Srinivas

WarrenT
  • 4,502
  • 19
  • 27
Srinivas
  • 1,383
  • 5
  • 20
  • 28
  • 1
    I gave you tips about how to test a java call to a rpg program in your other question. – robertnl Jan 20 '10 at 20:56
  • 1
    Oh, look! It's urgent! Drop everything and answer it! Or, to be less sarcastic, *everybody* who asks a question here would like to get an answer. You *will not* get a better response by trying to light a fire under the community. And you should link to your previous question on the same topic ( http://stackoverflow.com/questions/2103928/as400-rpg-simulator ) and explain how this one is related to it. – dmckee --- ex-moderator kitten Jan 20 '10 at 20:58
  • 1
    Indeed dmckee, you're right. The question could be much better. Knowing nothing about the as400 doesn't help either. It is just that I've experienced how difficult and confusing the interface between java and rpg can be that I did answer both questions. Hope it helps Phani in adressing the real issue. Solving the issue may require another step (or question ;-) – robertnl Jan 20 '10 at 21:22
  • Very important: you need to tell the AS400Text object about the code page of the system you are talking to. If not, it will guess and for non-US systems this is frequently wrong. – Thorbjørn Ravn Andersen Jul 11 '14 at 09:43

4 Answers4

4

Well, I do have a clue just by the description of the parameters. Branch, account type and account number are IN. You need that information for a financial booking or transaction. The error code is appearently OUT. In my experience with financial systems it's reasonable normal that the API returns the way the amount is booked. Normally one would use the sign, but in financial systems the (D)ebit or (C)redit is the better way.

The API is very likely the API of a financial system. If that is true, then I'm missing the amount. Are you sure you've the complete description?

Notice that the first parameter is numeric. You're not in luck. The iSeries and RPG are not very forgiving about the type of a numeric. One can choose from Bit, Zoned, Packed, Decimal, Integer, Float and so on. If the RPG is really RPG instead of ILE RPG, then you can bring that down to Zoned, Packed and Byte.

I assume you've access to the iSeries. Then you can watch the program call, debug information and dump information. That will help you if you have to do "trial and error". If you don't have access, the road will be very hard. You'll receive an error in your java class if the program call is not succesfull. But it will be hard to identify the real error without the information from the iSeries yourself. Therefore, access is really required.

robertnl
  • 1,014
  • 6
  • 7
3

Your sample is mostly on the right track. But your branch parameter is numeric. So you should use AS400ZonedDecimal instead of AS400Text:

AS400ZonedDecimal branchNbr = new AS400ZonedDecimal(7,0)

The RPG program may be expecting packed instead of zoned. No big deal, just use AS400PackedDecimal instead.

As you construct your ProgramParameter object, your constructor requirements are different depending on if they are input or output parameters to your program. For input parameters, just pass the toBytes() results. There is no need to include the length. For output-only parameters, just pass the length.

I agree with Robert's answer that there is some missing information, but his assumptions on the outputness of the error code seems valid. I would guess, however, that the DCIndicator parameter is input since your sample passes a value. For the error code parameter, after your program call, you'll need to extract the value and do something with it. Given what you have already, here is how the program call would work. Take note that I specified a library name of "MyLibrary". That is for example purposes. You will have to determine which library your program object is in.

ProgramCall pgm = new ProgramCall(as400, QSYSObjectPathName.toPath("MyLibrary","ZM30000R","PGM"), parmList);
if (pgm.run() == true) {
    String sErrorCode = (String) errorCodeTxt.toObject(parmList[3].getOutputData());

    //Do something with your output data.
}
else {
    AS400Message[] messageList = pgm.getMessageList();
    for (int i=0; i<messageList.length; i++) {
        String sMessageID = messageList[i].getID();
        String sMessageText = messageList[i].getText();

        //Do something with the error messages
    }
}

Something else to consider is library lists. Does the RPG program expect certain libraries to be in the library list? If so, you should issue CommandCalls to add the libraries to the library list before calling the program.

Tracy Probst
  • 1,839
  • 12
  • 13
1

FWIW: It's a lot easier to call IBM i host programs & service programs using PCML rather than ProgramCall.

The compilers will even generate the PCML document for you.

See http://javadoc.midrange.com/jtopen/com/ibm/as400/data/ProgramCallDocument.html for details.

David G
  • 3,940
  • 1
  • 22
  • 30
0

If you don't have connectivity, then you really can't do what is asked. How do you test it? Is there numeric parameters or are they all character?

Mike Wills
  • 20,959
  • 28
  • 93
  • 149