0
Answer

Call SAP Remote Function from within C#

Ask a question
Michael Hudson

Michael Hudson

17y
7.1k
1
I'm looking for an example of how to call a SAP RFC from within a C#
program.  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.  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();
                                }
                        }
                }

        }