Skip to Content
0
Former Member
Sep 18, 2007 at 03:43 PM

Need Code Example to Call a SAP Remote Function from C#

452 Views

I'm looking for an example of how to call a SAP RFC from within a C#

program. I've tried numerous searches and have come up empty handed. If I have a function called "MyFunction" and it takes 1 input parameter and returns one output parameter (a table) how would it be coded. I have been able to code the connection and it works so once the connection is established I need to call the funcation. Any pointers are really appreciated. Environment is MS VS Developer 2003, Frameworks 1.1, SAP 4.6C Here is the code so far.

using System;

using SAP.Connector;

using SAP.Connector.Rfc;

using SAP.Connector.Internal;

namespace ConsoleApplication2

{

/// <summary>

/// Summary description for Class1.

/// </summary>

class Class1

{

static void Main(string[] args)

{

SAP.Connector.Destination dest = new SAP.Connector.Destination();

dest.AppServerHost = "NAFTATEST01.SAP.INTRA";

dest.Client = 300;

dest.SystemNumber = 0;

dest.Username = "myusername";

dest.Password = "mypassword";

SAP.Connector.SAPConnection connSAP = new

SAP.Connector.SAPConnection(dest);

using(connSAP)

{

try

{

connSAP.Open();

Console.WriteLine("SAP Connection was opened...");

connSAP.Close();

}

catch(SAP.Connector.RfcException rfcEx)

{

Console.WriteLine("SAP Connection was failed...");

Console.WriteLine( rfcEx.Message

+ rfcEx.StackTrace);

Console.WriteLine();

}

}

}

}