Click here to Skip to main content
12,955,493 members (59,639 online)
Click here to Skip to main content
Add your own
alternative version


82 bookmarked
Posted 23 May 2007

Transferring Data from SAP to .NET using ERPConnect

, 23 May 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
Description of an interface programming tool for SAP and .NET integration.


In my last customer project, I had to implement a kind of "quick ordering software" for a machine manufacturer company. The goal of this project was to give the construction engineers the possibility to send an auto-generated order list to the buying department. The construction department uses a PDM system based on SQL Server 2000, with an Access front-end, while the buying department and the other economic departments use a SAP system. So, the main task in my project was to implement an interface for these two systems, especially to receive the necessary data from the SAP system into my .NET application. After a short search on the Internet, I found ERPConnect by Theobald Software. This tool allowed me to directly access the data from BAPIs and Tables in the SAP system I needed.

On The Code Project, I only found some articles about the .NET Connector by SAP, but no article dealing with ERPConnect, so I thought that it might be interesting for the other users to read about the usage, the features, and my personal experience with a second tool for SAP interface programming. Because of understandable reasons, I don't want to publish the code of my customer project, so I wrote two examples that explain the usage of ERPConnect basically. The first example deals with BAPI access, while the second example deals with directly reading from SAP tables.

I have included the two examples in VB.NET and C# in the download section above. I have removed the SAP login and connection data from the projects; to try the examples, you have to fill them with your own connection and login information.

SAP Background

For those of you with no SAP experience, I want to explain the most important SAP terms for interface programming.

Function Modules: A Function Module is equivalent to a normal function/procedure in any conventional programming language. Function Modules are SAP integrated modules written in ABAP and are accessible from any other ABAP program in the System. Like a function in any other programming language, Function Modules accept import and export parameters. Function modules also provide a third opportunity the bidirectional Tables. To access a Function Module from outside SAP (just like in our case) the Function Module has to be RFC-enabled. There is also a possibility to access Function Modules being RFC-disabled, this possibility I want to describe later in this article.

BAPIs: BAPIs work like Function Modules, the only difference is that they are the programming interface (API) for the SAP Business Object Repository.

IDocs: IDocs are used to exchange data between two SAP systems or an SAP system and a subsystem. You can imagine IDocs as an electronic kind of receipt written on paper. An IDoc can be uniquely identified by its name (and eventually the name of its extension). IDocs are also well structured; they have a header containing administrative information like the sender, information about the receiving system and the transport. Beside the header an IDoc has segments that are hierarchical like a tree structure. Every segment has one or more fields containing the economic data.

SAP Queries: SAP Queries work just like any other query. For unique identifying of a SAP Query there are three pieces of information necessary: user area (global or local); user group and the name of the query.

How to use ERPConnect

After installing ERPConnect on your computer, you just have to add a reference (ERPConnect.dll for use with .NET Framework 1.1 or ERPConnect20.dll for use with .NET Framework 2.0) to your project and add the using ERPConnect; statement in the header, that's all.

Example 1: Reading Data from a BAPI using the RFCFunction Object

In this short example, I want to show you how to receive the BANK_KEY value of customer 0000001172 and display the result on the console.

After creating a R3Connection object and opening the connection, we create a RFCFunction object on the connection calling our BAPI. Then we fill the Exports parameter of our RFC function object with the Import parameter of the BAPI. That means we send the Import value to the BAPI. After this is done, we execute the function and extract the data of interest from the result table. That's all.

