Auto-Creating the IRfcModule Object
Use
Using autoCreateRfcModule creates the IRfcModule object together with all the necessary metadata of all the parameters of the RFC function module.
Using autoCreateRfcModule eliminates the need to explicitly create and add the metadata of all the parameters of the function.
However, using autoCreateRfcModule is less efficient, because it may result in multiple calls to the R/3 system for obtaining the metadata of the function module.
Prerequisites
SessionManager and all the necessary connection properties must be set up.Procedure
The following diagram summarizes this process:
Result
The IRfcModule object is created with all of its metadata, that is, it is created with all of the parameters of the RFC function modules defined in it.
You can access the metadata of the various parameters of the function module by using the various get methods of the IRfcModule object.
Example
The following example creates a function module for the RFC function BAPI_GL_ACC_GETLIST.
The BAPI_GL_ACC_GETLIST function returns the list of G/L accounts (G/L account number, short text and long text) for a specified company in a specified language. It has the following parameters:
Parameter Name |
Category |
Type |
Internal Name |
Mandatory? |
ACCOUNT_LIST |
Imp/Exp |
Table |
BAPI3006_1 |
N |
COMPANYCODE |
Import |
Field |
COMP_CODE |
Y |
LANGUAGE |
Import |
Field |
LANGU |
N |
LANGUAGE_ISO |
Import |
Field |
LANGU_ISO |
N |
RETURN |
Export |
Structure |
BAPIRETURN |
N |
This example uses auto-create to create the function module. Compare its code with the
code for creating the same function module manually.// Create the module factory
IRfcModuleFactory moduleFac = SessionMgr.getRfcModuleFactory();
// Create the IRfcModule object
IRfcModule rfcModule = moduleFac.autoCreateRfcModule("BAPI_GL_ACC_GETLIST");
// Set the values of COMPANYCODE and LANGUAGE import parameters
rfcModule.getSimpleImportParam("COMPANYCODE").setString ("3000");
rfcModule.getSimpleImportParam("LANGUAGE").setString ("E");
// Call the function module
rfcModule.callReceive();