Giter VIP home page Giter VIP logo

nwrfcnet's Introduction

.NET client library for SAP NetWeaver RFC

An easy way of making SAP RFC calls from .NET. Libray is supported in Windows, Linux and macOS.

Supported Platforms & Prerequisites

  • Requires .NET Framework ( .NET Standard 2.0 or higher )

    • .NET Framework 4.6.1 or higher
    • .NET Core 2.0 or higher
  • OS versions

    • Windows x64.
    • Redhat Linux 7 or other Linux distribution that is supported simultaneously by .NET Core and SAP NetWeaver RFC.
    • macOS 10.12+.
  • SAP NetWeaver RFC Library 7.50 SDK C++ binaries must be installed locally. For download and installation instructions check SAP Note 2573790

Using this package

Add the package using the dotnet cli:

$ dotnet add package NwRfcNet

Create a class to match SAP RFC parameters

    public class BapiCompanyOutputParameters
    {
        public CompanyDetails[] Details { get; set; }
    }

    public class CompanyDetails
    {
        public string CompanyCode { get; set; }

        public string Name { get; set; }
    }

Map RFC mapameters to class

    RfcMapper mapper = new RfcMapper();

    mapper.Parameter<BapiCompanyOutputParameters>().Property(x => x.Details)
        .HasParameterName("COMPANYCODE_LIST")
        .HasParameterType(RfcFieldType.Table);

    mapper.Parameter<CompanyDetails>().Property(x => x.CompanyCode)
        .HasParameterName("COMP_CODE")
        .MaxLength(4)
        .HasParameterType(RfcFieldType.Char);

    mapper.Parameter<CompanyDetails>().Property(x => x.Name)
        .HasParameterName("COMP_NAME")
        .MaxLength(25)
        .HasParameterType(RfcFieldType.Char);

Open a connection to server and invoke a BAPI

    using (var conn = new RfcConnection(builder => builder
        .UseConnectionHost("hostname")
        .UseLogonUserName("user")
        .UseLogonPassword("password")
        .UseLogonClient("cln")))
    {
        conn.Open();
        using(var func = conn.CallRfcFunction("BAPI_COMPANYCODE_GETLIST"))
        {
            func.Invoke();
        }
    }

or

    using (var conn = new RfcConnection("Server=server_name;lang=en;user=testUser;pwd=secret"))
    {
        conn.Open();
        using(var func = _conn.CallRfcFunction("BAPI_COMPANYCODE_GETLIST"))
        {
            func.Invoke();
        }
    }

Get result and display to Console

    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));
    }

Output should be

Company Code Company Name
C001 company 1
C002 Company 2

Samples

Included samples in project

  • List FI Companies
  • List FI Customers
  • Get Details of a FI Customer
  • FI General Ledger Account
  • RFC Read Table

Connection String

Example : Server=server_name;lang=en;user=testUser;pwd=secret

Value Alias
User Name "userName", "userId", "uid", "user", "u"
password "password", "passwd", "pass", "pwd", "p"
Host "target_host", "targetHost", "host", "server", "h"
Logon Language "language", "lang", "l"
System Client "client", "cl", "c"
SystemNumber "system_number", "systemnumber", "sysnr"
SystemId "system_id", "systemid", "sysid"
Trace "trace", "tr", "RfcSdkTrace"
Snc Mode "snc_mode", "sncmode", "UseSnc", "snc"
Snc Qop "snc_partnername", "sncpartnername", "snc_partner", "sncpartner"
Snc Lib "snc_library", "snc_lib", "snclib"

nwrfcnet's People

Contributors

davidstahl97 avatar escoto avatar hechtag avatar insonusk avatar mhudasch avatar nunomaia avatar oliver-hermann avatar shaggygi avatar tomisoft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nwrfcnet's Issues

Connection string

The connection to include the server name, and other parameters needed to establish the initial connection.

Question

How to receive the RETURN of a BAPI

Sample:

BAPI_PROC_MESS_DEST_RECEIVE_PM

  • PROC_MESS_HEADER
  • PROC_MESS_CHARAC
  • PROC_MESS_TEXTLINES

those Tables we are sending successfull

But we are not able to Rewceive#

  • RETURN

what to do?

Suggestion: Associate RfcMapper with RfcFunction rather than RfcConnection

This is just an idea (and you might have reason for not doing things this way), but in my mind it seems more logical to associate the mapper with a specific RfcFunction rather than the RfcConnection, so multiple mappers would be used where multiple function calls are required, rather than a single generic RfcConnection.Mapper (RfcFunction.DefaultMapper).

How to package SAP Netweaver DLLs with my deployment

