Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args).WithParsed <Options>(o =>
            {
                try
                {
                    var version = RfcConnection.GetLibVersion();
                    Console.WriteLine($"currently loaded sapnwrfc library version : Major {version.MajorVersion}, Minor {version.MinorVersion}, patchLevel {version.PatchLevel}");

                    using (var conn = new RfcConnection(userName: o.UserName, password: o.Password, hostname: o.Hostname, client: o.Client))
                    {
                        ParameterMapping();
                        conn.Open();
                        using (var func = conn.CallRfcFunction("BAPI_COMPANYCODE_GETLIST"))
                        {
                            func.Invoke();
                            var returnValue = func.GetOutputParameters <BapiCompanyOutputParameters>();
                            Console.WriteLine(String.Format("|{0,-20}|{1,-10}", "Company Code", "Company Name"));
                            foreach (var row in returnValue.Details)
                            {
                                Console.WriteLine(String.Format("|{0,-20}|{1,-10}", row.CompanyCode, row.Name));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw;
                }
            });
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args)
            .WithParsed <Options>(o =>
            {
                try
                {
                    ParameterMapping();

                    var version = RfcConnection.GetLibVersion();
                    Console.WriteLine($"currently loaded sapnwrfc library version : Major {version.MajorVersion}, Minor {version.MinorVersion}, patchLevel {version.PatchLevel}");

                    using (var conn = new RfcConnection(builder => builder
                                                        .UseConnectionHost(o.Hostname)
                                                        .UseLogonUserName(o.UserName)
                                                        .UseLogonPassword(o.Password)
                                                        .UseLogonClient(o.Client)))
                    {
                        conn.Open();
                        using (var func = conn.CallRfcFunction("RFC_READ_TABLE"))
                        {
                            var inParams = new RfcParametersInput
                            {
                                QueryTable = "T001",
                                Delimiter  = ";",
                                No_Data    = "",
                                RowCount   = 0,
                                RowSkips   = 0
                            };

                            func.Invoke(inParams);

                            var result = func.GetOutputParameters <RfcParametersOutput>();

                            if (result.Data == null)
                            {
                                Console.WriteLine("No Data");
                            }

                            foreach (var r in result.Data)
                            {
                                Console.WriteLine(r.Wa);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw ex;
                }
            });
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args)
            .WithParsed <Options>(o =>
            {
                try
                {
                    ParameterMapping();

                    var version = RfcConnection.GetLibVersion();
                    Console.WriteLine($"currently loaded sapnwrfc library version : Major {version.MajorVersion}, Minor {version.MinorVersion}, patchLevel {version.PatchLevel}");

                    using (var conn = new RfcConnection(builder => builder
                                                        .UseConnectionHost(o.Hostname)
                                                        .UseLogonUserName(o.UserName)
                                                        .UseLogonPassword(o.Password)
                                                        .UseLogonClient(o.Client)))
                    {
                        conn.Open();
                        using (var func = conn.CallRfcFunction("BAPI_GL_GETGLACCPERIODBALANCES"))
                        {
                            var inParams = new BapiParametersInput
                            {
                                CompanyCode  = o.Company,
                                CurrencyType = "10",        // document Currency
                                FiscalYear   = o.FiscalYear,
                                GlAccount    = o.GlAccount
                            };
                            func.Invoke(inParams);

                            var result = func.GetOutputParameters <BapiParametersOutput>();

                            Console.WriteLine(String.Format("|{0,-6}|{1,-6}|{2,-10}|{3,-10}", "Company", "Period", "Debit", "Credit"));
                            foreach (var row in result.Detail)
                            {
                                Console.WriteLine(String.Format("|{0,-6}|{1,-6}|{2,-10}|{3,-10}",
                                                                row.CompanyCode,
                                                                row.FiscalPeriod,
                                                                row.TotalCredit.ToString(),
                                                                row.TotalDebit.ToString()
                                                                ));;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw ex;
                }
            });
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args)
            .WithParsed <Options>(o =>
            {
                try
                {
                    ParameterMapping();

                    var version = RfcConnection.GetLibVersion();
                    Console.WriteLine($"currently loaded sapnwrfc library version : Major {version.MajorVersion}, Minor {version.MinorVersion}, patchLevel {version.PatchLevel}");

                    using (var conn = new RfcConnection(userName: o.UserName, password: o.Password, hostname: o.Hostname, client: o.Client))
                    {
                        conn.Open();
                        using (var func = conn.CallRfcFunction("BAPI_CUSTOMER_GETLIST"))
                        {
                            var inParams = new ListCustomersInputParameters
                            {
                                MaxRows = 10,
                                Range   = new IdRange[]
                                {
                                    new IdRange()
                                    {
                                        Sign = "I", Option = "BT", High = "ZZZZZZZZZZ"
                                    }
                                }
                            };

                            func.Invoke(inParams);
                            var returnValue = func.GetOutputParameters <ListCustomersOutputParameters>();

                            Console.WriteLine(String.Format("|{0,-20}|{1,-10}", "Customer Number", "Customer Name"));
                            foreach (var row in returnValue.Addresses)
                            {
                                Console.WriteLine(String.Format("|{0,-20}|{1,-10}", row.CustomerId, row.Name));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw ex;
                }
            });
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args)
            .WithParsed <Options>(o =>
            {
                try
                {
                    ParameterMapping();

                    var version = RfcConnection.GetLibVersion();
                    Console.WriteLine($"currently loaded sapnwrfc library version : Major {version.MajorVersion}, Minor {version.MinorVersion}, patchLevel {version.PatchLevel}");

                    using (var conn = new RfcConnection(builder => builder
                                                        .UseConnectionHost(o.Hostname)
                                                        .UseLogonUserName(o.UserName)
                                                        .UseLogonPassword(o.Password)
                                                        .UseLogonClient(o.Client)))
                    {
                        conn.Open();
                        using (var func = conn.CallRfcFunction("BAPI_CUSTOMER_GETDETAIL2"))
                        {
                            var inParams = new CustomerDataInput {
                                Customer = o.Customer
                            };
                            func.Invoke(inParams);

                            var result = func.GetOutputParameters <CustomerDataOutput>();

                            Console.WriteLine(String.Format("|{0,-20}|{1,-20}|{2,-20}|{3,-20}", "Customer Number", "Create Date", "Confirm Date", "Confirm Time"));

                            Console.WriteLine(String.Format("|{0,-20}|{1,-20}|{2,-20}|{3,-20}",
                                                            result.Detail.Customer,
                                                            result.Detail.CreateDate?.ToString("yyyy-MM-dd") ?? "Not Defined",
                                                            result.Detail?.ConfirmDate?.ToString("yyyy-MM-dd") ?? "Not Defined",
                                                            result.Detail?.ConfirmationTime?.ToString() ?? "Not Defined")
                                              );
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw ex;
                }
            });
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args)
            .WithParsed(o =>
            {
                var version = RfcConnection.GetLibVersion();
                Console.WriteLine($"currently loaded sapnwrfc library version : Major {version.MajorVersion}, Minor {version.MinorVersion}, patchLevel {version.PatchLevel}");

                /**
                 * Use the connection builder fluent api.
                 */
                using (var conn = new RfcConnection(builder => builder
                                                    .UseConnectionHost(o.Hostname)
                                                    .UseLogonUserName(o.UserName)
                                                    .UseLogonPassword(o.Password)
                                                    .UseLogonClient(o.Client)))
                {
                    conn.Open();
                    conn.Ping();
                    // do something more interesting here...
                }


                /**
                 * Use the connection string api.
                 */
                using (var conn = new RfcConnection(connectionString: $"Server={o.Hostname}; Uid={o.UserName}; Passwd={o.Password}; Client={o.Client}"))
                {
                    conn.Open();
                    conn.Ping();
                    // do something more interesting here...
                }

                /**
                 * Use the connection uri api.
                 */
                using (var conn = new RfcConnection(connectionUri: new Uri($"sap://user={ Uri.EscapeDataString(o.UserName) };passwd={ Uri.EscapeDataString(o.Password) };client={o.Client}@A/{o.Hostname}")))
                {
                    conn.Open();
                    conn.Ping();
                    // do something more interesting here...
                }
            });
        }