public class ServiceProgramCall extends ProgramCall
Limitations of this class:
The name of the service program to call is the fully qualified name in the integrated file system. The extension is ".SRVPGM". For example, to call MySrvPgm in MyLib, the program name is /QSYS.LIB/MYLIB.LIB/MYSRVPGM.SRVPGM.
Service program entry point notes:
The following example calls procedure int_int in service program ENTRYPTS in library MYPGM. The procedure takes one input parameter, an integer, and returns an integer.
// Create a single parameter parameter list. ProgramParameter[] parameterList = new ProgramParameter[1]; // Create the input parameter. We are sending the number 9 to the service program. AS400Bin4 bin4 = new AS400Bin4(); byte[] parameter = bin4.toBytes(9); parameterList[0] = new ProgramParameter(parameter); // Construct the system object. The service program is on this system. AS400 system = new AS400("mySystem"); // Construct the ServiceProgramCall object. ServiceProgramCall sPGMCall = new ServiceProgramCall(system); // Set the fully qualified service program and the parameter list. sPGMCall.setProgram("/QSYS.LIB/MYPGM.LIB/ENTRYPTS.SRVPGM", parameterList); // Set the procedure to call in the service program. sPGMCall.setProcedureName("int_int"); // Set the format of returned value. The program we call returns an integer. sPGMCall.setReturnValueFormat(ServiceProgramCall.RETURN_INTEGER); // Call the service program. if (sPGMCall.run() != true) { // Get the error messages when the call fails. AS400Message[] messageList = sPGMCall.getMessageList(); for (int i = 0; i < messageList.length; ++i) { System.out.println(messageList[i].getText()); } } else { // Get the returned value when the call is successful. int i = bin4.toInt(sPGMCall.getReturnValue()); System.out.println("Result is: " + i); }
NOTE: There are two ways to run a service program in an iasp. Users can call a service program directly with path prefixed with the iasp information like "/IASP1/QSYS.LIB/MYPGM.LIB/ENTRYPTS.SRVPGM". Users can also call AS400.setIASPGroup to set the asp group information firstly, then call the service program in regular library-qualified object name syntax. The second way is recommended. For example:
// Call a service program on system named "Hal" on asp "iasp1" AS400 system = new AS400("Hal"); system.setIASPGroup("iasp1"); //If do not use *CURUSR for current library and library list, call other setIASPGroup interfaces. ServiceProgramCall sPGMCall = new ServiceProgramCall(system); sPGMCall.setProgram("/QSYS.LIB/MYPGM.LIB/ENTRYPTS.SRVPGM");
Modifier and Type | Field and Description |
---|---|
static int |
NO_RETURN_VALUE
Constant indicating the service program returns void.
|
static int |
RETURN_INTEGER
Constant indicating the service program returns an integer.
|
Constructor and Description |
---|
ServiceProgramCall()
Constructs a ServiceProgramCall object.
|
ServiceProgramCall(AS400 system)
Constructs a ServiceProgramCall object.
|
ServiceProgramCall(AS400 system,
java.lang.String serviceProgram,
ProgramParameter[] parameterList)
Constructs a ServiceProgramCall object.
|
ServiceProgramCall(AS400 system,
java.lang.String serviceProgram,
java.lang.String procedureName,
int returnValueFormat,
ProgramParameter[] parameterList)
Constructs a ServiceProgramCall object.
|
ServiceProgramCall(AS400 system,
java.lang.String serviceProgram,
java.lang.String procedureName,
ProgramParameter[] parameterList)
Constructs a ServiceProgramCall object.
|
Modifier and Type | Method and Description |
---|---|
int |
getErrno()
Returns the error number (errno).
|
int |
getIntegerReturnValue()
Returns the return data when the service program returns an integer.
|
java.lang.String |
getProcedureName()
Returns the service program procedure to be called.
|
byte[] |
getReturnValue()
Returns the data returned from the service program.
|
int |
getReturnValueFormat()
Returns the format of the returned data.
|
boolean |
run()
Calls the service program.
|
boolean |
run(AS400 system,
java.lang.String serviceProgram,
java.lang.String procedureName,
int returnValueFormat,
ProgramParameter[] parameterList)
Calls the service program.
|
boolean |
run(java.lang.String serviceProgram,
ProgramParameter[] parameterList)
Calls the service program.
|
void |
setAlignOn16Bytes(boolean align)
Sets whether to align the first parameter on a 16-byte boundary.
|
void |
setProcedureName(java.lang.String procedureName)
Sets the service program procedure to call.
|
void |
setProcedureName(java.lang.String procedureName,
int procedureNameCCSID)
Sets the service program procedure to call.
|
void |
setProgram(java.lang.String serviceProgram)
Sets the path name of the service program.
|
void |
setReturnValueFormat(int returnValueFormat)
Sets the format of the returned data.
|
addActionCompletedListener, addParameter, addPropertyChangeListener, addVetoableChangeListener, cancel, getMessageList, getMessageOption, getParameterList, getProgram, getServerJob, getSystem, getSystemThread, getTimeout, isRunning, isStayOnThread, isThreadSafe, removeActionCompletedListener, removePropertyChangeListener, removeVetoableChangeListener, setMessageOption, setParameterList, setProgram, setSystem, setThreadSafe, setTimeOut, suggestThreadsafe, toString
public static final int NO_RETURN_VALUE
public static final int RETURN_INTEGER
public ServiceProgramCall()
public ServiceProgramCall(AS400 system)
system
- The system that contains the program.public ServiceProgramCall(AS400 system, java.lang.String serviceProgram, ProgramParameter[] parameterList)
system
- The system which contains the program.serviceProgram
- The service program name as a fully qualified name in the integrated file system.parameterList
- A list of up to 7 parameters with which to call the program.public ServiceProgramCall(AS400 system, java.lang.String serviceProgram, java.lang.String procedureName, ProgramParameter[] parameterList)
system
- The system which contains the program.serviceProgram
- The program name as a fully qualified name in the integrated file system.procedureName
- The procedure in the service program to call.parameterList
- A list of up to 7 parameters with which to call the program.public ServiceProgramCall(AS400 system, java.lang.String serviceProgram, java.lang.String procedureName, int returnValueFormat, ProgramParameter[] parameterList)
system
- The system which contains the program.serviceProgram
- The program name as a fully qualified name in the integrated file system.procedureName
- The procedure in the service program to call.returnValueFormat
- The format of the returned data. The value must be one of the following:
NO_RETURN_VALUE
The procedure does not return a value.
RETURN_INTEGER
The procedure returns an integer.
parameterList
- A list of up to 7 parameters with which to call the program.public int getErrno()
The errno is valid only when the return code is non-zero. Service programs are not required to reset the errno each time the API is called, so the errno may not be reset from a previous call. Suppose, for example, calling an entry point the first time fails so the return code and errno are both non-zero. If the next call works, the return code will be zero but the errno may have the non-zero value from the previous call of the entry point. Checking only the errno would indicate the second call failed when it actually worked. Call this method only when a call to getIntegerReturnValue returns a non-zero value.
public int getIntegerReturnValue()
public java.lang.String getProcedureName()
public byte[] getReturnValue()
public int getReturnValueFormat()
NO_RETURN_VALUE
The procedure does not return a value.
RETURN_INTEGER
The procedure returns an integer.
public boolean run() throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException
run
in class ProgramCall
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the system object does not exist.public boolean run(java.lang.String serviceProgram, ProgramParameter[] parameterList) throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException, java.beans.PropertyVetoException
run
in class ProgramCall
serviceProgram
- The program name as a fully qualified name in the integrated file system.parameterList
- A list of up to 7 parameters with which to call the program.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the system object does not exist.java.beans.PropertyVetoException
- If a change for a property is vetoed.public boolean run(AS400 system, java.lang.String serviceProgram, java.lang.String procedureName, int returnValueFormat, ProgramParameter[] parameterList) throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException, java.beans.PropertyVetoException
system
- The system which contains the program.serviceProgram
- The program name as a fully qualified name in the integrated file system.procedureName
- The procedure in the service program to call.returnValueFormat
- The format of the returned data. The value must be one of the following:
NO_RETURN_VALUE
The procedure does not return a value.
RETURN_INTEGER
The procedure returns an integer.
parameterList
- A list of up to 7 parameters with which to call the program.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the system object does not exist.java.beans.PropertyVetoException
- If a change for a property is vetoed.public void setAlignOn16Bytes(boolean align)
align
- Whether to align the first parameter on a 16-byte boundary.public void setProcedureName(java.lang.String procedureName) throws java.beans.PropertyVetoException
procedureName
- The procedure in the service program to call.java.beans.PropertyVetoException
- If a change for the value of procedureName is vetoed.public void setProcedureName(java.lang.String procedureName, int procedureNameCCSID) throws java.beans.PropertyVetoException
procedureName
- The procedure in the service program to call.procedureNameCCSID
- The CCSID to use when converting the procedure name from a Java String to EBCDIC.java.beans.PropertyVetoException
- If a change for the value of procedureName is vetoed.public void setProgram(java.lang.String serviceProgram) throws java.beans.PropertyVetoException
setProgram
in class ProgramCall
serviceProgram
- The fully qualified integrated file system path name to the service program. The library and service program name must each be 10 characters or less.java.beans.PropertyVetoException
- If the change is vetoed.public void setReturnValueFormat(int returnValueFormat) throws java.beans.PropertyVetoException
returnValueFormat
- The format of the returned data. The value must be one of the following:
NO_RETURN_VALUE
The procedure does not return a value.
RETURN_INTEGER
The procedure returns an integer.
java.beans.PropertyVetoException
- If a change for the value of returnValueFormat is vetoed.