I am trying to get this to work with a .net core web application. I keep getting an error about PATH. I know I can set this up locally and configure PATH, but how do I package this to deploy to the webserver? Do I have to setup PATH on all the webservers as well? How would this work in a kubernetes environment?

Handle large RFC String parameters values

Isn't possible to read RFC String parameters with a length larger then 1024.
Check if native library function return buffer to small, increase size and try to read again.

        if (rc == RfcInterop.RFC_RC.RFC_BUFFER_TOO_SMALL)
        {
            buffer = new char[bufferLength];
            rc = RfcInterop.RfcGetString(dataHandle, name, buffer, (uint)buffer.Length, out bufferLength, out errorInfo);
        }

sapnwrfc.dll

Hi.
It's seems that the package requires sapnwrfc.dll.
Correct?

can you support automatic load of SAP NetWeaver RFC Library DLL?

can you support automatic load of SAP RFC Native Library DLL?
such as :
win64>icudt50.dll/icuin50.dll/icuuc50.dll/libicudecnumber.dll/libsapucum.dll/sapnwrfc.dll
linux64>libicudata.so.50/libicudecnumber.so/libicui18n.so.50/libicuuc.so.50/libsapnwrfc.so/libsapucum.so

Generic Output

Is it possible to work with generic output instead of defining Outputs for every function call?

Async & Mapping with attributes request

Hi,

Thats the only one libray ever that i found over the web which using netweaver and supporting .net core. Thanks for all.

I'd like to use it on some asp.net core app as an integration. Adding async support would be great.

Also if possible, could you add some attribute mapping ?

Instead:

mapper.Parameter<SomeOutputClass>().Property(x => x.SomeProp)
        .HasParameterName("SOME_MAPPED_FIELD")
        .HasParameterType(RfcFieldType.SomeType);

Using attribute mapping like:

public class SomeOutputClass
{
[RfcParam("SOME_MAPPED_FIELD", RfcFieldType.SomeType, "Maybe some description here")]
 public string SomeProp {get; set;}
}

Connection open issues

Hi nunomaia

As issues below

Could not open the ICU common library.
The following files must be in the path described by
the environment variable "PATH":
icuuc50.dll, icudt50.dll, icuin50.dll [D:/depot/bas/753_REL/src/flat/nlsui0.c 662] pid = 25568

Thanks.

Date Mapping Bug

I'm calling a rfc function with the Date input parameter. I'm mapping the value as a RFC date object.

I've tried changing the .Net object from DateTime, string, & tried adding different max lengths to the abap object. All of these get the same error:

image

Cannot load SAP NetWeaver RFC into container

I try to build .net core container (mcr.microsoft.com/dotnet/core/sdk:3.0-alpine + mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine).

On loading sapnwrfc.dll, I get an error "Unable to load shared library '/app/libs/nwrfcnet/sapnwrfc.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: Error loading shared library /app/libs/nwrfcnet/sapnwrfc.dll: Exec format error"

In issue #32 author has got .so libs, but in SAP Note 2573790 I could not find these such libs.

By the way, I load NwRfcNet lib not from Nuget, but directly from DLL. Because the last pull request has not been uploaded to NuGet yet.

Unable to connect to table with RFC_READ_TABLE function

When trying to connect a table via the RFC_READ_TABLE function I receive the following error:
image
According to this source https://success.jitterbit.com/display/DOC/Guide+to+Using+RFC_READ_TABLE+to+Query+SAP+Tables its returning a table not found error:
image

namespace SapFunctions.ReadTable
{

public static class SapReadTable
{
    //private RfcConnection _conn = new RfcConnection();
    /// <summary>
    /// ReadTable
    /// </summary>
    /// <param name="sTableName">string</param>
    /// <param name="saFields">string[]</param>
    /// <param name="saOptions">string[]</param>
    /// <param name="sSortField">string with name and direction</param>
    /// <param name="iMaxRowCount">int</param>
    /// <returns>DataTable or empty</returns>
    public static string[] ReadTable(string sTableName, in string[] saFields, in string[] saOptions, in string sSortField, int iMaxRowCount = 0)
    {
        using (RfcConnection _conn = new RfcConnection(hostname: "XXXXX.de.ina.com", client: "XX",language: "EN",systemNumber:"XX",
            sncQop: "X",
            sncPartnername: "XXX",
            sncLib: "qgsskrb5.dll"
            ))
        {
            _conn.Open();
            sTableName = "MARA";
            using (RfcFunction f = _conn.CallRfcFunction("RFC_READ_TABLE"))
            {
                ParameterMapping();
                f.Invoke(new SAPInputs
                {
                    QueryTable = sTableName,
                    Delimiter = ";",
                    No_Data = "",
                    RowCount = 0,
                    RowSkips = 0
                });

                var out_T = f.GetOutputParameters<SAPTableOutput>();


            }
        }


        return new string[] { };
    }


