· 

How to build a RFC Server with NCo 3.0 Part 1

In some cases you want to trigger an external program from a SAP system. In this part 1 I explain how to build a RFC Server with NCo 3.0. I had several problems when I started with this topic so I decided to write a short example. If someone want the Visual Studio project files, please contact me.

 

So let's go.

 

This Post describes how to build a simple RFC Server using SAP NCo 3.0 and the app.config. Part 2 will be describe how to build a RFC Server with RFC Parameter. As example program I use STFC_CONNECTION. It is a good example, because it contains importing and exporting parameters.

 

First you have to download and install NCo 3.0 (OSS login required). Afterwards you have to start a new project in Visual Studio.

 

Setting up the Visual Studio Project:

 

In the properties of the project you have to use a new console application. As target framework I use .Net Framework 4.5.

Visual Studio Project Properties
Visual Studio Project Properties

Next you have to add references to the SAP .Net Connector. There are two DLLs (sapnco.dll and sapnco_utils.dll). Since NCo 3.0 SAP offers a help manual which describes all commands.

Visual Studio Project References
Visual Studio Project References

Define the SAP Connections

 

There are many methods you can use to define a SAP host. For a quick and simple solution you can use the app.config to define your SAP connection.

 

For basic RFC server configuration, there are two sections that are used. One section are the ClientSettings, the other the ServerSettings. A RFC server configuration is linked to a RFC repository by using the REPOSITORY_DESTINATION attribute. To be able to access function metadata, this attribute must match the name of a destination in the client settings.

 

All RFC servers communicate with a SAP system through a service called the SAP gateway service. The server settings defines how the application connects to the gateway. In the server section the NAME field identifies this entry to your RFC Connection in a SAP system. The SAP .Net Connector uses the values in the GWHOST, GWSERV and PROGRAM_ID fields to register your program on the SAP Gateway. The PROGRAM_ID must match the Registered Server Program of your RFC Destination.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<? xml version="1.0" encoding="utf-8" ?>
  <configuration>
    <configSections>
      <sectionGroup name="SAP.Middleware.Connector">
        <sectionGroup name="ServerSettings">
          <section name="ServerConfiguration" type="SAP.Middleware.Connector.RfcServerConfiguration, sapnco"/>
        </sectionGroup>
        <sectionGroup name="ClientSettings">
          <section name="DestinationConfiguration" type="SAP.Middleware.Connector.RfcDestinationConfiguration, sapnco"/>
        </sectionGroup>
      </sectionGroup>
    </configSections>
    <SAP.Middleware.Connector>
      <ServerSettings>
         <ServerConfiguration>
           <servers>
              <add NAME="DINOZZO" GWHOST="xxx.xxx.xxx.xxx" GWSERV="SAPGW00" PROGRAM_ID="STFC_CONNECTION" REPOSITORY_DESTINATION="ABC" REG_COUNT="1"/>
           </servers>
         </ServerConfiguration>
      </ServerSettings>
      <ClientSettings>
        <DestinationConfiguration>
          <destinations>
            <add NAME="ABC" USER="user" PASSWD="password" CLIENT="client" LANG="EN" ASHOST="xxx.xxx.xxx.xxx" SYSNR="00" />
          </destinations>
        </DestinationConfiguration>
      </ClientSettings>
    </SAP.Middleware.Connector>
    <startup>
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
  </configuration>

SAP Function module:

SAP transaction se37 can be used to find out the parameters for the STFC_CONNECTION. In this example, you receive a parameter REQUTEXT, which will be returned to the caller in ECHOTEXT. It also return a text string to the caller in field RESPTEXT.

 

Transaction sm59 is used to configure the RFC Destination. The name of the RFC Destination.

SAP RFC Destination
SAP RFC Destination

Coding:

 

First you have to create a class that exposes a method that can be called via a SAP RFC Call. In the example that class is named ServerFunction and it contains one method which will supply the STFC_CONNECTION functionality.

 

Add a new class in the Visual Studio

Visual Studio Add new class
Visual Studio Add new class

Import the NCo functions

Visual Studio Import SAP NCo Connector

Create a method, similar to this one

Visual Studio Method
Visual Studio Method

Now you have to implement the coding for Main()

 

First Import the NCo functions

Visual Studio Import SAP NCo Connector

Afterwards you have to create a similar coding

Visual Studio Sub
Visual Studio Sub

RfcServerManager.GetServer("DINOZZO", New Type(0) {GetType(ServerFunction)})

 

DINOZZO references to the RFC Destination name in transaction sm59 and in the app.config.

 

ServerFunction references to the class above.

 

The RFC Server will be started by following code: RemoteServer.Start

 

In SAP transaction SMGW >> Goto >> Logged on Clients you can now see your program running on the application gateway.

SAP Connection (transaction SMGW)
SAP Connection (transaction SMGW)

Now you can use the test function screen in transaction se37 to test STFC_CONNECTION. The RFC Target System is set to the name of the RFC destination (sm59)

SAP Test Function Module
SAP Test Function Module

Click Execute (F8)

SAP Result Function Module
SAP Result Function Module

The console will also display some information.

Console result
Console result

Part 2 will be describe how to build a RFC Server with a custom RFC repository and how to be flexible with RFC config parameters.

author.


I am Tobias, I write this blog since 2014, you can find me on twitter and youtube. If you want you can leave me a paypal coffee donation. You can also contact me directly if you want.

SAP Analysis for Office - The Comprehensive Guide
The book SAP Analysis for Office - The Comprehensive Guide by Tobias Meyer is a pdf book about SAP Analysis for Office. It is based on Analysis for Office 2.8 and contains 346 Pages.
45,00 €
SAP Analysis for Office - The Comprehensive Guide
SAP Analysis for Office - The Comprehensive Guide is a pdf book about SAP BusinessObjects Analysis for Office. It is based on Analysis for Office 2.7 and contains 299 Pages.
37,00 €
SAP Analysis for Office - The Comprehensive Guide
SAP Analysis for Office - The Comprehensive Guide is a pdf book about SAP BusinessObjects Analysis for Office. It is based on Analysis for Office 2.6 and contains 272 Pages.
27,00 €

Write a comment

Comments: 1
  • #1

    Shubham (Monday, 28 December 2020 11:43)

    Hi
    I am trying to build the rfc server with NCo 3.0 by following your approach ,In the .net project is debugging without any error but the rfc server not visible in smgw Transaction code on th SAP side .
    Can u please help.
    Thanks,
    Shubham