示例#1
0
        public static void Run()
        {
            string connStr = "connectionstring";

            using var connection = new SapConnection(connStr);
            connection.Connect();

            using var someFunction = connection.CreateFunction("MySapfunction");
            var result = someFunction.Invoke <SomeFunctionResult>(new
            {
                VBELN = "partnumber",
            });
        }
示例#2
0
 static void Main(string[] args)
 {
     try
     {
         Console.WriteLine("/************************ rfc .net core support *************************");
         Console.WriteLine("   Author(s):   christ chang");
         Console.WriteLine("   Description: rfc .net core support");
         Console.WriteLine("   github: https://github.com/Nightstars/rfc_demo");
         Console.WriteLine("   thanks: huysentruitw and his work ");
         Console.WriteLine("************************************************************************/");
         //define connect string
         string connectionString = "AppServerHost=192.168.95.20; SystemNumber=00; User=ZBT_RFC; Password=Zbt_rfc123; Client=310; Language=ZH; PoolSize=5; Trace=8;";
         //structure rfc connection
         using var connection = new SapConnection(connectionString);
         //open rfc connection
         connection.Connect();
         //structure call function by rfc target fun
         using var someFunction = connection.CreateFunction("ZMDG_MDATA_INFO");
         //call remote rfc functon with input parameter constructor and get fun result
         rfc_demo.FunctionResult result = someFunction.Invoke <FunctionResult>(new FunctionParameters
         {
             Ibukrs = "1010",
             Iztype = "2",
             Izdata = "20200801",
             Iztime = "00:00:00"
         });
         //print result in console
         foreach (ZMDGS003 item in result.result)
         {
             Console.WriteLine(item.Mdata);
             Console.WriteLine(item.Meinst);
             Console.WriteLine(item.Groes);
             Console.WriteLine(item.Zspm);
             Console.WriteLine(item.Maktx);
             Console.WriteLine(item.Bukrs);
             Console.WriteLine();
         }
         Console.ReadKey();
     }catch (Exception e)
     {
         Console.WriteLine("Oh no: " + e.Message);
         Console.ReadKey();
     }
 }
示例#3
0
        public ClassRfcReadTable SapReadTable(string query_table, string delimiter, string no_data, string fields, string filter)
        {
            SapLibrary.EnsureLibraryPresent();
            ClassRfcReadTable data = null;
            // System.Console.WriteLine("Starting...");
            var connectionString = ConfigurationManager.AppSettings["ConnectionString"];

            using var conn = new SapConnection(connectionString);
            conn.Connect();
            // Console.WriteLine("SAP Connction was opened...");
            ClassRfcReadTableInput fc = new ClassRfcReadTableInput();

            fc.QueryTable = query_table;
            fc.Delimiter  = delimiter;
            fc.NoData     = no_data;
            string[] af = fields.Split(',');
            fc.Fields = new RFC_DB_FLD[af.Length];
            for (int i = 0; i < af.Length; i++)
            {
                fc.Fields[i]           = new RFC_DB_FLD();
                fc.Fields[i].FieldName = af[i];
            }
            string[] ao = filter.Split(',');
            if (ao != null && ao.Length > 0)
            {
                fc.Options = new RFC_DB_OPT[ao.Length];
            }
            for (int i = 0; i < ao.Length; i++)
            {
                fc.Options[i] = new RFC_DB_OPT();
                if (!string.IsNullOrEmpty(ao[i]))
                {
                    if (ao[i].Length > 72)
                    {
                        throw new Exception("Error by rfc_read_table:; an option string is longer as 72 -> " + ao[i]);
                    }
                    fc.Options[i].Text = ao[i];
                }
            }
            using var func = conn.CreateFunction("RFC_READ_TABLE");
            data           = func.Invoke <ClassRfcReadTable>(fc);
            return(data);
        }
        public void CreateFunction_ShouldCreateFunction()
        {
            // Arrange
            var          connection = new SapConnection(_interopMock.Object, new SapConnectionParameters());
            RfcErrorInfo errorInfo;

            _interopMock
            .Setup(x => x.OpenConnection(It.IsAny <RfcConnectionParameter[]>(), It.IsAny <uint>(), out errorInfo))
            .Returns(RfcConnectionHandle);
            _interopMock
            .Setup(x => x.GetFunctionDesc(RfcConnectionHandle, "FunctionA", out errorInfo))
            .Returns(FunctionDescriptionHandle);

            connection.Connect();

            // Act
            ISapFunction function = connection.CreateFunction("FunctionA");

            // Assert
            function.Should().NotBeNull();
            _interopMock.Verify(x => x.CreateFunction(FunctionDescriptionHandle, out errorInfo), Times.Once);
        }