    static void ParameterMapping()
    {
        var mapper = RfcMapper.DefaultMapper;

        mapper.Parameter<SAPInputs>()
            .Property(x => x.QueryTable)
            .HasParameterName("QUERY_TABLE")
            .HasParameterType(RfcFieldType.Char).MaxLength(60);

        mapper.Parameter<SAPInputs>()
            .Property(x => x.Delimiter)
            .HasParameterName("DELIMITER")
            .HasParameterType(RfcFieldType.Char).MaxLength(2);

        mapper.Parameter<SAPInputs>()
            .Property(x => x.No_Data)
            .HasParameterName("NO_DATA")
            .HasParameterType(RfcFieldType.Char).MaxLength(2);


        mapper.Parameter<SAPInputs>()
      .Property(x => x.RowCount)
      .HasParameterName("ROWCOUNT")
      .HasParameterType(RfcFieldType.Int);
        
        mapper.Parameter<SAPInputs>()
      .Property(x => x.RowSkips)
      .HasParameterName("ROWSKIPS")
      .HasParameterType(RfcFieldType.Int);

        mapper.Parameter<SAPTableOutput>()
            .Property(x => x.Fields)
            .HasParameterName("FIELDS")
            .HasParameterType(RfcFieldType.Table);

        mapper.Parameter<SAPTableOutput>()
            .Property(x => x.Options)
            .HasParameterName("OPTIONS")
            .HasParameterType(RfcFieldType.Table);

        mapper.Parameter<SAPTableOutput>()
            .Property(x => x.Data)
            .HasParameterName("DATA")
            .HasParameterType(RfcFieldType.Table);
    }
}

public class SAPInputs
{
    public string QueryTable { get; set; }
    public string Delimiter { get; set; }
    public string No_Data { get; set; }
    public int RowSkips { get; set; }
    public int RowCount { get; set; }
}

public class SAPTableOutput
{
    public string[] Fields { get; set; }
    public string[] Options { get; set; }
    public string[] Data { get; set; }
}

}

RFC type Char

Move native libary functions to a new RfcChar class

Error in 'GetOutputParameters' despite mapping the output class

I'm calling the SAP function like that

            using (var conn = new RfcConnection(builder => builder
                            .UseConnectionHost(_sapConfig.ServerHost)
                            .UseLogonUserName(_sapConfig.Username)
                            .UseLogonPassword(_sapConfig.Password)
                            .UseLogonClient(_sapConfig.Client)))
            {
                conn.Open();
                using (var func = conn.CallRfcFunction(_sapConfig.FuncName))
                {
                    func.Mapper = new RfcMapper();

                    func.Mapper.Parameter<SapFunctionParameters>().Property(x => x.EmployeeID)
                        .HasParameterName("EMP_NO")
                        .HasParameterType(RfcFieldType.Int8);

                    func.Mapper.Parameter<SapFunctionParameters>().Property(x => x.RunDate)
                        .HasParameterName("RUN_DATE")
                        .HasParameterType(RfcFieldType.Date);

                    func.Mapper.Parameter<BapiOutput>().Property(x => x.Details)
                        .HasParameterName("PA0000_OUT")
                        .HasParameterType(RfcFieldType.Table);


                    func.Mapper.Parameter<SapFunctionResults>().Property(x => x.MANDT)
                       .HasParameterName("MANDT")
                       .HasParameterType(RfcFieldType.String);


                    func.Mapper.Parameter<SapFunctionResults>().Property(x => x.PERNR)
                       .HasParameterName("PERNR")
                       .HasParameterType(RfcFieldType.Int8);

                    func.Invoke(new SapFunctionParameters { EmployeeID = 1692, RunDate = new DateTime(2021, 1, 1) });

                    var output = func.GetOutputParameters<BapiOutput>();
                }
            }

calling the function which returns a table of parameters as shown in the image
issue1

and I'm mapping two columns of the returned table to a class

public class BapiOutput
{
    public SapFunctionResults[] Details { get; set; }
}

public class SapFunctionResults
{
    public string MANDT { get; set; }
    public long PERNR { get; set; }
}

getting error NwRfcNet.RfcException: 'Type BapiOutput is not mapped'

Connecting to a message server

Hello,

thank you for your work on this package, I really appreciate it!

I was wondering if you support connecting to a message server since the constructor does not accept the parameters MSHOST, R3NAME/SystemId and GROUP.
Am I missing something here?
I'm not an SAP dev, just trying to interface with it, so excuse me if I'm on the wrong track..

If you do not support it, do you plan on adding support?

Cheers

Bug

System.DllNotFoundException: Unable to load DLL 'sapnwrfc' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.