You can call RFC functions using several patterns depending on the function's signature:
1. No parameters
using var someFunction = connection.CreateFunction("BAPI_SOME_FUNCTION_NAME");
someFunction.Invoke();
2. Input parameters only
Use a class decorated with [SapName] to map C# properties to SAP field names.
class SomeFunctionParameters
{
[SapName("SOME_FIELD")]
public string SomeField { get; set; }
}
using var someFunction = connection.CreateFunction("BAPI_SOME_FUNCTION_NAME");
someFunction.Invoke(new SomeFunctionParameters
{
SomeField = "Some value",
});
3. Input and Output parameters
Pass a generic type to Invoke<T> to capture the output parameters into a result object.
class SomeFunctionResult
{
[SapName("RES_ABC")]
public string Abc { get; set; }
}
using var someFunction = connection.CreateFunction("BAPI_SOME_FUNCTION_NAME");
var result = someFunction.Invoke<SomeFunctionResult>(new SomeFunctionParameters
{
SomeField = "Some value",
});
4. Dynamic parameters
For quick prototyping or when the schema is unknown, use dynamic.
using var someFunction = connection.CreateFunction("BAPI_SOME_FUNCTION_NAME");
var result = someFunction.Invoke<dynamic>(new
{
SOME_FIELD = "Some value",
});
string abc = result.RES_ABC;