📜 ⬆️ ⬇️

Integration with SAP ERP. The implementation of mobile price-checker in the store

In our example of integrating SAP ERP with third-party software, we will use the SAP Connector for Microsoft .NET to get data from SAP. The software for the data collection terminal (TSD) will interact with Microsoft Internet Information Server (IIS) on the server and with any client software such as Internet Explorer, the technology used for developing the component is asp.net in the C # programming language.


When developing a functional module (FM) in SAP, specify the “Remote Module” parameter:



The function takes the value of the factory I_WERKS and returns the table TAB:


FUNCTION Y_GET_MATNR_PRICE IMPORTING VALUE(I_WERKS) TYPE WERKS_D TABLES TAB LIKE YSOUT_PRICE EXCEPTIONS NO_DATA NO_VKORG. 

We will save the settings for IIS in the SQL Server database in a separate table:



In asp.net parts in C #, use SAP Connector for Microsoft .NET


Setting up SAP Connector:


  public class MyBackendConfig : IDestinationConfiguration { SaalutDataClasses1DataContext context; public RfcConfigParameters GetParameters(String destinationName) { if (context == null) context = new SaalutDataClasses1DataContext(); if ("AEP".Equals(destinationName)) { var settingsSP = (from s in context.SettingsSAPERPTbls select s).FirstOrDefault(); RfcConfigParameters parms = new RfcConfigParameters(); parms.Add(RfcConfigParameters.Name, settingsSP.SystemID); parms.Add(RfcConfigParameters.AppServerHost, settingsSP.MessageServerHost); if (settingsSP.LogonGroup != null || settingsSP.LogonGroup != "") parms.Add(RfcConfigParameters.LogonGroup, settingsSP.LogonGroup); parms.Add(RfcConfigParameters.SystemID, settingsSP.SystemID); parms.Add(RfcConfigParameters.SystemNumber, settingsSP.SystemNumber); if (settingsSP.SAPRouter != null || settingsSP.SAPRouter != "") parms.Add(RfcConfigParameters.SAPRouter, settingsSP.SAPRouter); parms.Add(RfcConfigParameters.User, settingsSP.SAPUser); parms.Add(RfcConfigParameters.Password, settingsSP.SAPPassword); parms.Add(RfcConfigParameters.Client, settingsSP.Client); parms.Add(RfcConfigParameters.Language, "en"); parms.Add(RfcConfigParameters.PoolSize, "5"); parms.Add(RfcConfigParameters.MaxPoolSize, "10"); parms.Add(RfcConfigParameters.IdleTimeout, "600"); return parms; } else return null; } public bool ChangeEventsSupported() { return false; } public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged; } 

Setting up a connection to SAP ERP and receiving data from FM Y_GET_MATNR_PRICE (c #):


  RfcDestinationManager.RegisterDestinationConfiguration(cfg);//1 RfcDestination prd = RfcDestinationManager.GetDestination("AEP");//2 RfcRepository repo = prd.Repository;//3 IRfcFunction pricesBapi = repo.CreateFunction("Y_GET_MATNR_PRICE");//4 pricesBapi.SetValue("I_WERKS", werk); //5 pricesBapi.Invoke(prd); //6 IRfcTable detail = pricesBapi.GetTable("TAB"); 

The resulting data is inserted into the SQL Server table:


  int i = 0; foreach (IRfcStructure elem in detail) { string matnr = elem[0].GetString(); double kbetr = elem[1].GetDouble(); string kschl = elem[2].GetString(); string assort = elem[3].GetString(); SAPPriceTbl np = new SAPPriceTbl(); np.MATNR = matnr; np.KBETR = kbetr; np.KSCHL = kschl; np.ASSORT = assort; context.SAPPriceTbls.InsertOnSubmit(np); if (i == 100) { context.SubmitChanges(); i = 0; } i++; } context.SubmitChanges(); 

We draw the interface in the Visual Studio for the Terminal of Data Collection (TSD). When working with a TSD, we perform a barcode search, visually compare the price on the TSD screen with the price on the price tag, and in case of discrepancies add to the log



Formed magazine price tags, print and replace the price tags on the trading floor.


→ The full C # code can be viewed on GitHub


→ The full code of the SAP function module as an example on GitHub


The functionality of SAP Connector for Microsoft .NET and C # allows you to receive data in a simple and convenient way from SAP ERP.


')

Source: https://habr.com/ru/post/446964/


All Articles