580 likes | 875 Views
SAP & .NET application (Visual Studio 2005) Integration. Microsoft Corporation SAP-Microsoft Competence Center (Tokyo). Landscape. SAP. Console application. Table, View. Web application. BAPI RFC. SAP R/3 SAP ERP. XML Web Services. BizTalk Adapter Pack (SAP) setup procedure.
E N D
SAP & .NET application(Visual Studio 2005) Integration Microsoft CorporationSAP-Microsoft Competence Center (Tokyo)
Landscape SAP Consoleapplication Table,View Web application BAPIRFC SAP R/3 SAP ERP XML WebServices
BizTalk Adapter Pack (SAP) setup procedure • Console application development • Table select, .NET Data Provider for SAP • Console application development • RFC/BAPI execution, WCF LOB Adapter • ASP .NET Web application development • Table select, .NET Data Provider for SAP • ASP .NET Web application development • RFC/BAPI execution, WCF LOB Adapter • ASP .NET Web Service development • Table select, .NET Data Provider for SAP
Landscape SAP Consoleapplication Table,View Web application BAPIRFC SAP R/3 SAP ERP XML WebServices
1. Console application development • Visual Studio 2005 – New project – Visual C# - Console application • Solution Explorer – Reference – Add reference – add “Microsoft.Data.SapClient”, “Microsoft.Adapters.SAP”, “Microsoft.ServiceModel.Channels” • Customize the SAP connection (from “connectionStrings.Add("CLIENT=800;LANG=EN;USER=SAP*;PASSWD=06071992;ASHOST=MSSAP01;SYSNR=00");”) for your SAP system • Customize the SAP command (from “cmd.CommandText = "select * from ENT1027 where SPRAS = 'JA'";”) for your SAP system • Paste the code and build it • (* Option for trouble shooting) • Place the XXXXXX.exe.config file in the same folder as the executable, XXXXX to be named the same as the console application • In case the app is “ABC.exe”, name the config file name as “ABC.exe.config” • Execute the console app from command prompt then XMLTrace.xml file is generated • Each time the console app is executed delete the XMLTrace.xml
1. Console application development • using System; • using System.Collections.Generic; • using System.Text; • using Microsoft.Data.SAPClient; • using Microsoft.Adapters.SAP; • using Microsoft.ServiceModel.Channels; • namespace ConsoleApplication2 • { • class Program • { • public class ExecTest • { • public static void Main() • { • try • { • System.Console.Write("Client:"); • string strClient = Console.ReadLine(); • System.Console.Write("Language:"); • string strLanguage = Console.ReadLine(); • System.Console.Write("User:"); • string strUser = Console.ReadLine(); • System.Console.Write("Password:"); • string strPassword = Console.ReadLine(); • System.Console.Write("SAPServer:"); • string strSAPServer = Console.ReadLine(); • System.Console.Write("SystemNo:"); • string strSystemNo = Console.ReadLine(); • System.Console.Write("CommandText:"); • string strCommandText = Console.ReadLine(); • List<string> connectionStrings = new List<string>(); • // connectionStrings.Add("CLIENT=800;LANG=EN;USER=SAP*;PASSWD=06071992;ASHOST=MSSAP01;SYSNR=00"); • connectionStrings.Add("CLIENT=" + strClient + ";LANG=" + strLanguage +";USER=" + strUser + • ";PASSWD=" + strPassword + ";ASHOST=" + strSAPServer + ";SYSNR=" + strSystemNo); • foreach (string connStr in connectionStrings) • { • using (SAPConnection conn = new SAPConnection(connStr)) • { • conn.Open(); • using (SAPCommand cmd = conn.CreateCommand()) • { • // cmd.CommandText = "select * from ENT1027 where SPRAS = 'JA'"; */ • // cmd.CommandText = "EXEC BAPI_SALESORDER_GETSTATUS @SALESDOCUMENT='5404'"; */ • // cmd.CommandText = "EXEC BAPI_VENDOR_GETDETAIL @VENDORNO='1000',@COMPANYCODE=''"; • cmd.CommandText = strCommandText; • using (SAPDataReader dr = cmd.ExecuteReader()) • { • do • { • Console.WriteLine("TABLE START"); • while (dr.Read()) • { • StringBuilder sb = new StringBuilder(); • for (int i = 0; i < dr.FieldCount; i++) • { • sb.Append(dr[i].ToString() + "|"); • } • Console.WriteLine("ROW: " + sb.ToString()); • } • Console.WriteLine("TABLE END"); • } while (dr.NextResult()); • } • } • } • } • } • catch (Exception ex) • { • Console.WriteLine("Exception: " + ex.Message + "\r\n" + ex.StackTrace + "\r\n"); • Exception innerException = ex.InnerException; • while (innerException != null) • { • Console.WriteLine("InnerException: " + innerException.Message + "\r\n" + innerException.StackTrace + "\r\n"); • innerException = innerException.InnerException; • } • } • } • } • } • }
(*Option) 1. Xxxxx.exe.config for the console app • <?xml version="1.0" encoding="utf-8" ?> • <configuration> • <system.diagnostics> • <sharedListeners> • <add name="xmlFile" type="System.Diagnostics.XmlWriterTraceListener" initializeData="XmlTrace.xml" /> • </sharedListeners> • <sources> • <source name="Microsoft.ServiceModel.Channels" switchValue="Verbose"> • <listeners> • <add name="xmlFile" /> • </listeners> • </source> • <source name="Microsoft.Adapters.SAP" switchValue="Verbose"> • <listeners> • <add name="xmlFile" /> • </listeners> • </source> • <source name="Microsoft.Data.SAPClient" switchValue="Verbose"> • <listeners> • <add name="xmlFile" /> • </listeners> • </source> • </sources> • <trace autoflush="true" /> • </system.diagnostics> • </configuration>
Visual Studio 1-1. Creating a new console application project
Visual Studio 1-2. Adding references
Visual Studio 1-3. Coding Paste the attached code.
Visual Studio 1-4. Building/deploying the code
Visual Studio 1-5. Executing the console application
BizTalk Adapter Pack (SAP) setup procedure • Console application development • Table select, .NET Data Provider for SAP • Console application development • RFC/BAPI execution, WCF LOB Adapter • ASP .NET Web application development • Table select, .NET Data Provider for SAP • ASP .NET Web application development • RFC/BAPI execution, WCF LOB Adapter • ASP .NET Web Service development • Table select, .NET Data Provider for SAP
Landscape SAP Consoleapplication Table,View Web application BAPIRFC SAP R/3 SAP ERP XML WebServices
2. Console application development • using System; • using System.Collections.Generic; • using System.Text; • using System.ServiceModel; • using Microsoft.ServiceModel.Channels; • using Microsoft.Adapters.SAP; • namespace SapRfcClientSM • { • class Program • { • static void Main(string[] args) • { • try • { • // Create client from configuration • using (RfcClient rfcClient = new RfcClient("SAPBinding_Rfc")) • { • rfcClient.ClientCredentials.UserName.UserName = "SAP*"; • rfcClient.ClientCredentials.UserName.Password = "06071992“; • // Open client • rfcClient.Open(); • microsoft.lobservices.sap._2007._03.Types.Rfc.BRFCKNA1[] customers = new microsoft.lobservices.sap._2007._03.Types.Rfc.BRFCKNA1[0]; • // Invoke SD_RFC_CUSTOMER_GET • rfcClient.RFC_CUSTOMER_GET(string.Empty, "AB*", ref customers); • // Write the results to the console • foreach ( • microsoft.lobservices.sap._2007._03.Types.Rfc.BRFCKNA1 customer in customers) • { • Console.WriteLine("Customer Name = " + customer.NAME1); • Console.WriteLine(" Id = " + customer.KUNNR); • Console.WriteLine(); • } • } • } • catch (Exception ex) • { • Console.WriteLine(ex.Message); • if (ex.InnerException != null) • Console.WriteLine("Inner exception is :" + ex.InnerException); • } • } • } • }
Visual Studio 2-1. Creating a new console application project
Visual Studio 2-2. Adding references
Visual Studio 2-3. Adding Adapter Service Reference
Visual Studio 2-3. Adding Adapter Service Reference
Visual Studio 2-4. Coding Paste the attached code.
Visual Studio 2-5. Building/deploying the code
Visual Studio 2-6. Executing the console application
BizTalk Adapter Pack (SAP) setup procedure • Console application development • Table select, .NET Data Provider for SAP • Console application development • RFC/BAPI execution, WCF LOB Adapter • ASP .NET Web application development • Table select, .NET Data Provider for SAP • ASP .NET Web application development • RFC/BAPI execution, WCF LOB Adapter • ASP .NET Web Service development • Table select, .NET Data Provider for SAP
Landscape SAP Consoleapplication Table,View Web application BAPIRFC SAP R/3 SAP ERP XML WebServices
Visual Studio 3-1. Creating a new ASP .NET Web application project
Visual Studio 3-2. Designing the user interface
Visual Studio 3-3. Adding references
3. ASP .NET Web application development (1) • using Microsoft.Data.SAPClient; • using Microsoft.Adapters.SAP; • using Microsoft.ServiceModel.Channels; • using System.Collections.Generic;
Visual Studio 3-5. Coding Paste the attached code.
3. ASP .NET Web application development (2) • protected void Button1_Click(object sender, EventArgs e) • { • List<string> connectionStrings = new List<string>(); • connectionStrings.Add("CLIENT=800;LANG=EN;USER=SAP*;PASSWD=06071992;ASHOST=MSSAP01;SYSNR=00"); • foreach (string connStr in connectionStrings) • { • using (SAPConnection conn = new SAPConnection(connStr)) • { • String str; • str = TextBox1.Text; • DataTable dt = new DataTable(); • dt.Columns.Add(new DataColumn("Client", typeof(string))); • dt.Columns.Add(new DataColumn("Language", typeof(string))); • dt.Columns.Add(new DataColumn("Country", typeof(string))); • dt.Columns.Add(new DataColumn("No", typeof(string))); • dt.Columns.Add(new DataColumn("RegionName", typeof(string))); • conn.Open(); • using (SAPCommand cmd = conn.CreateCommand()) • { • cmd.CommandText = "select MANDT, SPRAS, LAND1, BLAND, BEZEI from T005U where SPRAS = 'EN' and LAND1 ='" + str +"'"; • using (SAPDataReader reader = cmd.ExecuteReader()) • { • do • { • while (reader.Read()) • { • dt.Rows.Add(reader[0], reader[1], reader[2], reader[3], reader[4]); • } • } while (reader.NextResult()); • GridView1.DataSource = dt; • GridView1.DataBind(); • } • } • } • } • }
Visual Studio 3-5. Coding Paste the attached code.
Visual Studio 3-5. Coding
Visual Studio 3-6. Debugging the application
BizTalk Adapter Pack (SAP) setup procedure • Console application development • Table select, .NET Data Provider for SAP • Console application development • RFC/BAPI execution, WCF LOB Adapter • ASP .NET Web application development • Table select, .NET Data Provider for SAP • ASP .NET Web application development • RFC/BAPI execution, WCF LOB Adapter • ASP .NET Web Service development • Table select, .NET Data Provider for SAP
Landscape SAP Consoleapplication Table,View Web application BAPIRFC SAP R/3 SAP ERP XML WebServices
Visual Studio 4-1. Creating a new ASP .NET Web application project
Visual Studio 4-2. Designing the user interface
Visual Studio 4-3. Adding references
Visual Studio 4-4. Adding Adapter Service Reference
Visual Studio 4-4. Adding Adapter Service Reference
4. ASP .NET Web application development (1) • using System.ServiceModel; • using Microsoft.ServiceModel.Channels; • using Microsoft.Adapters.SAP;
Visual Studio 4-5. Coding Paste the attached code.
4. ASP .NET Web application development (2) • protected void Button1_Click(object sender, EventArgs e) • { • String str; • DataTable dt = new DataTable(); • DataRow dr; • dr = null; • try • { • // Create client from configuration • using (RfcClient rfcClient = new RfcClient("SAPBinding_Rfc")) • { • rfcClient.ClientCredentials.UserName.UserName = "SAP*"; • rfcClient.ClientCredentials.UserName.Password = "06071992"; • // Open client • rfcClient.Open(); • microsoft.lobservices.sap._2007._03.Types.Rfc.BRFCKNA1[] customers = • new microsoft.lobservices.sap._2007._03.Types.Rfc.BRFCKNA1[0]; • // Invoke SD_RFC_CUSTOMER_GET • str = TextBox1.Text; • rfcClient.RFC_CUSTOMER_GET(string.Empty, str, ref customers); • dt.Columns.Add(new DataColumn("Name1", typeof(string))); • dt.Columns.Add(new DataColumn("CustomerNo", typeof(string))); • dt.Columns.Add(new DataColumn("Region", typeof(string))); • dt.Columns.Add(new DataColumn("Pfach", typeof(string))); • dt.Columns.Add(new DataColumn("PostalCode", typeof(string))); • dt.Columns.Add(new DataColumn("Address", typeof(string))); • dt.Columns.Add(new DataColumn("Telephone", typeof(string))); • dt.Columns.Add(new DataColumn("Fax", typeof(string))); • // Write the results to the console • foreach ( • microsoft.lobservices.sap._2007._03.Types.Rfc.BRFCKNA1 customer in customers) • { • dr = dt.NewRow(); • dr[0] = customer.NAME1; • dr[1] = customer.KUNNR; • dr[2] = customer.ORT01; • dr[3] = customer.PFACH; • dr[4] = customer.PSTLZ; • dr[5] = customer.STRAS; • dr[6] = customer.TELF1; • dr[7] = customer.TELFX; • dt.Rows.Add(dr); • } • GridView1.DataSource = dt; • GridView1.DataBind(); • } • } • catch (Exception ex) • { • } • }
Visual Studio 4-5. Coding Paste the attached code.
Visual Studio 4-5. Coding
Visual Studio 4-6. Debugging the application
BizTalk Adapter Pack (SAP) setup procedure • Console application development • Table select, .NET Data Provider for SAP • Console application development • RFC/BAPI execution, WCF LOB Adapter • ASP .NET Web application development • Table select, .NET Data Provider for SAP • ASP .NET Web application development • RFC/BAPI execution, WCF LOB Adapter • ASP .NET Web Service development • Table select, .NET Data Provider for SAP
Landscape SAP Consoleapplication Table,View Web application BAPIRFC SAP R/3 SAP ERP XML WebServices
Visual Studio 5-1. Creating a new ASP .NET Web Service project
Visual Studio 5-2. Adding references