1 / 56

SAP & .NET application (Visual Studio 2005) Integration

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.

boone
Télécharger la présentation

SAP & .NET application (Visual Studio 2005) Integration

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SAP & .NET application(Visual Studio 2005) Integration Microsoft CorporationSAP-Microsoft Competence Center (Tokyo)

  2. Landscape SAP Consoleapplication Table,View Web application BAPIRFC SAP R/3 SAP ERP XML WebServices

  3. 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

  4. Landscape SAP Consoleapplication Table,View Web application BAPIRFC SAP R/3 SAP ERP XML WebServices

  5. 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

  6. 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; • } • } • } • } • } • }

  7. (*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>

  8. Visual Studio 1-1. Creating a new console application project

  9. Visual Studio 1-2. Adding references

  10. Visual Studio 1-3. Coding Paste the attached code.

  11. Visual Studio 1-4. Building/deploying the code

  12. Visual Studio 1-5. Executing the console application

  13. 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

  14. Landscape SAP Consoleapplication Table,View Web application BAPIRFC SAP R/3 SAP ERP XML WebServices

  15. 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); • } • } • } • }

  16. Visual Studio 2-1. Creating a new console application project

  17. Visual Studio 2-2. Adding references

  18. Visual Studio 2-3. Adding Adapter Service Reference

  19. Visual Studio 2-3. Adding Adapter Service Reference

  20. Visual Studio 2-4. Coding Paste the attached code.

  21. Visual Studio 2-5. Building/deploying the code

  22. Visual Studio 2-6. Executing the console application

  23. 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

  24. Landscape SAP Consoleapplication Table,View Web application BAPIRFC SAP R/3 SAP ERP XML WebServices

  25. Visual Studio 3-1. Creating a new ASP .NET Web application project

  26. Visual Studio 3-2. Designing the user interface

  27. Visual Studio 3-3. Adding references

  28. 3. ASP .NET Web application development (1) • using Microsoft.Data.SAPClient; • using Microsoft.Adapters.SAP; • using Microsoft.ServiceModel.Channels; • using System.Collections.Generic;

  29. Visual Studio 3-5. Coding Paste the attached code.

  30. 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(); • } • } • } • } • }

  31. Visual Studio 3-5. Coding Paste the attached code.

  32. Visual Studio 3-5. Coding

  33. Visual Studio 3-6. Debugging the application

  34. 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

  35. Landscape SAP Consoleapplication Table,View Web application BAPIRFC SAP R/3 SAP ERP XML WebServices

  36. Visual Studio 4-1. Creating a new ASP .NET Web application project

  37. Visual Studio 4-2. Designing the user interface

  38. Visual Studio 4-3. Adding references

  39. Visual Studio 4-4. Adding Adapter Service Reference

  40. Visual Studio 4-4. Adding Adapter Service Reference

  41. 4. ASP .NET Web application development (1) • using System.ServiceModel; • using Microsoft.ServiceModel.Channels; • using Microsoft.Adapters.SAP;

  42. Visual Studio 4-5. Coding Paste the attached code.

  43. 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) • { • } • }

  44. Visual Studio 4-5. Coding Paste the attached code.

  45. Visual Studio 4-5. Coding

  46. Visual Studio 4-6. Debugging the application

  47. 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

  48. Landscape SAP Consoleapplication Table,View Web application BAPIRFC SAP R/3 SAP ERP XML WebServices

  49. Visual Studio 5-1. Creating a new ASP .NET Web Service project

  50. Visual Studio 5-2. Adding references

More Related