Bevor Sie beginnen, erstellen Sie über den folgenden Link ein kostenloses Konto in der SAP HANA Cloud-API. Dann erhalten Sie einen neuen API-Schlüssel, indem Sie auf die Schaltfläche "Show API Key" klicken.
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() {