|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ibm.as400.access.ProgramCall
The ProgramCall class allows a user to call an AS/400 program, pass parameters to it (input and output), and access data returned in the output parameters after the program runs. Use ProgramCall to call AS/400 programs. To call AS/400 service programs, use ServiceProgramCall.
The following example demonstrates the use of Program Call:
// Call programs on system "Hal" AS400 system = new AS400("Hal"); ProgramCall program = new ProgramCall(system); try { // Initialize the name of the program to run. String programName = "/QSYS.LIB/TESTLIB.LIB/TESTPROG.PGM"; // Set up the 3 parameters. ProgramParameter[] parameterList = new ProgramParameter[3]; // First parameter is to input a name. AS400Text nametext = new AS400Text(8); parameterList[0] = new ProgramParameter(nametext.toBytes("John Doe")); // Second parmeter is to get the answer, up to 50 bytes long. parameterList[1] = new ProgramParameter(50); // Third parmeter is to input a quantity and return a value up to 30 bytes long. byte[] quantity = new byte[2]; quantity[0] = 1; quantity[1] = 44; parameterList[2] = new ProgramParameter(quantity, 30); // 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() + " did not run!"); } // Done with the system. system.disconnectAllServices();
NOTE: When getting the AS400Message list from programs, users no longer have to create a MessageFile to obtain the program help text. The load() method can be used to retrieve additional message information. Then the getHelp() method can be called directly on the AS400Message object returned from getMessageList(). Here is an example:
if (program.run("myPgm", myParmList) != true) { // Show messages. AS400Message[] messageList = program.getMessageList(); for (int i = 0; i < messageList.length; ++i) { // Show each message. System.out.println(messageList[i].getText()); // Load additional message information. messageList[i].load(); //Show help text. System.out.println(messageList[i].getHelp()); } }
ProgramParameter
,
AS400Message
,
ServiceProgramCall
, Serialized FormConstructor Summary | |
ProgramCall()
Constructs a ProgramCall object. |
|
ProgramCall(AS400 system)
Constructs a ProgramCall object. |
|
ProgramCall(AS400 system,
java.lang.String program,
ProgramParameter[] parameterList)
Constructs a program call object. |
Method Summary | |
void |
addActionCompletedListener(ActionCompletedListener listener)
Adds an ActionCompletedListener. |
void |
addParameter(ProgramParameter parameter)
Adds a ProgramParameter to the parameter list. |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener. |
void |
addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Adds a VetoableChangeListener. |
RJob |
getJob()
Returns an RJob object which represents the AS/400 job in which the program will be run. |
AS400Message[] |
getMessageList()
Returns the list of AS/400 messages returned from running the program. |
ProgramParameter[] |
getParameterList()
Returns the list of parameters. |
java.lang.String |
getProgram()
Returns the integrated file system pathname for the program. |
AS400 |
getSystem()
Returns the AS/400 on which the program is to be run. |
java.lang.Thread |
getSystemThread()
Returns the AS/400 thread on which the program would be run, if it were to be called on-thread. |
boolean |
isStayOnThread()
Indicates whether or not the AS/400 program will actually get run on the current thread. |
boolean |
isThreadSafe()
Indicates whether or not the AS/400 program will be assumed thread-safe, according to the settings specified by setThreadSafe() or the com.ibm.as400.access.ProgramCall.threadSafe property. |
void |
removeActionCompletedListener(ActionCompletedListener listener)
Removes the ActionCompletedListener. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes the PropertyChangeListener. |
void |
removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Removes the VetoableChangeListener. |
boolean |
run()
Runs the program on the AS/400. |
boolean |
run(java.lang.String program,
ProgramParameter[] parameterList)
Sets the program name and the parameter list and runs the program on the AS/400. |
void |
setParameterList(ProgramParameter[] parameterList)
Sets the list of parameters to pass to the AS/400 program. |
void |
setProgram(java.lang.String program)
Sets the path name of the program. |
void |
setProgram(java.lang.String program,
ProgramParameter[] parameterList)
Sets the path name of the program and the parameter list. |
void |
setSystem(AS400 system)
Sets the AS/400 to run the program. |
void |
setThreadSafe(boolean threadSafe)
Specifies whether or not the program should be assumed thread-safe. |
java.lang.String |
toString()
Returns the string representation of this program call object. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Constructor Detail |
public ProgramCall()
public ProgramCall(AS400 system)
system
- The AS/400 on which to run the program.public ProgramCall(AS400 system, java.lang.String program, ProgramParameter[] parameterList)
system
- The AS/400 on which to run the program.program
- The program name as a fully qualified path name in the library file system. The library and program name must each be 10 characters or less.parameterList
- A list of up to 35 parameters with which to run the program.Method Detail |
public void addActionCompletedListener(ActionCompletedListener listener)
listener
- The ActionCompletedListener.removeActionCompletedListener(com.ibm.as400.access.ActionCompletedListener)
public void addParameter(ProgramParameter parameter) throws java.beans.PropertyVetoException
parameter
- The ProgramParameter.public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The PropertyChangeListener.removePropertyChangeListener(java.beans.PropertyChangeListener)
public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The VetoableChangeListener.removeVetoableChangeListener(java.beans.VetoableChangeListener)
public RJob getJob() throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException
AS400.disconnectService()
or AS400.disconnectAllServices()
.
public AS400Message[] getMessageList()
public ProgramParameter[] getParameterList()
public java.lang.String getProgram()
public AS400 getSystem()
public java.lang.Thread getSystemThread() throws AS400SecurityException, java.io.IOException
public boolean isStayOnThread() throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException
isThreadSafe()
public boolean isThreadSafe()
setThreadSafe()
or the com.ibm.as400.access.ProgramCall.threadSafe
property.isStayOnThread()
public void removeActionCompletedListener(ActionCompletedListener listener)
listener
- The ActionCompletedListener.addActionCompletedListener(com.ibm.as400.access.ActionCompletedListener)
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The PropertyChangeListener.addPropertyChangeListener(java.beans.PropertyChangeListener)
public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The VetoableChangeListener.addVetoableChangeListener(java.beans.VetoableChangeListener)
public boolean run() throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException
public boolean run(java.lang.String program, ProgramParameter[] parameterList) throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException, java.beans.PropertyVetoException
program
- The fully qualified integrated file system path name to the program. The library and program name must each be 10 characters or less.parameterList
- The list of parameters with which to run the program.public void setParameterList(ProgramParameter[] parameterList) throws java.beans.PropertyVetoException
parameterList
- A list of up to 35 parameters with which to run the program.public void setProgram(java.lang.String program, ProgramParameter[] parameterList) throws java.beans.PropertyVetoException
program
- The fully qualified integrated file system path name to the program. The library and program name must each be 10 characters or less.parameterList
- A list of up to 35 parameters with which to run the program.public void setProgram(java.lang.String program) throws java.beans.PropertyVetoException
program
- The fully qualified integrated file system path name to the program. The library and program name must each be 10 characters or less.public void setSystem(AS400 system) throws java.beans.PropertyVetoException
system
- The AS/400 on which to run the program. The system cannot be changed once a connection is made to the server.public void setThreadSafe(boolean threadSafe)
threadSafe
- true if the program should be assumed to be thread-safe; false otherwise.isThreadSafe()
,
isStayOnThread()
public java.lang.String toString()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |