3.Calling RFC .NET Server from SAP Programs
To execute our .NET server stub application from the SAP system we need to execute the ABAP command Call function X Destination Y. This report calls our proxy and writes the results to screen. Alternatively, you can use the SAP function module』s single test capability with the TRFC destination for your .NET server stub.
To create a TRFC destination for the SAP .NET server stub create a destination of type T (TRFC) in transaction code SM59. The program ID in your server stub is case sensitive.
Example
*&---------------------------------------------------------------------
*& Report ZRFCSERVERCALL
**&--------------------------------------------------------------------
*& This program can be used with the RFCServerConsole sample
*& Source is available in %RFCServerConsoleABAPProgram
*&---------------------------------------------------------------------
REPORT ZRFCSERVERCALL .
DATA: TBLCUST like BRFCKNA1 occurs 0 with header line.
PARAMETERS: P_CUSTNO like KNA1-KUNNR, P_CUSTNA like KNA1-NAME1,
P_DEST(15) TYPE C.
CALL FUNCTION 'RFC_CUSTOMER_GET' DESTINATION P_DEST
EXPORTING
KUNNR = P_CUSTNO
NAME1 = P_CUSTNA
TABLES
CUSTOMER_T = TBLCUST
EXCEPTIONS
NOTHING_SPECIFIED = 1
NO_RECORD_FOUND = 2
OTHERS = 3.
CASE SY-SUBRC.
WHEN 0.
LOOP AT TBLCUST.
WRITE: / SY-TABIX, TBLCUST-KUNNR, TBLCUST-NAME1, TBLCUST-ORT01.
ENDLOOP.
WHEN 1.
WRITE: / 'You need to specify a value ', SY-MSGV1.
WHEN 2.
WRITE: / '.NET component didnt find anything ', SY-MSGV1.
WHEN 3.
WRITE: / 'Some other error occurred ', SY-MSGV1.
WHEN OTHERS.
WRITE: / 'Something is wrong if we get here'.
ENDCASE.
The entry point in the C# method is the method with the function module name being called from the SAP system (for example, RFC_CUSTOMER_GET). In Microsoft Visual Studio, you can set a breakpoint here and examine the input values from the SAP system. This provides a similar idea to the ABAP_DEBUG functionality that is provided in the client proxy.
RFCServerConsole - is an SAP RFC Server implemented in C#.
The SAP system calls out to this .net component.
This component implements, RFC_CUSTOMER_GET and will return 2 customers to SAP. Before calling this
component from inside of SAP, you'll need a TCP/IP destination (SM59) - (type registration). Set the
SAP connection in the Visual Studio project properties for RFCServerConsole (e.g. right click on it)
Properties > Configuration Properties > Debugging > Command line arguments.
(example -aSomeProgID -gLOCALHOST -xSAPGW00)
The program id (-a) parameter must match exactly in your component and in the TCP/IP destination (SM59)
All you have to do in sm59 is write RFC destination , Program ID , Description .
The Program ID is important ,because it is just the SomeProgID (example -aSomeProgID -gLOCALHOST -xSAPGW00)run RFCServerConsole.exe -aSomeProgID -gLOCALHOST -xSAPGW00 in commond.exe