Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            using (var connection = new SapConnection("DEV"))
            {
                connection.Open();

                var session = new SapSession(connection);

                //var transaction = connection.BeginTransaction();

                var command = new SapCommand("BAPI_GET_PROJECT_DETAILS_TABLE", connection);

                command.Parameters.Add("PROJECT_TYPE","EP");

                session.StartSession();

                var resultDataSet = command.ExecuteDataSet();

                session.EndSession();

                var sapDataReader = command.ExecuteReader("RESULTS");

                
                var i = 0;
                while(sapDataReader.Read())
                {
                    Console.WriteLine("{0} : {1}",i,sapDataReader.Item.GetString(0));
                    i++;
                }

                Console.WriteLine(sapDataReader.RowCount);

                //transaction.Commit();
                //var rfcTables = command.ExecuteRfcTables();

            }

            Console.WriteLine("Done !");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            using (var connection = new SapConnection("DEV"))
            {
                connection.Open();

                var session = new SapSession(connection);

                //var transaction = connection.BeginTransaction();

                var command = new SapCommand("BAPI_GET_PROJECT_DETAILS_TABLE", connection);

                command.Parameters.Add("PROJECT_TYPE", "EP");

                session.StartSession();

                var resultDataSet = command.ExecuteDataSet();

                session.EndSession();

                var sapDataReader = command.ExecuteReader("RESULTS");


                var i = 0;
                while (sapDataReader.Read())
                {
                    Console.WriteLine("{0} : {1}", i, sapDataReader.Item.GetString(0));
                    i++;
                }

                Console.WriteLine(sapDataReader.RowCount);

                //transaction.Commit();
                //var rfcTables = command.ExecuteRfcTables();
            }

            Console.WriteLine("Done !");
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Execute SAP RFC-function.
        /// </summary>
        /// <param name="function">Name of the SAP function</param>
        /// <returns>JToken dictionary of export parameter or table values returned by SAP function.</returns>
        public static dynamic ExecuteFunction(ExecuteFunctionInput taskInput)
        {
            var           connectionParams = ConnectionStringToDictionary(taskInput.ConnectionString.Value);
            var           returnvalues     = new JObject();
            FunctionInput input;
            IRfcFunction  sapFunction;

            if (taskInput.InputType == InputType.JSON)
            {
                try
                {
                    input = new FunctionInput(taskInput.InputFunctions);
                }
                catch (Exception e)
                {
                    throw new Exception("Failed to parse input JSON", e);
                }
            }
            else if (taskInput.InputType == InputType.PARAMETERS)
            {
                input = new FunctionInput();
                var structures = new List <Structure>();
                foreach (var s in taskInput.SimpleInput.Functions)
                {
                    structures.Add(new Structure
                    {
                        Name   = s.Name,
                        Fields = s.Fields
                    });
                }
                input.Functions = structures.ToArray();
            }
            else
            {
                throw new Exception("Invalid input type!");
            }

            using (var connection = new SapConnection(connectionParams))
            {
                connection.Open();

                var repo = connection.Destination.Repository;

                using (var session = new SapSession(connection))
                {
                    session.StartSession();

                    foreach (var f in input.Functions)
                    {
                        try
                        {
                            sapFunction = repo.CreateFunction(f.Name);
                        }
                        catch (Exception e)
                        {
                            throw new Exception($"Failed to create function: {e.Message}", e);
                        }

                        try
                        {
                            f.PopulateRfcDataContainer(sapFunction);
                        }
                        catch (Exception e)
                        {
                            throw new Exception($"Failed to populate function input structure: {e.Message}", e);
                        }


                        try
                        {
                            sapFunction.Invoke(connection.Destination);
                        }
                        catch (Exception e)
                        {
                            throw new Exception($"Invoking function failed: {e.Message}", e);
                        }

                        var tables       = GetTableNames(sapFunction);
                        var exportParams = GetExportParameters(sapFunction);

                        var tablesAsJObject = new JObject();

                        foreach (var table in tables)
                        {
                            var rfcTable = sapFunction.GetTable(table);
                            tablesAsJObject.Add(table, JToken.FromObject(RfcTableToDataTable(rfcTable, table)));
                        }

                        foreach (var parameter in exportParams)
                        {
                            tablesAsJObject.Add(parameter.Key, parameter.Value);
                        }

                        returnvalues.Add(f.Name, tablesAsJObject);
                    }

                    session.EndSession();
                }
            }

            return(returnvalues);
        }