Manually Creating the IRfcModule Object 

Use

Creating the IRfcModule object manually means that you initially create an empty IRfcModule object and then you create and add its parameters in a separate step.

Manually creating the IRfcModule object involves more work, but it gives you more control over the creation of the parameters of the function module.

Another reason for creating the IRfcModule object manually is when you know that the RFC function does not have any parameters. In such a case, it is not necessary to create or add any parameters to the IRfcModule object. Using auto-create may result in an unnecessary connection to the R/3 system to get the metadata of the parameters of the function, when there is none.

Prerequisites

SessionManager and all the necessary connection properties must be set up.

Procedure

  1. Obtain an IRfcModuleFactory by using the getRfcModuleFactory method of the SessionManager.
  2. Create the IRfcModule object using the createRfcModule method of IRfcModuleFactory.
  3. Obtain an ISimpleFactory, IStructureFactory, and ITableFactory interfaces as necessary for constructing the various types of parameters that exist in the function module.
  4. For example, if the function module contains only simple parameters (individual fields), then you only need to obtain an ISimpleFactory. If the function module also contains a structure parameter, you need to also obtain an IStructureFactory.

    You only need to obtain a single factory interface for all the parameters of the same type.

  5. Perform the following steps for every parameter of the RFC function module:
    1. Create the parameter.
    2. Add the parameter to the IRfcModule object.
    3. You have to perform these two steps for all of the import, export, and table parameters of the function.

      Note that RFC function parameter are named parameters, meaning that the order of the parameters within the function is not important. Therefore it is not important which parameter you create or add first.

    4. For each table and structure parameters you must also create and add the individual fields of that table or structure. To do so, perform the following steps:
    1. Instantiate an array of SimpleInfo objects representing the fields in the table or structure.
    2. Create an ISimpleField object for every element of that array.
    3. Create a ComplexInfo object
    4. Assign the array of SimpleInfo objects to the ComplexInfo object.
    5. Use the ComplexInfo object to construct the ITable or the IStructure object, using the ITableFactory or the IStructureFactory respectively.

Note that the order of the fields in a structure or a table is important.

As an alternative to creating all the individual fields of a table or a structure, you can auto-create the table or the structure.

After completing this step (Step 4) you have defined the IRfcModule object and all of its metadata (that is, all of the metadata of the parameters of the RFC function modules). You can now access the metadata of the various parameters of the function module by using the various get methods of the IRfcModule object.

  1. Set the value of import parameters for the function module.

The following diagram summarizes the steps for manually creating an IRfcModule and its parameters. Inside the rectangular area are tasks that are performed automatically if you use auto-create to create the IRfcModule.

Example

The code in Example: Calling an RFC Function with Parameters manually creates the IRfcModule object and creates and adds all the parameters to it.