Show TOC

Procedure documentationCreating JCO.Function Objects Locate this document in the navigation structure


To create a JCO.Function object, proceed as follows:

  1. 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.

  2. 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.

  3. You can then use the template to create a JCO.Function object, using the method getFunction().

Syntax Syntax

Creating a Function Object

  1. Public JCO.function createFunction (String name) throws Exception {
  2.    try {
  3.       IFunctionTemplate ft =
  4.          mRepository.getFunctionTemplate (name.toUpperCase ())
  5.       if (ft == null)
  6.          return null;
  7.       return ft.getFunction ();
  8. }catch (Exception.ex) {
  9.       throw new Exception (“Problem retrieving JCO.Function object.“);
  10.   }
  11. }
End of the code.

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 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.

End of the note.