class Program
    static void Main(string[] args)

    static void Connect()
        ERPConnect.LIC.SetLic("licence code");

        //creating the connection object
        R3Connection con = new R3Connection("name of the application server",
                    "system number",
        //open the connection
        //creating the RFCFunction object 
        RFCFunction func = con.CreateFunction("BAPI_CUSTOMER_GETDETAIL2");

        //sending the import parameter to the BAPI 
        func.Exports["CUSTOMERNO"].ParamValue = "0000001172";

            //execute the function
        catch (ERPException e)

        /*Reading the BANK_KEY from func and store it in a string.
        We do only have one row in our result table, because there 
        can be only one customer according to our customer number
        so we only have to select the column of interest from the result table*/
        string Bank_Key = 
        Convert.ToString(func.Tables["CUSTOMERBANKDETAIL"].Rows[0, "BANK_KEY"]);

        //after all don't forget to close the connection

        //display the Data 
        Console.WriteLine("Customer: 0000001172");
        Console.WriteLine("Bank Key: {0}", Bank_Key);

The result should look like this:


It is also possible to store the result in a DataTable, by adding the line...

DataTable dt = func.Tables["CUSTOMERBANKDETAIL"].ToADOTable();

... after the Try Catch block, then we receive all data from CUSTOMERBANKDETAIL according to customer number 0000001172.

In this example, I have shown the basic use of ERPConnect to communicate with Function Modules, but there are some more very interesting features (I'm going to describe later on in this article) handling the RFC and IDoc communication and even the possibility to directly read from SAP tables.

Example 2: Reading Directly from a SAP Table using the ReadTable Class

In my opinion, the ReadTable class is one of the most useful special classes, because it provides the possibility to directly read from SAP tables. For my customer project, it was very important to extract data from a SAP table into a .NET DataSet, so this class was very helpful for me.

This example shows how to use the ReadTable class by using a "where - like" statement to get the address of all customers in table KNA1 that match an entered name criteria and display the result in a DataGridView.

The logic of this example is encapsulated in a class called SAPConnect. Just like in the example above the using ERPConnect; statement and also the using ERPConnect.Utils; for using the ReadTable class have to be added to the header.

The private properties we need are:

private  string _userName;
private  string _password;
private  string _client;
private  R3Connection _con;

Parameters for the constructor are username, password and client that are stored in local properties.

public SAPConn(string userName, string password, string client)
    _userName = userName;
    _password = password;
    _client   = client;

Because the address of the application server, the system number and the language mostly have the same value we can enter these parameters directly into the code or store it in a configuration file. In my customer project, I had a lot of methods using the same connection string, so I thought it was useful to store the procedure of opening the connection in a separate private function called openConnection:

private void openConnection()
    ERPConnect.LIC.SetLic("licence code");

    R3Connection con = new R3Connection("name of the application server",
                    "system number",
    catch (ERPException e)

    _con = connection;

And of course we need a method to close the connection:

private void closeConnection()

Now we can implement the method to read directly from a SAP table and return the result in a DataSet. Let me first explain the way this function works:

At first, we have to create a ReadTable object and fill the TableName property with the name of the SAP table we want to read from. After that, we can add the fields of interest by using the AddField method. When this is done, we can fill the WhereClause with our Like string. In this example I have set the optional RowCount property on 100, so that we only receive 100 rows in our result. After executing the query, we have the Result as DataTable.

public DataTable WhereLikeSearch(string sapTable, string nameCriteria)

    //creating a ReadTable object
    ReadTable table = new ReadTable(_con);

    //setting the table name that we want to read from
    table.TableName = sapTable;

    //adding the fields we want to display in our DataTable
    //this is the 
    table.WhereClause = string.Format("NAME1 LIKE '%{0}%'", nameCriteria);    

    //this is an optional property
    table.RowCount = 100;

    //executing the query
    catch(ERPException e)

    DataTable dt = table.Result;


    return dt;


Instead of the like clause we can use the = operator to search for results that match our nameCriteria exactly, then the table.WhereClause looks like that:

table.WhereClause = string.Format("NAME1 = '{0}'", nameCriteria);

In this statement, it is important to care about the correct syntax especially the spaces before and after the = or an ERPException will be raised.

To display the data in a DataGridView, we have to add the following code to the button1_Click eventhandler. After the button is clicked, the content of textBox1 will be our nameCriteria.

private void button1_Click(object sender, EventArgs e)
    string nameCriteria = textBox1.Text;

    SAPConn sapConn = new SAPConn("userName", "password", "client");
    DataTable dt = sapConn.WhereLikeSearch("KNA1", nameCriteria);

    dataGridView1.DataSource = dt;

After executing the program we should have the DataGridView filled with 100 Customers matching our criteria (e.g. entering t in the TextBox returns all customers with a t in their name).

ReadTable in action

Other ERPConnect Features

There are a lot of more features coming along with ERPConnect than the classes I have used in the two examples above. I haven't used them all yet, but I have also worked with the following classes for my customer project.

Not RFC-enabled Function Modules: If a Function Module is not RFC-enabled, ERPConnect provides a solution to access these Function Modules and use them like RFC-enabled Function Modules by building an internal wrapper around the Function Module executing this Function Module indirectly. In the .NET application, you just have to set the UseRFCWrapper property of the RFCFunction object on true.

ASP.NET: ERPConnect also can be integrated into an ASP.NET application. To use ERPConnect in a Web Application, you have to add a reference on ERPConnect20.dll and the libfcr32.dll which can be found in the System32 directory of a SAP client computer. After adding these references, you can use ERPConnect described above.

SAP Queries: It is also possible to access any kind of SAP queries by using the namespace ERPConnect.Queries.

To execute a query, the following steps are necessary:

  • Create an R3Connection object and open the connection (just like in the examples above)
  • Create a query object Query q = con.CreateQuery("user area","user group","query name");
  • Add the criteria q.SelectionParameters["the parameter"].Ranges.Add(Sign.Include, RangeOption.Equals, "criteria");
  • Execute the query q.Execute
  • Now we find the result in DataTable dt = q.Result;

In this namespace, you also find the very helpful class ERPConnect.Query.QueryHelper.QueryHelper providing kind of "search for Queries" functionality.

IDocs: Another interesting feature is the sending of IDocs by using the CreateIDoc method. Let me explain this using a short listing taken from the ERPConnect online documentation. This example will send a STATUS IDoc. The STATUS IDoc is designed to manipulate the status of another IDoc. The STATUS IDoc can be used to confirm the successful processing of receiving another IDoc.

static void Main(string[] args)
    R3Connection con = new R3Connection("hamlet", 11,"Theobald", 
                                        "pw", "DE", "800");
    Console.WriteLine("Which Idocnumber would you like to manipulate?");
    string IdocNo = Console.ReadLine();
    Idoc i = con.CreateIdoc("SYSTAT01", "");

    // Fill Message Type 
    i.MESTYP = "STATUS";

    // Fill Information about Idoc Receiver
    i.RCVPRN = "PT4_800"; // Partner number 
    i.RCVPRT = "LS"; // Partner type

    // Fill information about idoc sender
    i.SNDPOR = "ERPCONNECT"; // Partner port
    i.SNDPRN = "ERPCONNECT"; // Partner number
    i.SNDPRT = "LS";// Partner type 

    // Fill the right fields in the segments 
    i.Segments["E1STATS", 0].Fields["LOGDAT"].FieldValue = "20060101";
    i.Segments["E1STATS", 0].Fields["LOGTIM"].FieldValue = "152301";
    i.Segments["E1STATS", 0].Fields["STATUS"].FieldValue = "12";
    i.Segments["E1STATS", 0].Fields["DOCNUM"].FieldValue = IdocNo;


    Console.WriteLine("Idoc sent");

Receiving IDocs is a little bit different from sending IDocs. To receive IDocs, we have to implement an small IDoc server by setting the CanReceiveIdocs property on true and catch the incoming IDocs:

//create an RFCServer object

RFCServer s = new RFCServer();
s.Logging = true;

//setting the properties (you have to fill the empty
//strings with your specific values)

s.GatewayHost = "";
s.GatewayService = "";
s.ProgramID = "";

//this property is important
s.CanReceiveIdocs = true;

//here we catch the incoming IDocs to handle them in function s_IncomingIdoc
s.IncomingIdoc += new ERPConnect.RFCServer.OnIncomingIdocs(s_IncomingIdoc);

//start the server
//let the server work
//after all stop the server


In this short listing, I show how to receive the IDOCTYPE of the received IDoc:

private static void s_IncomingIdoc(RFCServer Sender, Idoc idoc)

Of course, you can read all the content of the received IDoc, but for details I refer to the documentation. For implementation of the server in a productive area, you also have to implement a kind of threading to manage plenty of incoming IDocs.

The IDoc classes also provides the possibility to handle IDocs as XML files. For example you can create an XML scheme defining how the IDoc has to look like or an XML file storing the data of an IDoc.

Special Classes: For recurring tasks, ERPConnect provides the special classes encapsulated in the ERPConnect.Utils namespace, like the ReadTable class demonstrated in example 2.

Another special class is the ABAPCode class that allows you to generate ABAP code on the fly in your .NET application. Instead of writing a Function Module in the SAP system, you can write the ABAP code in your .NET application without declaring a new Function Module in your SAP system.

Just as written above, there are some more features that come along with ERPConnect like an XML based SOAP/HTTP protocol or the RFC-Server, so that nearly every interface programming task can be solved.


In my opinion, one of the major tasks for consultants and software engineers in our days is to develop interfaces for the different IT-Systems like ERP, PDM or CRM systems. One of the most used ERP systems in bigger companies is SAP. In consideration of this fact, it is very important to know an easy way of programming an interface for SAP. I think ERPConnect is a very big help for this task because it supports the possibilities of the .NET Framework like ASP.NET or the Compact Framework, also ERPConnect supports any IDE like SharpDevelop. The documentation coming along with the software was very understandable (I have only read the German one, but I think the English one is the same) with a lot of examples explaining the usage of the classes. You can also download the documentation from here.


  • 23rd May, 2007: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Frank Mayer-Potschak
Software Developer FMP software & process engineering GmhH
Germany Germany
Im working as freelance consultant and software engineer in southern germany. If you have any questions about this article please contact me.

You may also be interested in...


Comments and Discussions

QuestionDisplay value of a structure Pin
Member 1232798821-Jul-16 19:01
memberMember 1232798821-Jul-16 19:01 
QuestionNo variant or Invalid variant Pin
FaizanMubasher29-Sep-15 20:54
professionalFaizanMubasher29-Sep-15 20:54 
QuestionUsing the SAP.NET Connector 3.0 Pin
mahendra.Net26-Nov-14 18:48
membermahendra.Net26-Nov-14 18:48 
QuestionLicense code Pin
brandonfcx16-Sep-14 17:25
memberbrandonfcx16-Sep-14 17:25 
QuestionGreat contribution Pin
Kike Kikee10-Sep-13 4:35
memberKike Kikee10-Sep-13 4:35 
QuestionSAP Dotnet Integration Pin
rohitnegi0921-Nov-12 21:25
memberrohitnegi0921-Nov-12 21:25 
QuestionWell,... Could you show me how to bind the data which we recieve from BAPI and bind that data to Crystal Report Pin
venu gopal reddy m7-Jun-12 0:09
membervenu gopal reddy m7-Jun-12 0:09 
QuestionIssue With ERPConnect While Retriving Decimal Values Pin
snehalpatel8421-Mar-12 20:44
membersnehalpatel8421-Mar-12 20:44 
GeneralNot able to call BAPI_FIXEDASSET_GETLIST with structure GENERALDATA Pin
Member 30282654-Feb-11 23:34
memberMember 30282654-Feb-11 23:34 
GeneralGood article but old technologies Pin
choopie2-Jan-10 6:04
memberchoopie2-Jan-10 6:04 
JokeRe: Good article but old technologies Pin
Brian Shifrin27-Jan-10 12:52
memberBrian Shifrin27-Jan-10 12:52 
GeneralRe: Good article but old technologies Pin
choopie31-Jan-10 9:51
memberchoopie31-Jan-10 9:51 
GeneralRegarding Pin
madhura014-Oct-09 18:04
membermadhura014-Oct-09 18:04 
GeneralRe: Regarding Pin
Frank Mayer-Potschak14-Oct-09 22:45
memberFrank Mayer-Potschak14-Oct-09 22:45 
GeneralRgrading Article Pin
madhura014-Oct-09 18:00
membermadhura014-Oct-09 18:00 
GeneralCodepage of server Pin
intecai25-Feb-09 1:24
memberintecai25-Feb-09 1:24 
QuestionEine Frage zum Senden von IDocs per Pin
swapp15-Dec-08 21:32
memberswapp15-Dec-08 21:32 
GeneralGreat article Pin
bobcapilontra30-Sep-08 14:46
memberbobcapilontra30-Sep-08 14:46 
GeneralGreat Article Pin
Sunil_Pawar6-Jul-07 1:28
memberSunil_Pawar6-Jul-07 1:28 
GeneralRe: Great Article Pin
Frank Mayer-Potschak7-Jul-07 7:55
memberFrank Mayer-Potschak7-Jul-07 7:55 
Generalhelal olsun Pin
el_aristo23-May-07 23:18
memberel_aristo23-May-07 23:18 
AnswerRe: helal olsun Pin
Frank Mayer-Potschak24-May-07 0:47
memberFrank Mayer-Potschak24-May-07 0:47 
GeneralSehr guter Artikel Pin
EDVBS23-May-07 20:49
memberEDVBS23-May-07 20:49 
AnswerRe: Sehr guter Artikel Pin
Frank Mayer-Potschak23-May-07 22:07
memberFrank Mayer-Potschak23-May-07 22:07 
Generalgood article Pin
guveno23-May-07 20:32
memberguveno23-May-07 20:32 
good article. I use only libfcr32.dll and class that i wrote; i add new function when i need.
ConvertDataTabletOSaptable and ConvertSaptableToDataTable functions tables beetwen sap table and ado .

<br />
Imports Microsoft.VisualBasic<br />
Imports System.Data<br />
Imports System.Data.OleDb<br />
Namespace Saputilty<br />
    'RFC TİPLERİ<br />
    'ABAP/4 data types      ANSI C         Visual Basic    Comment          <br />
    'Const gTYPC     = 0       'RFC_CHAR       STRING $        characters       <br />
    'Const gTYPDATE  = 1       'RFC_DATE       STRING $        date (YYYYMMDD)  <br />
    'Const gTYPP     = 2       'RFC_BCD        STRING $        packed numbers   <br />
    'Const gTYPTIME  = 3       'RFC_TIME       STRING $        time (HHMMSS)    <br />
    'Const gTYPX     = 4       'RFC_BYTE       STRING $        raw data         <br />
    'Const gTYPTABH  = 5       'not used here                                   <br />
    'Const gTYPNUM   = 6       'RFC_NUM        STRING $        digits           <br />
    'Const gTYPFLOAT = 7       'RFC_FLOAT      FLOAT #         floating point   <br />
    'Const gTYPINT   = 8       'RFC_INT        LONG &          4 byte integer   <br />
    'Const gTYPINT2  = 9       'RFC_INT2       INTEGER %       2 byte integer   <br />
    'Const gTYPINT1  = 10      'RFC_INT1       INTEGER %       1 byte integer   <br />
    'Const gTYPB     = 11      'not used here                                   <br />
    'Const gTYP1     = 12      'not used here                                   <br />
    'Const gTYP2     = 13      'not used here                                   <br />
    'RFC_MODE Rfc open modus                                                           <br />
    'Const RFC_MODE_R3ONLY = 0 'only for R/3 systems, any kind of user                 <br />
    'Const RFC_MODE_CPIC   = 1 'can be used for R/2, but CPIC-Users only  <br />
    'T2.Columns(3).Decimals  0           sayı ise decimal kısım<br />
    'T2.Columns(3).Name      MSNUMBER    adı<br />
    'T2.Columns(3).Type      0           tipi<br />
    'T2.Columns(3).TypeName  String RFC  tip adi<br />
    'T2.Columns(3).intlength 10          uzunluk             <br />
<br />
    'RFC_RC Rfc return codes                                                           <br />
    'Const RFC_OK            = 0 'OK                                                   <br />
    'Const RFC_FAILURE       = 1 'error occured                                        <br />
    'Const RFC_EXCEPTION     = 2 'exception raised                                     <br />
    'Const RFC_SYS_EXCEPTION = 3 'system exception raised, connection closed           <br />
    'Const RFC_CALL          = 4 'call received                                        <br />
    'Const RFC_INTERNAL_COM  = 5 'internal communication, repeat                       <br />
    'Const RFC_CLOSED        = 6 'connection closed by the other side                  <br />
    'Const RFC_RETRY         = 7 'no data yet (RfcListen only)                         <br />
    'Const RFC_NO_TID        = 8 'no transaction ID available                          <br />
    'Const RFC_EXECUTED      = 9 'function already executed                            <br />
    'Type BAPIRETURN                 <br />
    'Type As STRING * 1            <br />
    'Code As STRING * 5            <br />
    'Message As STRING * 220       <br />
    'LogNo As STRING * 20          <br />
    'LogMsgNo As STRING * 6        <br />
    'MessageV1 As STRING * 50      <br />
    'MessageV2 As STRING * 50      <br />
    'MessageV3 As STRING * 50      <br />
    'MessageV4 As STRING * 50      <br />
    'End Type                        <br />
    Public Class Saptools<br />
        Public Structure SapConnectionOptions<br />
            Public logfilename As String<br />
            Public loglevel As Integer<br />
            Public ApplicationServer As String<br />
            Public user As String<br />
            Public Password As String<br />
            Public Destination As String<br />
            Public Client As String<br />
            Public Language As String<br />
            Public System As String<br />
            Public systemid As String<br />
            Public SystemNumber As Integer<br />
            Public GatewayHOST As String<br />
            Public Gatewayservice As String<br />
            Public tracelevel As Integer<br />
        End Structure<br />
        Public Structure Personel_bil<br />
            Public BUKRS As String   'Sınırlama nasıl 4 katrakter <VBFixedString(4)><br />
            Public ADSOYAD As String<br />
            Public AUFNR As String<br />
            Public GSBER As String<br />
            Public KOSTL As String<br />
            Public CEPTEL As String<br />
            Public PLAKA As String<br />
            Public KUNNR As String<br />
            Public SP_GL_IND As String<br />
            Public DB_CR_IND As String<br />
            Public LOC_CURRCY As String<br />
            Public LC_BAL As String<br />
            Public HATA As String<br />
        End Structure<br />
        Public Structure musteri_bil<br />
            Public UNVAN1 As String<br />
            Public UNVAN2 As String<br />
            Public ADRES1 As String<br />
            Public ADRES2 As String<br />
            Public SEMT As String<br />
            Public POSTCODE As String<br />
            Public KENT As String<br />
            Public TEL_NUMBER As String<br />
            Public FAX_NUMBER As String<br />
            Public ISTASYONISMI As String<br />
        End Structure<br />
        Public Structure MasrafBaslik<br />
            Public MANDT As String<br />
            Public BUKRS As String<br />
            Public MSNUMBER As String<br />
            Public MSTARIHI As String<br />
            Public PERSNOB As String<br />
            Public VALUT As String<br />
            Public WAERS As String<br />
            Public MSHARCAMATUR As String<br />
            Public MSAVANSTOP As String<br />
            Public MSAVANSBKY As String<br />
            Public MSAVANSKAL As String<br />
        End Structure<br />
        Public Structure MasrafBelgeSatir<br />
            Public MANDT As String          'Üst birim<br />
            Public BUKRS As String          'Şirket kodu<br />
            Public MSNUMBER As String       'Masraf Numarası<br />
            Public MSTARIHI As String       'Masraf Tarihi<br />
            Public WAERS As String          'Para Birimi<br />
            Public BUZEI As String          'Masraf Satir No<br />
            Public MSCESIDI As String       'Masraf Çeşidi<br />
            Public MSFATTARIHI As String    'Fatura/Fiş Tarihi<br />
            Public MSFATURANO As String     'Fatura No<br />
            Public WRBTR As String          'Belge para birimi cinsinden tutar<br />
            Public MWSKZ As String          'Kdv Göstergesi<br />
            Public FWBAS As String          'vergi matrahı<br />
            Public WMWST As String          'vergi tutarı<br />
            Public BELNR As String          'Muhasebe belge no<br />
            Public BUDAT As String          'Belgedeki kayıt tarihi<br />
            Public SGTXT As String          'Masraf Kalemi açıklama<br />
            Public KOSTL As String          'Masraf Yeri<br />
            Public AUFNR As String          'İç Sipariş<br />
            Public PERSNO As String         'Personel No<br />
            Public KFZKZ As String          'Taşıt Plakasi<br />
            Public ANLN1 As String          'Duran varlık ana numarası<br />
            Public ANLN2 As String          'Duran varlık alt numarası<br />
            Public MENGE As String          'Miktar<br />
            Public MEINS As String          'Temel ölçü birimi<br />
        End Structure<br />
        Private Personel As Personel_bil<br />
        Private SapFunctions As Object<br />
        Dim FNS As Object<br />
        Dim CONN, RS, MYFUNC, T1, T2, T3, t4_reserved As Object<br />
        Private T_ConnectionState As Boolean<br />
        Private T_ShowConnectDialog As Boolean<br />
        Private T_FunctionCalledState As Boolean = False<br />
        Public Sub New()<br />
            T_ShowConnectDialog = True<br />
            T_ConnectionState = False<br />
        End Sub<br />
        Public Sub New(ByVal ShowConnectDialog As Boolean)<br />
            T_ShowConnectDialog = ShowConnectDialog<br />
            T_ConnectionState = False<br />
        End Sub<br />
        Sub SAP_CONNECT(ByVal Connectoption As SapConnectionOptions, ByVal VarsayilanBaglanti As Boolean)<br />
            FNS = CreateObject("SAP.Functions")<br />
            CONN = FNS.Connection<br />
            RS = Nothing<br />
            MYFUNC = Nothing<br />
            T1 = Nothing<br />
            T2 = Nothing<br />
            T3 = Nothing<br />
            If Not VarsayilanBaglanti Then<br />
                If Connectoption.logfilename <> "" Then FNS.logfilename = Connectoption.logfilename<br />
                If Connectoption.loglevel > -1 Then FNS.loglevel = Connectoption.loglevel<br />
                If Connectoption.ApplicationServer <> "" Then CONN.ApplicationServer = Connectoption.ApplicationServer<br />
                If Connectoption.user <> "" Then CONN.user = Connectoption.user<br />
                If Connectoption.Password <> "" Then CONN.Password = Connectoption.Password<br />
                If Connectoption.Destination <> "" Then CONN.Destination = Connectoption.Destination<br />
                If Connectoption.Client <> "" Then CONN.Client = Connectoption.Client<br />
                If Connectoption.Language <> "" Then CONN.Language = Connectoption.Language<br />
                If Connectoption.System <> "" Then CONN.system = Connectoption.System<br />
                If Connectoption.systemid <> "" Then CONN.systemid = Connectoption.systemid<br />
                If Connectoption.SystemNumber <> Nothing Then CONN.SystemNumber = Connectoption.SystemNumber<br />
                If Connectoption.GatewayHOST <> "" Then CONN.GatewayHOST = Connectoption.GatewayHOST<br />
                If Connectoption.Gatewayservice <> "" Then CONN.Gatewayservice = Connectoption.Gatewayservice<br />
                If Connectoption.tracelevel > -1 Then CONN.tracelevel = Connectoption.tracelevel<br />
            Else<br />
                FNS.logfilename = "C:\RFSsap.txt"<br />
                FNS.loglevel = 7<br />
                CONN.ApplicationServer = 'xxx'<br />
                CONN.user = "xxxxxx"<br />
                CONN.Password = "xxxxxxx"<br />
                CONN.Client = "xxx"<br />
                CONN.Language = "T"<br />
                CONN.tracelevel = 6<br />
            End If<br />
            T_ConnectionState = CONN.Logon(0, T_ShowConnectDialog)<br />
        End Sub<br />
        Sub SAP_DISCONNECT()<br />
            If T_ConnectionState = True Then<br />
                T_ConnectionState = False<br />
                CONN.logoff()<br />
                FNS.Connection.logoff()<br />
                FNS = Nothing<br />
                CONN = Nothing<br />
                MYFUNC = Nothing<br />
                T1 = Nothing<br />
                T2 = Nothing<br />
                T3 = Nothing<br />
            End If<br />
        End Sub<br />
<br />
        Public ReadOnly Property ConnectionState() As Boolean<br />
            Get<br />
                ' Return T_ConnectionState<br />
                ' T_ConnectionState = CONN.isconnected<br />
                Try<br />
                    If CONN Is Nothing Then<br />
                        Return False<br />
                    Else<br />
                        'Return CONN.isconnected<br />
                        Return T_ConnectionState<br />
                    End If<br />
                Catch ex As Exception<br />
                    Return False<br />
                End Try<br />
<br />
            End Get<br />
        End Property<br />
        Public ReadOnly Property FunctionCalledState() As Boolean<br />
            Get<br />
                Return T_FunctionCalledState<br />
            End Get<br />
        End Property<br />
        Public Property ShowConnectdialog() As Boolean<br />
            Get<br />
                Return T_ShowConnectDialog<br />
            End Get<br />
            Set(ByVal Value As Boolean)<br />
                T_ShowConnectDialog = Value<br />
            End Set<br />
        End Property<br />
        <br />
       Sub ConvertDataTabletOSaptable(ByVal DtTable As DataTable, ByRef saptable As Object)<br />
            Dim readrow As DataRow<br />
            Dim sira As Integer = 1<br />
            For j As Integer = 0 To DtTable.Rows.Count - 1<br />
<br />
                saptable.Rows.Add()<br />
                readrow = DtTable.Rows.Item(j)<br />
<br />
                For k As Integer = 0 To DtTable.Columns.Count - 1<br />
                    If DtTable.Columns(k).ToString <> "MsCesID" Then<br />
                        saptable.Value(sira, DtTable.Columns(k).ToString) = readrow(DtTable.Columns(k).ToString)<br />
                    End If<br />
                Next<br />
                sira += 1<br />
            Next j<br />
        End Sub<br />
<br />
        Function ConvertSaptableToDataTable(ByVal Saptable As Object) As DataTable<br />
            Dim TableName As String =<br />
            Dim dt As New DataTable(TableName)<br />
            Dim myRow As DataRow<br />
            For i As Integer = 1 To Saptable.COLUMNCOUNT<br />
                With dt.Columns.Add<br />
                    .ColumnName = Saptable.Columns(i).Name.ToString<br />
                    Select Case Saptable.Columns(i).typename<br />
                        Case "String RFC"<br />
                            .DataType = System.Type.GetType("System.String")<br />
                        Case "Date RFC"<br />
                            .DefaultValue = Now<br />
                            .DataType = System.Type.GetType("System.DateTime")<br />
                        Case "Numerical RFC"<br />
                            .DataType = System.Type.GetType("System.Int32")<br />
                        Case "BCD RFC"<br />
                            .DataType = System.Type.GetType("System.Decimal")<br />
                        Case "Time RFC"<br />
                            .DefaultValue = Now<br />
                            .DataType = System.Type.GetType("System.DateTime")<br />
                        Case "Byte RFC"<br />
                            .DataType = System.Type.GetType("System.Int16")<br />
                        Case "Short RFC"<br />
                            .DataType = System.Type.GetType("System.Int16")<br />
                        Case "Long RFC"<br />
                            .DataType = System.Type.GetType("System.Int64")<br />
                        Case "Float RFC"<br />
                            .DataType = System.Type.GetType("System.Double")<br />
                    End Select<br />
                End With<br />
                'dt.Columns.Add(Saptable.Columns(i).Name.ToString)<br />
            Next i<br />
            For i As Integer = 1 To Saptable.RowCount<br />
                myRow = dt.NewRow()<br />
                For j As Integer = 1 To Saptable.COLUMNCOUNT<br />
                    Dim gecici As String = dt.Columns(j - 1).ToString<br />
                    myRow(gecici) = Saptable.Value(i, gecici.ToString)<br />
                Next j<br />
                dt.Rows.Add(myRow)<br />
            Next i<br />
            Return dt<br />
        End Function<br />
<br />
        Sub personel_bilgi(ByVal pers_no As String, ByVal KEYDATE As String, ByVal UMSKZ As String, ByRef Personel As Personel_bil)<br />
            If T_ConnectionState Then<br />
                MYFUNC = FNS.Add("Z_RFC_PERSONEL_BILGILERI")<br />
                MYFUNC.exports("PERNR") = pers_no<br />
                MYFUNC.exports("KEYDATE") = KEYDATE<br />
                MYFUNC.exports("UMSKZ") = UMSKZ<br />
                T_FunctionCalledState = MYFUNC.Call<br />
                If T_FunctionCalledState Then<br />
                    Personel.BUKRS = MYFUNC.ImportS("BUKRS").Value<br />
                    Personel.ADSOYAD = MYFUNC.ImportS("ADSOYAD").Value<br />
                    Personel.KOSTL = MYFUNC.ImportS("KOSTL").Value<br />
                    Personel.SP_GL_IND = MYFUNC.ImportS("SP_GL_IND").Value<br />
                    Personel.GSBER = MYFUNC.ImportS("GSBER").Value<br />
                    Personel.KUNNR = MYFUNC.ImportS("KUNNR").Value<br />
                    Personel.PLAKA = MYFUNC.ImportS("PLAKA").Value<br />
                    Personel.HATA = MYFUNC.ImportS("HATA").Value<br />
                    Personel.CEPTEL = MYFUNC.ImportS("CEPTEL").Value<br />
                    Personel.AUFNR = MYFUNC.ImportS("AUFNR").Value<br />
                    Personel.LC_BAL = MYFUNC.ImportS("LC_BAL").Value<br />
                    Dim bakiye As Long<br />
                    bakiye = Convert.ToDouble(Personel.LC_BAL)<br />
                    Personel.LC_BAL = bakiye.ToString<br />
                End If<br />
            End If<br />
        End Sub<br />
        <br />
        Function musteri_bakiye(ByVal skod As String, ByVal must As String, ByVal KEYDATE As String, ByVal odk As String) As DataSet<br />
            Dim ds As New DataSet("sap1")<br />
            must = must.PadLeft(10, Char.Parse("0"))<br />
            If T_ConnectionState Then<br />
                T1 = MYFUNC.tables("KEYBALANCE")<br />
                T2 = MYFUNC.imports("RETURN")<br />
                MYFUNC.exports("COMPANYCODE") = skod<br />
                MYFUNC.exports("CUSTOMER") = must<br />
                MYFUNC.exports("KEYDATE") = KEYDATE<br />
                MYFUNC.exports("BALANCESPGLI") = odk<br />
<br />
                T_FunctionCalledState = MYFUNC.Call<br />
<br />
                If T_FunctionCalledState And Not T1 Is Nothing Then<br />
                    ds.Tables.Add(ConvertSaptableToDataTable(T1))<br />
                End If<br />
            End If<br />
            Return ds<br />
        End Function<br />
      <br />
        Function Bapi_get_orders(ByVal CustomerNumber_ As String, _<br />
                                 ByVal SalesOrganization_ As String, _<br />
                                 ByVal Material_ As String, _<br />
                                 ByVal DocumentDate_ As String, _<br />
                                 ByVal DocumentDateTo_ As String, _<br />
                                 ByVal PurchaseOrder_ As String, _<br />
                                 ByVal TransactionGroup_ As Char, _<br />
                                 ByVal PurchaseOrderNumber_ As String) As DataSet<br />
            Dim ds As New DataSet("sap1")<br />
            If T_ConnectionState Then<br />
                MYFUNC = FNS.Add("BAPI_SALESORDER_GETLIST")<br />
                T1 = MYFUNC.tables("SALES_ORDERS")<br />
                T2 = MYFUNC.imports("RETURN")<br />
                CustomerNumber_ = CustomerNumber_.PadLeft(MYFUNC.exports("CUSTOMER_NUMBER").length, Char.Parse("0"))<br />
                MYFUNC.exports("CUSTOMER_NUMBER") = CustomerNumber_<br />
                MYFUNC.exports("SALES_ORGANIZATION") = SalesOrganization_<br />
                MYFUNC.exports("MATERIAL") = Material_<br />
                MYFUNC.exports("DOCUMENT_DATE") = DocumentDate_<br />
                MYFUNC.exports("DOCUMENT_DATE_TO") = DocumentDateTo_<br />
                MYFUNC.exports("PURCHASE_ORDER") = PurchaseOrder_<br />
                MYFUNC.exports("TRANSACTION_GROUP") = TransactionGroup_<br />
                MYFUNC.exports("PURCHASE_ORDER_NUMBER") = PurchaseOrderNumber_<br />
                T_FunctionCalledState = MYFUNC.Call<br />
                If T_FunctionCalledState And Not T1 Is Nothing Then<br />
                    ds.Tables.Add(ConvertSaptableToDataTable(T1))<br />
                End If<br />
            End If<br />
<br />
            Return ds<br />
        End Function<br />
 <br />
<br />
       <br />
<br />
        Function masraf_belge_kaydet(ByRef BelgeBaslik As MasrafBaslik, ByRef BelgeSatir() As MasrafBelgeSatir) As Boolean<br />
            If T_ConnectionState Then<br />
                MYFUNC = FNS.Add("Z_RFC_MASRAF_TABLOLARI")<br />
                T1 = MYFUNC.tables("ZRFCFI04")<br />
                T2 = MYFUNC.tables("ZRFCFI05")<br />
                '***********************belge başlık*************************************<br />
                T1.Rows.add()<br />
                T1.Value(1, "MANDT") = BelgeBaslik.MANDT<br />
                T1.Value(1, "BUKRS") = BelgeBaslik.BUKRS<br />
                T1.Value(1, "MSNUMBER") = BelgeBaslik.MSNUMBER<br />
                T1.Value(1, "MSTARIHI") = BelgeBaslik.MSTARIHI<br />
                T1.Value(1, "PERSNOB") = BelgeBaslik.PERSNOB<br />
                T1.Value(1, "VALUT") = BelgeBaslik.VALUT<br />
                T1.Value(1, "WAERS") = BelgeBaslik.WAERS<br />
                T1.Value(1, "MSHARCAMATUR") = BelgeBaslik.MSHARCAMATUR<br />
                T1.Value(1, "MSAVANSTOP") = BelgeBaslik.MSAVANSTOP<br />
                T1.Value(1, "MSAVANSBKY") = BelgeBaslik.MSAVANSBKY<br />
                T1.Value(1, "MSAVANSKAL") = BelgeBaslik.MSAVANSKAL<br />
                '***********************Satir********************************************<br />
                For k As Integer = 0 To BelgeSatir.Length - 1<br />
                    T2.Rows.Add()<br />
                    T2.Value(k + 1, "MANDT") = BelgeSatir(k).MANDT<br />
                    T2.Value(k + 1, "BUKRS") = BelgeSatir(k).BUKRS<br />
                    T2.Value(k + 1, "MSNUMBER") = BelgeSatir(k).MSNUMBER<br />
                    T2.Value(k + 1, "MSTARIHI") = BelgeSatir(k).MSTARIHI<br />
                    T2.Value(k + 1, "WAERS") = BelgeSatir(k).WAERS<br />
                    T2.Value(k + 1, "BUZEI") = BelgeSatir(k).BUZEI<br />
                    T2.Value(k + 1, "MSCESIDI") = BelgeSatir(k).MSCESIDI<br />
                    T2.Value(k + 1, "MSFATTARIHI") = BelgeSatir(k).MSFATTARIHI<br />
                    T2.Value(k + 1, "MSFATURANO") = BelgeSatir(k).MSFATURANO<br />
                    T2.Value(k + 1, "WRBTR") = BelgeSatir(k).WRBTR<br />
                    T2.Value(k + 1, "MWSKZ") = BelgeSatir(k).MWSKZ<br />
                    T2.Value(k + 1, "FWBAS") = BelgeSatir(k).FWBAS<br />
                    T2.Value(k + 1, "WMWST") = BelgeSatir(k).WMWST<br />
                    T2.Value(k + 1, "BELNR") = BelgeSatir(k).BELNR<br />
                    T2.Value(k + 1, "BUDAT") = BelgeSatir(k).BUDAT<br />
                    T2.Value(k + 1, "SGTXT") = BelgeSatir(k).SGTXT<br />
                    T2.Value(k + 1, "KOSTL") = BelgeSatir(k).KOSTL<br />
                    T2.Value(k + 1, "AUFNR") = BelgeSatir(k).AUFNR<br />
                    T2.Value(k + 1, "PERSNO") = BelgeSatir(k).PERSNO<br />
                    T2.Value(k + 1, "KFZKZ") = BelgeSatir(k).KFZKZ<br />
                    T2.Value(k + 1, "ANLN1") = BelgeSatir(k).ANLN1<br />
                    T2.Value(k + 1, "ANLN2") = BelgeSatir(k).ANLN2<br />
                    T2.Value(k + 1, "MENGE") = BelgeSatir(k).MENGE<br />
                    T2.Value(k + 1, "MEINS") = BelgeSatir(k).MEINS<br />
                Next<br />
            End If<br />
            T_FunctionCalledState = MYFUNC.Call<br />
            Dim Hata As String = MYFUNC.ImportS("HATA").ToString  'error döner<br />
            If Hata <> "" Then<br />
                Return True<br />
            Else<br />
                Return False<br />
            End If<br />
        End Function<br />
<br />
         <br />
<br />
        Function SD_RFC_CUSTOMER_GET(ByVal CUSTNAME As String) As DataTable<br />
            Dim dt As New DataTable<br />
            If T_ConnectionState Then<br />
                MYFUNC = FNS.Add("SD_RFC_CUSTOMER_GET")<br />
                MYFUNC.exports("NAME1") = CUSTNAME<br />
                T1 = MYFUNC.tables("CUSTOMER_T")<br />
                T_FunctionCalledState = MYFUNC.Call<br />
                If T_FunctionCalledState And Not T1 Is Nothing Then<br />
                    dt = ConvertSaptableToDataTable(T1)<br />
                    Dim dcolCustCodeName= New DataColumn<br />
                    dcolMusteriVekodu.ColumnName = "CustomercodeName"<br />
                    dcolMusteriVekodu.DataType = System.Type.GetType("System.String")<br />
                    dcolMusteriVekodu.Expression = "KUNNR + ' ' + NAME1"<br />
                    dt.Columns.Add(dcolCustCodeName)<br />
                End If<br />
            End If<br />
            Return dt<br />
        End Function<br />
<br />
    End Class<br />
<br />
End Namespace<br />

güven özdemir

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 23 May 2007
Article Copyright 2007 by Frank Mayer-Potschak
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid