usingERPConnect;staticvoidMain(string[]args){RFCServers=newRFCServer();s.GatewayHost="sap-erp-as05.example.com";s.GatewayService="sapgw11";s.ProgramID="ERPTEST";s.IncomingCall+=newERPConnect.RFCServer.OnIncomingCall(s_IncomingCall);RFCServerFunctionf=s.RegisteredFunctions.Add("Z_ADD");f.Imports.Add("NUMBER1",RFCTYPE.INT);f.Imports.Add("NUMBER2",RFCTYPE.INT);f.Exports.Add("RES",RFCTYPE.INT);s.Start();Console.Write("Server is running. Press any key to exit.");Console.ReadLine();}
Two input parameters (NUMBER1 and NUMBER2) are added in a new function (Z_ADD). The result (RES) is passed back to the calling ABAP program, see Call RFC Server Functions in ABAP.
usingERPConnect;staticvoidMain(string[]args){staticRFCServers=newRFCServer();s.GatewayHost="SAPServer";s.GatewayService="sapgw00";s.ProgramID="ERPConnectTEST";s.IncomingCall+=newRFCServer.OnIncomingCall(s_IncomingCall);RFCServerFunctionf=s.RegisteredFunctions.Add("Z_ADD_2");f.Exports.Add("RES",RFCTYPE.INT);RFCTablenumbertable=f.Tables.Add("NUMBERS");numbertable.Columns.Add("NUMB",10,0,RFCTYPE.NUM);s.Start();Console.WriteLine("Press Enter to quit");Console.ReadLine();}
A table (NUMBERS) with a column (NUMB) is added to a table collection using Add(). The result (RES) is passed back to the calling ABAP program, see Call RFC Server Functions in ABAP.
usingERPConnect;staticvoidMain(string[]args){staticRFCServers=newRFCServer();s.GatewayHost="hamlet";s.GatewayService="sapgw11";s.ProgramID="ERPTEST";s.IncomingCall+=newRFCServer.OnIncomingCall(s_IncomingCall);RFCServerFunctionf=s.RegisteredFunctions.Add("Z_ADD_3");RFCTableColumnCollectionColumns=newRFCTableColumnCollection();Columns.Add("NUMB",10,0,RFCTYPE.NUM);Columns.Add("NUMB2",10,0,RFCTYPE.NUM);f.Imports.Add("NUMBERS",Columns);f.Exports.Add("RES",RFCTYPE.INT);s.Start();Console.WriteLine("Press Enter to quit");Console.ReadLine();}
A structure (NUMBERS) with 2 columns (NUMB1 and NUMB2) is added to a column collection via RFCTableColumnCollection(). The result (RES) is passed back to the calling ABAP program, see Call RFC Server Functions in ABAP.
usingERPConnect;staticvoidMain(string[]args){staticRFCServers=newRFCServer();s.GatewayHost="hamlet";s.GatewayService="sapgw11";s.ProgramID="ERPTEST";s.IncomingCall+=newRFCServer.OnIncomingCall(s_IncomingCall);RFCServerFunctionf=s.RegisteredFunctions.Add("Z_ADD_4");RFCTableColumnCollectionColumns=newRFCTableColumnCollection();Columns.Add("NUMB1",10,0,RFCTYPE.NUM);Columns.Add("NUMB2",10,0,RFCTYPE.NUM);RFCTableColumnCollectionEXColumns=newRFCTableColumnCollection();EXColumns.Add("NUMB1",10,0,RFCTYPE.NUM);EXColumns.Add("NUMB2",10,0,RFCTYPE.NUM);f.Imports.Add("NUMBERS",Columns);f.Exports.Add("EXNUMBERS",EXColumns);s.Start();Console.WriteLine("Press Enter to quit");Console.ReadLine();}
Two structures (NUMBERS and EXNUMBERS) with 2 columns (NUMB1 and NUMB2) are added to column collections via RFCTableColumnCollection(). One structure (NUMBERS) is used for import and the other (EXNUMBERS) is passed back to the calling ABAP program, see Call RFC Server Functions in ABAP.
Handle Incoming Calls
The following code shows how the IncomingCall event is handled:
The values from the IMPORT collection (numberstruc) are set in variables. Then different values are added to them and are written back to the EXPORT collection (EXnumbers).
The import parameters are passed by the calling SAP system. The export parameters are passed back to SAP.
Call RFC Server Functions in ABAP
The following ABAP code is used to call the new function Z_ADD in the remote destination ERPTEST.
REPORTz_add_testDATAresult TYPE i.CALL FUNCTION'Z_ADD'DESTINATION'ERPTEST'EXPORTINGnumber1=26number2=25IMPORTINGres=result.WRITE:/'Result: ',result.
The two numbers 26 and 25 are passed, and the result 51 is passed back.
The two numbers 1 and 2 are passed, and the result 3 is passed back.
REPORTZADDTEST4..DATAnumbsLIKE zaddstruc2.DATAexnumberslike zaddstruc2.numbs-numb1='1'.numbs-numb2='2'.CALL FUNCTION'Z_ADD_4'DESTINATION'ERPTEST'EXPORTINGNUMBERS=numbsIMPORTINGEXNUMBERS=exnumbers.WRITE:/'First result is (added 1): ',exnumbers-numb1.WRITE:/'Second result is (added 98): ',exnumbers-numb2.
The two numbers 1 and 2 are passed, and the results 2 and 100 are passed back.