Skip to the content

How to integrate live SAP data into Aras Innovator

Integration of your PLM system and your ERP system has many benefits. One of them is synchronization of the engineering and manufacturing views of the BOM and the change process.

In this tutorial, you will learn how to integrate live data from the ERP system SAP into Aras Innovator.

The step-by-step video tutorial will guide you through the process. Scroll down to find additional information and scripts.

Additional tutorial notes

Before starting, create a free account on the SAP HANA Cloud API using the link below. Then get a new API key by clicking the "Show API key"-button.

SAP MATERIAL STOCK API Documentation:
https://api.sap.com/api/API_MATERIAL_STOCK_SRV/resource

JSON Class generated using:
http://json2csharp.com/

Method name: SAP_StockReader
Type: C#
ItemType: Part (or any you'd like)
Event: OnAfterGet
Package: com.aras.innovator.solution.PLM

Add line to: method-config.xml
In <ReferencedAssemblies> add: <name>$(binpath)/Newtonsoft.Json.dll</name>

Part Properties:
sap_material - String
sap_materialbaseunit - SAP Unit - Federated ( * )
sap_materialqty SAP Quantity - Federated ( * )
sap_materialfound - Federated (**)

(*) Disabled on form
(**) Hidden on form

            if (this.isCollection()) return (this);
            
            if (String.IsNullOrEmpty(this.getProperty("sap_material", ""))) { 
                this.setProperty("sap_materialfound", "0");
                return (this);
             }

            Innovator inn = this.getInnovator();

            // All materials: "https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_MATERIAL_STOCK_SRV/A_MaterialStock"
            // Select material: "https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_MATERIAL_STOCK_SRV/A_MaterialStock('FG226')?%24select=to_MatlStkInAcctMod&%24expand=to_MatlStkInAcctMod"

            string material = this.getProperty("sap_material", ""); // "FG226";
            string APIKey = "nEg9KynnWltBYwhZyJSn2XK1B6QCzQEM";

            string url = @"https://" + "sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_MATERIAL_STOCK_SRV/A_MaterialStock('" + material + "')?%24select=to_MatlStkInAcctMod&%24expand=to_MatlStkInAcctMod";
            var request = (HttpWebRequest)WebRequest.Create(url);

            request.Method = "GET";
            request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
            request.ContentType = "application/json";
            request.Accept = "application/json";
            request.Headers.Add("APIKey", APIKey);

            string json = string.Empty;

            try
            {
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    using (var stream = response.GetResponseStream())
                    {
                        using (var sr = new StreamReader(stream))
                        {
                            json = sr.ReadToEnd();
                        }
                    }
                }

                SAP_MATERIAL_STOCK stock = Newtonsoft.Json.JsonConvert.DeserializeObject<SAP_MATERIAL_STOCK>(json);

                decimal qtyTotal = 0;
                string sap_materialbaseunit = "";

                foreach (Result item in stock.d.to_MatlStkInAcctMod.results)
                {
                    decimal qty = 0;
                    Decimal.TryParse(item.MatlWrhsStkQtyInMatlBaseUnit, out qty);
                    sap_materialbaseunit = item.MaterialBaseUnit;

                    qtyTotal += qty;
                }

                this.setProperty("sap_materialfound", "1");

                this.setProperty("sap_materialbaseunit", sap_materialbaseunit);
                this.setProperty("sap_materialqty", qtyTotal.ToString("0.##"));

                return (this);
            } catch
            {
                this.setProperty("sap_materialfound", "0");
                return (this);
            }
        }
    }

    public class Metadata
    {
        public string id { get; set; }
        public string uri { get; set; }
        public string type { get; set; }
    }

    public class Metadata2
    {
        public string id { get; set; }
        public string uri { get; set; }
        public string type { get; set; }
    }

    public class Deferred
    {
        public string uri { get; set; }
    }

    public class ToMaterialStock
    {
        public Deferred __deferred { get; set; }
    }

    public class Result
    {
        public Metadata2 __metadata { get; set; }
        public string Material { get; set; }
        public string Plant { get; set; }
        public string StorageLocation { get; set; }
        public string Batch { get; set; }
        public string Supplier { get; set; }
        public string Customer { get; set; }
        public string WBSElementInternalID { get; set; }
        public string SDDocument { get; set; }
        public string SDDocumentItem { get; set; }
        public string InventorySpecialStockType { get; set; }
        public string InventoryStockType { get; set; }
        public string MaterialBaseUnit { get; set; }
        public string MatlWrhsStkQtyInMatlBaseUnit { get; set; }
        public ToMaterialStock to_MaterialStock { get; set; }
    }

    public class ToMatlStkInAcctMod
    {
        public List<Result> results { get; set; }
    }

    public class D
    {
        public Metadata __metadata { get; set; }
        public ToMatlStkInAcctMod to_MatlStkInAcctMod { get; set; }
    }

    public class SAP_MATERIAL_STOCK
    {
        public D d { get; set; }
    
        public SAP_MATERIAL_STOCK() {

About the author

Stephan Thierry

Stephan Thierry has 20 years of experience in software development and all surrounding processes. which are daily being put to the test as head of IT in Minerva. Among his specialties are .NET-Core, JavaScript, Aras Innovator, Security policies, Infrastructure, Documentation, SourceControl, Bug tracking systems, Support Organisation, GitLab CE, DevOps, Training and Machine Learning.

comments powered by Disqus

Request Demo

Ready to see Medical Device PLM in action? Send an email for a Free Demo and get a one-on-one preview on how your Business can benefit!