To create a JCO.Function object, proceed as follows:
Create a Function Template (interface IFunctionTemplate()). A function template contains all the metadata (parameters and exceptions) for an RFM. To optimize performance, SAP JCo retrieves the metadata only once and saves it in the cache.
Use the method getFunctionTemplate() of the class JCO.Repository to create the template. If the value null is returned, the RFM cannot be found in the SAP server.
You can then use the template to create a JCO.Function object, using the method getFunction().
Syntax
Creating a Function Object
Public JCO.function createFunction (String name) throws Exception {
try {
IFunctionTemplate ft =
mRepository.getFunctionTemplate (name.toUpperCase ())
if (ft == null)
return null;
return ft.getFunction ();
}catch (Exception.ex) {
throw new Exception (“Problem retrieving JCO.Function object.“);
}
}
In addition to containing metadata, a function object also contains the current parameters for executing the RFMs. The relationship between a function template and a function in SAP JCo is similar to that between a class and an object in Java. The code displayed above encapsulates the creation of a function object.
Note
SAP recommends that you create a new function object for each individual execution. By doing so you can ensure that the parameters do not contain any elements from previous calls.