× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Not fully correct, Alan. Every time you create a new ProgramCall object or CommandCall object, you get a new thread on the i. You can reuse that object to call multiple programs or commands within the same "job" on the i. I use this technique often to set the library list, then run a command.

CommandCall command = new CommandCall(system);
command.setThreadSafe(false);
Matcher liblistmatch = Pattern.compile("(.+?)(?:,|$)").matcher(libraryList);
while (liblistmatch.find()){
try {command.run("addlible " + liblistmatch.group(1));}finally{}
}
try
{
// Set the program name and parameter list.
command.setCommand("aCmd Parm1('value')");
// Run the program.
if (command.run() != true)
{
// Report failure.
StringBuffer sb = new StringBuffer("");
sb.append("Command failed! ");
// Show the messages.
AS400Message[] messagelist = command.getMessageList();
for (int i = 0; i < messagelist.length; ++i)
{
sb.append(messagelist[i]);
}
throw new Exception(sb.toString());

...

I do the same with ProgramCall, but call QCMDEXEC to add library list entries before calling the first program. I've used it to call several programs. The parameters you pass to the program are changed if the target program has changed them.

So you can, indeed, do as the op suggested.

-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx [mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of Alan Campin
Sent: Thursday, September 22, 2011 12:05 PM
To: Java Programming on and around the IBM i
Subject: Re: Calling RPG program (more than 1 time) and maintening the context between the two calls

Every time you make another call you get a new thread which is destroyed after it returns. You either have to save the values in say a user space but messy.

A better solution might be to make the RPG call a stored procedures. SQL maintains context between calls.

On Thu, Sep 22, 2011 at 10:37 AM, Tiago Cavaleiro < Tiago.Cavaleiro@xxxxxxxxxxx> wrote:

Hi all,

Can anyone give me some tips regarding a problem I'm having?

So we're doing some project using Websphere to integrate with iSeries
(we achieved to access DB2 on iSeries, calling RPG programs using
ProgramCall, etc..). Until here everything OK, our problem is related with the following:

Imagine we're on iSeries and call a RPG program that does the following:

· Fulfill Data Structure (1)

· Call X.PGM with DS as parameter (2)

o Eval return parameter, if OK then: (3)

§ Change a field value on the input DS (4)

§ Call X.PGM with DS (5)

· Print return parameter (the return is OK) (6)


Hope that my bullets explanation were representative. :) Ok so when we
emulate this on the Java (doing the same steps the program called from
iSeries does), we're getting some error on step 6 (saying that the
program didn't find any reference...) - we think this is because the
two ProgramCall calls occurs in different contexts (or the second call
doesn't have the first call context).

On our code we're reusing the ProgramCall, we've just change the
parameter value using ProgramParameter.setInputData(). Is it possible
to have the same behavior on Java that we have on RPG program?


Sample code below:

AS400 sys = session.getSystem();
String pgmPath = QSYSObjectPathName.toPath("XPTOLIB",
"PROGRA", "PGM");

Object[] inData = ...;

ProgramParameter[] parameters = new ProgramParameter[] {
new
ProgramParameter(DATATYPES[0].toBytes(inData[0]), ..),
new
ProgramParameter(DATATYPES[1].toBytes(inData[1]), ..),
new
ProgramParameter(DATATYPES[2].toBytes(inData[2]), ..),
new
ProgramParameter(DATATYPES[3].toBytes(inData[3]), ..),
new
ProgramParameter(DATATYPES[4].toBytes(inData[4]), ..),
new
ProgramParameter(DATATYPES[4].toBytes(inData[4]), ..),
new
ProgramParameter(DATATYPES[6].toBytes(inData[6]), ..),
new
ProgramParameter(DATATYPES[7].toBytes(inData[7]), ..),
new
ProgramParameter(DATATYPES[8].toBytes(inData[8]), ..),
new
ProgramParameter(DATATYPES[9].toBytes(inData[9]), .),
new
ProgramParameter(DATATYPES[10].toBytes(inData[10]), ..),
new
ProgramParameter(DATATYPES[11].toBytes(inData[11]), .),
new
ProgramParameter(DATATYPES[12].toBytes(inData[12]), ..)
};
ProgramCall pgm = new ProgramCall(sys);

boolean success = false;
try {
// first call
success = pgm.run(pgmPath, parameters);
if (!success) {
throw new ConnectionException("We've
received success=false.");
}
System.out.println("job number: " +
pgm.getServerJob().getNumber());
}
catch (Exception e) {
...// do logging etc..
}

outData = ...// process array
parameters[...].getOutputData();


printResponse(outData);

String status = outData[6].toString();
if ("R".equals(status)) {

try {
parameters[5].setInputData(dsaim2);
} catch (PropertyVetoException e1) {
e1.printStackTrace(); // test purpose only
}

success = false;
try {
// second call
success = pgm.run(h56h1r, parameters);
if (!success) {
throw new ConnectionException("We've
received success=false.");
}
System.out.println("job number: " +
pgm.getServerJob().getNumber());
}
catch (Exception e) {
...// do logging etc..
}

outData = ...// process array
parameters[...].getOutputData();

// were we see on the console the problem
printResponse(outData);





Thanks in advance!

Tiago Cavaleiro


________________________________

Disclaimer/Implicações legais
http://www.exictos.com/disclaimer/e-mail.htm

________________________________

Antes de imprimir este "e-mail" pense no meio ambiente.
Por favor considere as suas responsabilidades ambientais! Antes de
imprimir o Email, pergunte a si mesmo se realmente precisa duma cópia em papel.
--
This is the Java Programming on and around the IBM i (JAVA400-L)
mailing list To post a message email: JAVA400-L@xxxxxxxxxxxx To
subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at
http://archive.midrange.com/java400-l.


--
This is the Java Programming on and around the IBM i (JAVA400-L) mailing list To post a message email: JAVA400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/java400-l.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.