Please also have a look in our OnlineHelp for further information.
Apart from the client functionality that allows function modules or BAPIs to be accessed in the SAP system, ERPConnect also offers the possibility of easily developing a server function. Transactional RFC functions are, of course, supported.
The example below shows a simple task. An ABAP program should add two numbers with the help of a function module. The two imports NUMBER1 and NUMBER2 are added and passed back to the calling program via the export RES.
The code shows how to initialize an RFCServer object by providing the gateway host, the gateway service and the program ID to register on the SAP gateway (you may also refer to how to administrate RFC destinations).
After registering the RFCServer object at the SAP gateway, there is an RFCServerFunction object registered with the help of the .RegisteredFunctions.Add method. The imports and exports must be handled the same way as when calling RFC functions as a client. An RFCServer object can, of course, hold more than one RFCServerFunction object.
The event IncomingCall is fired when an ABAP program calls the function in a foreign destination. If you use C#, you must define the event call-back with a separate line of code. If you use Visual Basic on the other hand, use the WithEvents statement.
The following code shows how the IncomingCall event is handled. The import parameters are the ones that are passed by the calling SAP system. The export parameters are the ones that are passed back to SAP.
At the end of this example, you’ll see the ABAP code that is used to call our .NET function in the remote destination ERPTEST. The two numbers 26 and 25 are passed, and the result 51 is passed back. The screenshot further below shows the running ABAP program.
REPORT z_add_test .
DATA result TYPE i.
CALL FUNCTION 'Z_ADD' DESTINATION 'ERPTEST'
number1 = 26
number2 = 25
res = result.
WRITE: / 'Result: ', result.