All Packages Class Hierarchy This Package Previous Next Index
Class com.ibm.as400.access.ServiceProgramCall
java.lang.Object
|
+----com.ibm.as400.access.ProgramCall
|
+----com.ibm.as400.access.ServiceProgramCall
- public class ServiceProgramCall
- extends ProgramCall
The ServiceProgramCall class allows a user to call an AS/400 service program,
passing data via input parameters, then accessing data returned via output
parameters. ProgramParameter objects are used to pass data between the Java
program and the AS/400 service program.
ServiceProgramCall subclasses ProgramCall. Much of the setup to call the
service program is done via methods inherited from ProgramCall. For example
setSystem() and getSystem() are methods inherited from ProgramCall.
Limitations of this class:
- The service program must be on an AS/400 running OS/400 V4R4 or later.
- Up to seven parameters can be passed to the service program.
- The return value must be void or numeric. This class does not
support calling service programs that return a pointer.
- Parameters can be "pass by reference" or "pass by value". When pass
by reference, the data is copied from Java storage to AS/400 storage,
then a pointer to the AS/400 storage is passed to the service program.
The name of the service program to call is the fully qualified name
in the AS/400's integrated
file system. The extension is ".SRVPGM". For example,
to call MySrvPgm in MyLib, the program name is /QSYS.LIB/MYLIB.LIB/MYSRVPGM.SRVPGM.
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.
// Construct the parameter list. It contains the single parameter
// to the service program.
ProgramParameter[] parmlist = new ProgramParameter[1];
// Create the input parameter. In this case we are sending the number 9
// to the service program.
AS400Bin4 bin4 = new AS400Bin4();
byte[] parm = bin4.toBytes(9);
parmlist[0] = new ProgramParameter(parm, 0);
// Construct the AS/400 object. The service program is on this AS/400.
AS400 as400 = new AS400("mySystem");
// Construct the ServiceProgramCall object.
ServiceProgramCall sPGMCall = new ServiceProgramCall(as400);
// Set the fully qualified service program and the parameter list.
sPGMCall.setProgram("/QSYS.LIB/MYPGM.LIB/ENTRYPTS.SRVPGM", parmlist);
// 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 true is returned the program
// was successfully called. If false is returned the program
// could not be started. A list of messages is returned when
// the program cannot be started.
if (sPGMCall.run() != true)
{
// Get the error messages when the call fails.
AS400Message[] messageList = sPGMCall.getMessageList();
for (int msg = 0; msg < messageList.length; msg++)
System.out.println(messageList[msg].toString());
}
else
{
// Get the returned value when the call is successful.
Integer I = (Integer) bin4.toObject(sPGMCall.getReturnValue(),0);
int i = I.intValue();
System.out.println("Result is: " + i);
}
- See Also:
- ProgramParameter, ProgramCall
-
NO_RETURN_VALUE
- Constant indicating the service program returns void.
-
RETURN_INTEGER
- Constant indicating the service program returns an integer.
-
ServiceProgramCall()
- Constructs a ServiceProgramCall object.
-
ServiceProgramCall(AS400)
- Constructs a ServiceProgramCall object.
-
ServiceProgramCall(AS400, String, ProgramParameter[])
- Constructs a ServiceProgramCall object.
-
ServiceProgramCall(AS400, String, String, int, ProgramParameter[])
- Constructs a ServiceProgramCall object.
-
ServiceProgramCall(AS400, String, String, ProgramParameter[])
- Constructs a ServiceProgramCall object.
-
getErrno()
- Returns the error number (errno).
-
getIntegerReturnValue()
- Returns the return data when the service program returns an integer.
-
getProcedureName()
- Returns the service program procedure to be called.
-
getReturnValue()
- Returns the data returned from the service program.
-
getReturnValueFormat()
- Returns the format of the returned data.
-
run()
- Calls the service program.
-
run(AS400, String, String, int, ProgramParameter[])
- Calls the service program.
-
run(String, ProgramParameter[])
- Calls the service program.
-
setProcedureName(String)
- Sets the service program procedure to call.
-
setReturnValueFormat(int)
- Sets the format of the returned data.
NO_RETURN_VALUE
public static final int NO_RETURN_VALUE
- Constant indicating the service program returns void.
RETURN_INTEGER
public static final int RETURN_INTEGER
- Constant indicating the service program returns an integer.
ServiceProgramCall
public ServiceProgramCall()
- Constructs a ServiceProgramCall object.
A default ServiceProgramCall object is created.
The system,
program name,
procedure name and
parameters,
must be set before calling the program.
ServiceProgramCall
public ServiceProgramCall(AS400 system)
- Constructs a ServiceProgramCall object.
A ServiceProgramCall object representing the program on system
is created. The
program name,
procedure name and
parameters,
must be set before calling the program.
- Parameters:
- system - The AS/400 that contains the program.
ServiceProgramCall
public ServiceProgramCall(AS400 system,
String serviceProgram,
ProgramParameter parmList[])
- Constructs a ServiceProgramCall object.
A ServiceProgramCall object representing the program on system
with name serviceProgram and parameters parmList created.
The service program's
procedure name
must be set before calling the program.
- Parameters:
- system - The AS/400 which contains the program.
- serviceProgram - The service program name as a fully qualified name
in the integrated file system.
- parmList - A list of up to 7 parameters with which to call the program.
ServiceProgramCall
public ServiceProgramCall(AS400 system,
String serviceProgram,
String procedureName,
ProgramParameter parameterList[])
- Constructs a ServiceProgramCall object.
A ServiceProgramCall object representing the program on system
with name serviceProgram, procedure name procedureName,
and parameters parmList, is created.
- Parameters:
- system - The AS/400 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.
ServiceProgramCall
public ServiceProgramCall(AS400 system,
String serviceProgram,
String procedureName,
int returnValueFormat,
ProgramParameter parameterList[])
- Constructs a ServiceProgramCall object.
A ServiceProgramCall object representing the program on system
with name serviceProgram, procedure name procedureName,
parameters parmList, and returning a value as specified in
returnValueFormat, is created.
- Parameters:
- system - The AS/400 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.
getErrno
public int getErrno()
- Returns the error number (errno). If the service program returns an integer
and an errno, use this method to retrieve the errno. Zero is returned
if the service program returns an integer but no errno.
- Returns:
- The return data.
getIntegerReturnValue
public int getIntegerReturnValue()
- Returns the return data when the service program returns an integer.
- Returns:
- The return data.
getProcedureName
public String getProcedureName()
- Returns the service program procedure to be called.
If the name has not been set, null is returned.
- Returns:
- The service program procedure to be called.
getReturnValue
public byte[] getReturnValue()
- Returns the data returned from the service program. The data is
returned as a byte array. If no data is returned or if the
service program has not yet been called, null is returned.
- Returns:
- The data as a byte array.
getReturnValueFormat
public int getReturnValueFormat()
- Returns the format of the returned data.
- Returns:
- The format of the returned data.
run
public boolean run() throws AS400SecurityException, ErrorCompletingRequestException, InterruptedException, IOException, ObjectDoesNotExistException
- Calls the service program.
- Returns:
- True if the call is successful, false otherwise.
- Throws: AS400SecurityException
- If a security or authority error
occurs.
- Throws: ErrorCompletingRequestException
- If an error occurs before
the request is completed.
- Throws: InterruptedException
- If this thread is interrupted.
- Throws: IOException
- If an error occurs while communicating with
the AS/400.
- Throws: ObjectDoesNotExistException
- If the AS/400 object does not
exist.
- Overrides:
- run in class ProgramCall
run
public boolean run(String serviceProgram,
ProgramParameter parmList[]) throws AS400SecurityException, ConnectionDroppedException, ErrorCompletingRequestException, InterruptedException, IOException, ObjectDoesNotExistException, PropertyVetoException
- Calls the service program.
Calls the specified service program with the specified parameters.
The system object and service program
procedure name must be set before calling this method.
- Parameters:
- serviceProgram - The program name as a fully qualified name in the integrated file system.
- parmList - A list of up to 7 parameters with which to call the program.
- Returns:
- true if the call is successful, false otherwise.
- Throws: AS400SecurityException
- If a security or authority error
occurs.
- Throws: ConnectionDroppedException
- If the connection is dropped
unexpectedly.
- Throws: ErrorCompletingRequestException
- If an error occurs before
the request is completed.
- Throws: InterruptedException
- If this thread is interrupted.
- Throws: IOException
- If an error occurs while communicating with
the AS/400.
- Throws: ObjectDoesNotExistException
- If the AS/400 object does not
exist.
- Throws: PropertyVetoException
- If a change for a property is vetoed.
- Overrides:
- run in class ProgramCall
run
public boolean run(AS400 system,
String serviceProgram,
String procedureName,
int returnValueFormat,
ProgramParameter parameterList[]) throws AS400SecurityException, ConnectionDroppedException, ErrorCompletingRequestException, InterruptedException, IOException, ObjectDoesNotExistException, PropertyVetoException
- Calls the service program.
- Parameters:
- system - The AS/400 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.
- Throws: AS400SecurityException
- If a security or authority error
occurs.
- Throws: ConnectionDroppedException
- If the connection is dropped
unexpectedly.
- Throws: ErrorCompletingRequestException
- If an error occurs before
the request is completed.
- Throws: InterruptedException
- If this thread is interrupted.
- Throws: IOException
- If an error occurs while communicating with
the AS/400.
- Throws: ObjectDoesNotExistException
- If the AS/400 object does not
exist.
- Throws: PropertyVetoException
- If a change for a property is vetoed.
setProcedureName
public void setProcedureName(String procedureName) throws PropertyVetoException
- Sets the service program procedure to call.
- Parameters:
- procedureName - The procedure in the service program to call.
- Throws: PropertyVetoException
- If a change for the value of procedureName is vetoed.
setReturnValueFormat
public void setReturnValueFormat(int returnValueFormat) throws PropertyVetoException
- Sets the format of the returned data.
- Parameters:
- 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.
- Throws: PropertyVetoException
- If a change for the value of returnValueFormat is vetoed.
All Packages Class Hierarchy This Package Previous Next Index