|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ibm.as400.access.ProgramCall
public class ProgramCall extends Object implements Serializable
The ProgramCall class allows a user to call an IBM i system program, pass parameters to it (input and output), and access data returned in the output parameters after the program runs. Use ProgramCall to call programs. To call service programs, use ServiceProgramCall.
The following example demonstrates the use of Program Call:
// Call programs on system named "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 parameter is to get the answer, up to 50 bytes long. parameterList[1] = new ProgramParameter(50); // Third parameter 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() + " issued an exception!"); e.printStackTrace(); } // 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()); } }
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.
ProgramParameter
,
AS400Message
,
ServiceProgramCall
,
Serialized FormConstructor and Description |
---|
ProgramCall()
Constructs a ProgramCall object. |
ProgramCall(AS400 system)
Constructs a ProgramCall object. |
ProgramCall(AS400 system,
String program,
ProgramParameter[] parameterList)
Constructs a program call object. |
Modifier and Type | Method and Description |
---|---|
void |
addActionCompletedListener(ActionCompletedListener listener)
Adds an ActionCompletedListener. |
void |
addParameter(ProgramParameter parameter)
Adds a ProgramParameter to the parameter list. |
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener. |
void |
addVetoableChangeListener(VetoableChangeListener listener)
Adds a VetoableChangeListener. |
AS400Message[] |
getMessageList()
Returns the list of messages returned from running the program. |
int |
getMessageOption()
Returns the option for how many messages will be retrieved. |
ProgramParameter[] |
getParameterList()
Returns the list of parameters. |
String |
getProgram()
Returns the integrated file system pathname for the program. |
Job |
getServerJob()
Returns a Job object which represents the server job in which the program will be run. |
AS400 |
getSystem()
Returns the system on which the program is to be run. |
Thread |
getSystemThread()
Returns the thread on which the program would be run, if it were to be called on-thread. |
boolean |
isStayOnThread()
Indicates whether or not the program will actually get run on the current thread. |
boolean |
isThreadSafe()
Deprecated. The name of this method is misleading. Use isStayOnThread() instead. |
void |
removeActionCompletedListener(ActionCompletedListener listener)
Removes the ActionCompletedListener. |
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes the PropertyChangeListener. |
void |
removeVetoableChangeListener(VetoableChangeListener listener)
Removes the VetoableChangeListener. |
boolean |
run()
Runs the program on the system. |
boolean |
run(String program,
ProgramParameter[] parameterList)
Sets the program name and the parameter list and runs the program on the system. |
void |
setMessageOption(int messageOption)
Specifies the option for how many messages should be retrieved. |
void |
setParameterList(ProgramParameter[] parameterList)
Sets the list of parameters to pass to the program. |
void |
setProgram(String program)
Sets the path name of the program. |
void |
setProgram(String program,
ProgramParameter[] parameterList)
Sets the path name of the program and the parameter list. |
void |
setSystem(AS400 system)
Sets the system to run the program. |
void |
setThreadSafe(boolean threadSafe)
Specifies whether or not the program should be assumed thread-safe. |
void |
suggestThreadsafe()
Specifies that the called program should be assumed to be thread-safe. |
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 system on which to run the program.public ProgramCall(AS400 system, String program, ProgramParameter[] parameterList)
system
- The system 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 listener object.public void addParameter(ProgramParameter parameter) throws PropertyVetoException
parameter
- The ProgramParameter.PropertyVetoException
- If the change is vetoed.public void addPropertyChangeListener(PropertyChangeListener listener)
listener
- The listener object.public void addVetoableChangeListener(VetoableChangeListener listener)
listener
- The listener object.public AS400Message[] getMessageList()
public int getMessageOption()
public ProgramParameter[] getParameterList()
public String getProgram()
public Job getServerJob() throws AS400SecurityException, ErrorCompletingRequestException, IOException, InterruptedException
AS400.disconnectService()
or AS400.disconnectAllServices()
.
Note: This method is not supported in the Toolbox proxy environment.
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.IOException
- If an error occurs while communicating with the system.InterruptedException
- If this thread is interrupted.public AS400 getSystem()
public Thread getSystemThread() throws AS400SecurityException, IOException
AS400SecurityException
- If a security or authority error occurs.IOException
- If an error occurs while communicating with the system.public boolean isStayOnThread() throws AS400SecurityException, ErrorCompletingRequestException, IOException, InterruptedException
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.IOException
- If an error occurs while communicating with the system.InterruptedException
- If this thread is interrupted.public boolean isThreadSafe()
isStayOnThread()
instead.
setThreadSafe()
or the com.ibm.as400.access.ProgramCall.threadSafe
property.
public void removeActionCompletedListener(ActionCompletedListener listener)
listener
- The listener object.public void removePropertyChangeListener(PropertyChangeListener listener)
listener
- The listener object.public void removeVetoableChangeListener(VetoableChangeListener listener)
listener
- The listener object.public boolean run() throws AS400SecurityException, ErrorCompletingRequestException, IOException, InterruptedException, ObjectDoesNotExistException
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.IOException
- If an error occurs while communicating with the system.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the object does not exist on the system.public boolean run(String program, ProgramParameter[] parameterList) throws AS400SecurityException, ErrorCompletingRequestException, IOException, InterruptedException, ObjectDoesNotExistException, 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.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.IOException
- If an error occurs while communicating with the system.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the object does not exist on the system.PropertyVetoException
- If a change is vetoed.public void setParameterList(ProgramParameter[] parameterList) throws PropertyVetoException
parameterList
- A list of up to 35 parameters with which to run the program.PropertyVetoException
- If a change is vetoed.public void setProgram(String program, ProgramParameter[] parameterList) throws 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.PropertyVetoException
- If a change is vetoed.public void setProgram(String program) throws 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.PropertyVetoException
- If the change is vetoed.public void setMessageOption(int messageOption)
messageOption
- A constant indicating how many messages to retrieve. Valid values are:
public void setSystem(AS400 system) throws PropertyVetoException
system
- The system on which to run the program.PropertyVetoException
- If the change is vetoed.public void setThreadSafe(boolean threadSafe)
threadSafe
- true if the program should be assumed to be thread-safe; false otherwise.public void suggestThreadsafe()
public String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |