public static IRfcTable SAPExecuteDeulTableData(Hashtable[] arrht1, string Function_Name, string RfcStructure_Name, string SetTable_Name, string GetTable_Name) { RfcConfigParameters configParam = GetConfigParam(); RfcDestination destination = RfcDestinationManager.GetDestination(configParam); IRfcFunction function = destination.Repository.CreateFunction(Function_Name); IRfcTable rfcTable = function.GetTable(SetTable_Name); for (int i = 0; i < arrht1.Length; i++) { RfcStructureMetadata strMeta = destination.Repository.GetStructureMetadata(RfcStructure_Name); IRfcStructure rfcStructure = strMeta.CreateStructure(); IDictionaryEnumerator ie = arrht1[i].GetEnumerator(); while (ie.MoveNext()) { if (ie.Value.ToString().Length <= 4000) { rfcStructure.SetValue(ie.Key.ToString(), ie.Value); } } rfcTable.Append(rfcStructure); } function.Invoke(destination); IRfcTable rfcTable2 = function.GetTable(GetTable_Name); return(rfcTable2); }
public IRfcStructure CreateStructure(RfcStructureMetadata metadata, object parameterObject) { if (parameterObject == null) { return(null); } IRfcStructure structure = metadata.CreateStructure(); Type type = parameterObject.GetType(); EnsureTypeIsCached(type); for (int i = 0; i < metadata.FieldCount; i++) { string fieldName = metadata[i].Name; PropertyInfo property = null; object formattedValue = null; if (typeProperties[type].TryGetValue(fieldName.ToLower(), out property)) { object value = property.GetValue(parameterObject, null); formattedValue = this.ToRemoteValue(metadata[i].GetAbapDataType(), value); } else if (string.IsNullOrEmpty(fieldName)) { formattedValue = this.ToRemoteValue(metadata[i].GetAbapDataType(), parameterObject); } structure.SetValue(fieldName, formattedValue); } return(structure); }
public static string SAPExecuteStructureData(Hashtable ht, string Function_Name, string RfcStructure_Name, string param1) { RfcConfigParameters configParam = GetConfigParam(); RfcDestination destination = RfcDestinationManager.GetDestination(configParam); IRfcFunction function = destination.Repository.CreateFunction(Function_Name); RfcStructureMetadata strMeta = destination.Repository.GetStructureMetadata(RfcStructure_Name); IRfcStructure rfcStructure = strMeta.CreateStructure(); IDictionaryEnumerator ie = ht.GetEnumerator(); while (ie.MoveNext()) { if (ie.Value.ToString().Length <= 4000) { rfcStructure.SetValue(ie.Key.ToString(), ie.Value); } } function.SetValue(param1, rfcStructure); function.Invoke(destination); string returnCode = function.GetString("EV_E_TYPE"); return(returnCode); }
private Boolean ImportInvoice(String databaseName, DocumentCached invoice, out String documentNumber, out String errorMessage) { errorMessage = String.Empty; documentNumber = String.Empty; try { IRfcFunction fReadTable = repo.CreateFunction("ZZBAPI_DEBIT_MEMO_REQUEST"); fReadTable.SetValue("CUSTOMER", ("0000000" + invoice.CustomerCode).Right(10)); fReadTable.SetValue("SALES_ORG", invoice.VLCompany); fReadTable.SetValue("PURCH_DATE", invoice.DocDate); fReadTable.SetValue("PURCH_NO_C", invoice.Comment); foreach (DocumentLineCached line in invoice.Lines) { RfcStructureMetadata metaData = dest.Repository.GetStructureMetadata("ZORDERLINE"); IRfcStructure structConditions = metaData.CreateStructure(); structConditions.SetValue("ITM_NUMBER", ("0000" + line.LineNum.ToString() + "0").Right(6)); structConditions.SetValue("MATERIAL", line.ItemCode); // C => Certificate structConditions.SetValue("TARGET_QTY", line.Quantity); structConditions.SetValue("SALES_UNIT", line.UnitOfMeasure); structConditions.SetValue("COND_VALUE", line.Price); structConditions.SetValue("CURRENCY", line.Currency); structConditions.SetValue("SHORT_TEXT", line.ShortText); IRfcTable tblItems = fReadTable.GetTable("ORDERLINE"); tblItems.Append(structConditions); fReadTable.SetValue("ORDERLINE", tblItems); } fReadTable.Invoke(dest); String result = (String)fReadTable.GetValue("SALESDOCUMENT"); IRfcStructure result2 = (IRfcStructure)fReadTable.GetValue("RETURN"); documentNumber = result.ToString(); errorMessage = result2[3].ToString().Replace("FIELD MESSAGE=", ""); if (String.IsNullOrEmpty(documentNumber) || !String.IsNullOrEmpty(errorMessage)) { return(false); } } catch (Exception ex) { errorMessage = ex.Message; } return(true); }
public static string SAPExecuteTableData(Hashtable[] arrht, Hashtable ImportData, string Function_Name, string RfcStructure_Name, string Table_Name) { RfcConfigParameters configParam = GetConfigParam(); RfcDestination destination = RfcDestinationManager.GetDestination(configParam); IRfcFunction function = destination.Repository.CreateFunction(Function_Name); IRfcTable rfcTable = function.GetTable(Table_Name); for (int i = 0; i < arrht.Length; i++) { RfcStructureMetadata strMeta = destination.Repository.GetStructureMetadata(RfcStructure_Name); IRfcStructure rfcStructure = strMeta.CreateStructure(); if (arrht[i] == null) { continue; } IDictionaryEnumerator ie = arrht[i].GetEnumerator(); while (ie.MoveNext()) { if (ie.Value.ToString().Length <= 4000) { rfcStructure.SetValue(ie.Key.ToString(), ie.Value); } } rfcTable.Append(rfcStructure); } if (ImportData.Count > 0) { IDictionaryEnumerator ie = ImportData.GetEnumerator(); while (ie.MoveNext()) { if (ie.Value.ToString().Length <= 4000) { function.SetValue(ie.Key.ToString(), ie.Value); } } } function.Invoke(destination); string returnCode = function.GetString("E_VBELN"); return(returnCode); }
public FunctionResult ExecuteInsert(string functionName, List <NTable> parameters, List <string> tableNames) { try { _function = _destination.Repository.CreateFunction(functionName); for (int i = 0; i < tableNames.Count; i++) { RfcStructureMetadata metaData = _destination.Repository.GetStructureMetadata(parameters[i].StructureName); IRfcTable tblInput = _function.GetTable(tableNames[i]); foreach (DataRow row in parameters[i].Parameters.Rows) { IRfcStructure structRow = metaData.CreateStructure(); foreach (DataColumn column in parameters[i].Parameters.Columns) { object obj = row[column]; structRow.SetValue(column.ToString(), obj); } tblInput.Append(structRow); } } RfcSessionManager.BeginContext(_destination); _function.Invoke(_destination); IRfcTable returnTable = _function.GetTable("NOTESRETURN"); return(new FunctionResult { IsSuccess = true, Data = new List <object> { returnTable } }); } catch (Exception ex) { return(new FunctionResult { IsSuccess = false, ErrorMessage = ex.ToString() }); } }
private double ProductInfoGetRealtimeStock(string branchCode, string warehouseCode, string productCode, string uom) { RfcDestination sapRfcDestination = SapHelper.Destination; RfcRepository sapRfcRepository = sapRfcDestination.Repository; RfcRepository repo = sapRfcRepository; string bapiName = "BAPI_MATERIAL_AVAILABILITY"; IRfcFunction exportBapi = repo.CreateFunction(bapiName); exportBapi.SetValue("PLANT", ""); exportBapi.SetValue("MATERIAL", ""); exportBapi.SetValue("UNIT", ""); exportBapi.SetValue("CHECK_RULE", ""); exportBapi.SetValue("STGE_LOC", ""); exportBapi.SetValue("BATCH", ""); exportBapi.SetValue("CUSTOMER", ""); exportBapi.SetValue("DOC_NUMBER", ""); exportBapi.SetValue("ITM_NUMBER", ""); exportBapi.SetValue("WBS_ELEM", ""); exportBapi.SetValue("STOCK_IND", ""); exportBapi.SetValue("DEC_FOR_ROUNDING", 0); exportBapi.SetValue("DEC_FOR_ROUNDING_X", ""); exportBapi.SetValue("READ_ATP_LOCK", ""); exportBapi.SetValue("READ_ATP_LOCK_X", ""); IRfcStructure articol; RfcStructureMetadata am = repo.GetStructureMetadata("BAPIMGVMATNR"); articol = am.CreateStructure(); exportBapi.SetValue("MATERIAL_EVG", articol); exportBapi.SetValue("MATERIAL", FormatedProductCode(productCode)); exportBapi.SetValue("PLANT", branchCode); exportBapi.SetValue("UNIT", uom); exportBapi.SetValue("STGE_LOC", warehouseCode); exportBapi.SetValue("CHECK_RULE", "B"); exportBapi.SetValue("ITM_NUMBER", "000000"); exportBapi.Invoke(sapRfcDestination); IRfcTable detail = exportBapi.GetTable("WMDVEX"); return(detail.RowCount); }
private Boolean ImportInvoice2(String databaseName, DocumentCached invoice) { IRfcFunction fReadTable = repo.CreateFunction("ZZBAPI_DEBIT_MEMO_REQUEST"); fReadTable.SetValue("CUSTOMER", "0000008289"); fReadTable.SetValue("SALES_ORG", "ZW01"); fReadTable.SetValue("PURCH_DATE", DateTime.Now); fReadTable.SetValue("PURCH_NO_C", "TEST ZZBAPI_DEBIT_MEMO_REQUEST"); RfcStructureMetadata metaData = dest.Repository.GetStructureMetadata("ZORDERLINE"); IRfcStructure structConditions = metaData.CreateStructure(); structConditions.SetValue("ITM_NUMBER", "000010"); structConditions.SetValue("MATERIAL", "C"); // C => Certificate structConditions.SetValue("TARGET_QTY", 10); structConditions.SetValue("SALES_UNIT", "ST"); structConditions.SetValue("COND_VALUE", 16); structConditions.SetValue("CURRENCY", "EUR"); structConditions.SetValue("SHORT_TEXT", "test"); IRfcTable tblItems = fReadTable.GetTable("ORDERLINE"); tblItems.Append(structConditions); fReadTable.SetValue("ORDERLINE", tblItems); fReadTable.Invoke(dest); var result = fReadTable.GetValue("SALESDOCUMENT"); var result2 = fReadTable.GetValue("RETURN"); Console.WriteLine(result.ToString()); Console.ReadLine(); return(true); }
public static IRfcStructure CreateRFCStructure(Dictionary <string, object> item, RfcDestination destination, string structureName) { RfcStructureMetadata metaData = destination.Repository.GetStructureMetadata(structureName); IRfcStructure structure = metaData.CreateStructure(); foreach (var key in item.Keys) { if (GetDataType(structure[key].Metadata.DataType) == typeof(DateTime)) { structure.SetValue(key, ((DateTime)item[key]).ToString(kSAPStructureDateFormat)); } else if (GetDataType(structure[key].Metadata.DataType) == typeof(TimeSpan)) { TimeSpan t = (TimeSpan)item[key]; structure.SetValue(key, string.Format(kSAPStructureTimeFormat, t.Hours, t.Minutes, t.Seconds)); } else { structure.SetValue(key, item[key]); } } return(structure); }
/// <summary> /// Below function gets products information. /// </summary> /// <param name="Productname"></param> /// <param name="RegionID"></param> /// <param name="RegionName"></param> /// <param name="LanguageId"></param> /// <param name="LanguageName"></param> /// <param name="Materialno"></param> /// <param name="MaxHitcount"></param> /// <param name="ViewType"></param> /// <returns></returns> public List <SIISAPMSDSDTO> GetProductsInformation(string RegionID, string RegionName, string LanguageId, string LanguageName, string Productname, string Materialno, int MaxHitcount, string ViewType) { List <SIISAPMSDSDTO> objMDSDSList = new List <SIISAPMSDSDTO>(); var rfcDestination = RfcDestinationManager.GetDestination("SIISAP"); try { if (rfcDestination != null) { var getGateEntryRfc = rfcDestination.Repository.CreateFunction("ZEHS_MSDS_PRTL_F4_LIST_OF_MSDS"); /// PRODUCT RfcStructureMetadata metaData = rfcDestination.Repository.GetStructureMetadata("ZEHS_GEN_PRODS"); IRfcStructure structProduct = metaData.CreateStructure(); structProduct.SetValue("BRAND2", Productname);//, "ALKANOX® 240"); getGateEntryRfc.SetValue("I_PROD", structProduct); /// REGION RfcStructureMetadata metaDataCountry = rfcDestination.Repository.GetStructureMetadata("ZEHS_GEN_CNTRY"); IRfcStructure structRegions = metaDataCountry.CreateStructure(); structRegions.SetValue("LDEPID", RegionID); // "SDS_US"); structRegions.SetValue("LDEPNAM", RegionName); // ""); getGateEntryRfc.SetValue("I_REGION", structRegions); // LANGUAGE RfcStructureMetadata metaDataLanguage = rfcDestination.Repository.GetStructureMetadata("ZEHS_GEN_LNGS"); IRfcStructure strucLanguage = metaDataLanguage.CreateStructure(); strucLanguage.SetValue("SPRAS", LanguageId); // "E"); strucLanguage.SetValue("SPTXT", LanguageName); // ""); getGateEntryRfc.SetValue("I_LANGUAGE", strucLanguage); /// MATERIAL NUMBER getGateEntryRfc.SetValue("I_MATNR", Materialno); // "*"); /// MAX HIT COUNT getGateEntryRfc.SetValue("I_MAX_HIT_COUNT", MaxHitcount); // 300); /// I VIEW TYPE getGateEntryRfc.SetValue("I_VIEWTYPE", ViewType); // ""); // RfcSessionManager.BeginContext(rfcDestination); getGateEntryRfc.Invoke(rfcDestination); /// get the table values IRfcTable Report = getGateEntryRfc.GetTable("E_REPORT_TAB"); IRfcTable ObjectReport = getGateEntryRfc.GetTable("E_REPORT_OBJECT_TAB"); //Getting exported values from SAP var COUNT = getGateEntryRfc.GetValue("E_COUNT"); var MaxHITCount = getGateEntryRfc.GetValue("E_FLG_MAX_HIT_REACHED"); var objRTFT = getGateEntryRfc.GetValue("E_BRAND2").ToString().Substring(getGateEntryRfc.GetValue("E_BRAND2").ToString().LastIndexOf("=") + 1).Replace("}", ""); RfcSessionManager.EndContext(rfcDestination); foreach (var row in Report) { objMDSDSList.Add(new SIISAPMSDSDTO { ID = row[0].ToString().Substring(row[0].ToString().IndexOf("=") + 1), RECN = row[1].ToString().Substring(row[1].ToString().IndexOf("=") + 1), LANGU = row[2].ToString().Substring(row[2].ToString().IndexOf("=") + 1), LANGUTXT = row[3].ToString().Substring(row[3].ToString().IndexOf("=") + 1), LanguageID = row[4].ToString().Substring(row[4].ToString().IndexOf("=") + 1), LanguageText = row[5].ToString().Substring(row[5].ToString().IndexOf("=") + 1), Version = row[6].ToString().Substring(row[6].ToString().IndexOf("=") + 1), REPTYPE = row[7].ToString().Substring(row[7].ToString().IndexOf("=") + 1), REPTYPETEXT = row[8].ToString().Substring(row[8].ToString().IndexOf("=") + 1), RVLID = row[9].ToString().Substring(row[9].ToString().IndexOf("=") + 1), RVLIDTXT = row[10].ToString().Substring(row[10].ToString().IndexOf("=") + 1), STATUS = row[11].ToString().Substring(row[11].ToString().IndexOf("=") + 1), STATUSTXT = row[12].ToString().Substring(row[12].ToString().IndexOf("=") + 1), GENDAT = row[13].ToString().Substring(row[13].ToString().IndexOf("=") + 1), VALDAT = row[14].ToString().Substring(row[14].ToString().IndexOf("=") + 1), REMARK = row[15].ToString().Substring(row[15].ToString().IndexOf("=") + 1), PrdFileName = objRTFT }); var listinfo = objMDSDSList; } rfcDestination = null; } } catch (Exception ex) { RfcSessionManager.EndContext(rfcDestination); rfcDestination = null; FilePath = ConfigurationManager.AppSettings["siteUrl"]; WriteLog(FilePath, ex.Message); } return(objMDSDSList); }
public Location LocationGetByCode(string locationCode, string warehouseCode) { Location location = null; //using (var db = new DbManager("HandHeldDB")) //{ // var reader = db.SetCommand(GetSql(43), // db.Parameter("@LocationCode", locationCode), // db.Parameter("@WarehouseCode", warehouseCode)) // .ExecuteReader(); // while (reader.Read()) // { // location = new Location { Code = (string)reader["LocationCode"], WarehouseCode = (string)reader["WarehouseCode"] }; // } //} //var conn = new DBCon.DBSQLDataContext(); //var locationli = conn.ProductLocations.Where(x => x.LocationCode == locationCode && x.WarehouseCode == warehouseCode).ToList(); //foreach (var item in locationli) //{ // location = new Location { Code = item.LocationCode, WarehouseCode = item.WarehouseCode }; //} if (location == null) { RfcDestination sapRfcDestination = SapHelper.Destination; RfcRepository sapRfcRepository = sapRfcDestination.Repository; char delimiter = ':'; RfcRepository repo = sapRfcRepository; string bapiName = "RFC_READ_TABLE"; IRfcFunction exportBapi = repo.CreateFunction(bapiName); exportBapi.SetValue("QUERY_TABLE", "ZLOCSTRC"); exportBapi.SetValue("DELIMITER", delimiter); exportBapi.SetValue("NO_DATA", ""); exportBapi.SetValue("ROWSKIPS", 0); exportBapi.SetValue("ROWCOUNT", 0); RfcStructureMetadata rfcDbOpt = repo.GetStructureMetadata("RFC_DB_OPT"); var opt = rfcDbOpt.CreateStructure(); //opt.SetValue("TEXT", @"(APRVFLAG = 'C') AND (USEFLAG = 'X')"); opt.SetValue("TEXT", string.Format(" (BINLOC = '{0}') ", locationCode)); var tableOptions = exportBapi.GetTable("OPTIONS"); tableOptions.Append(opt); var table = exportBapi.GetTable("FIELDS"); IRfcStructure articol; RfcStructureMetadata am = repo.GetStructureMetadata("RFC_DB_FLD"); articol = am.CreateStructure(); articol.SetValue("FIELDNAME", "BINLOC"); table.Append(articol); articol = am.CreateStructure(); articol.SetValue("FIELDNAME", "LGORT"); table.Append(articol); articol = am.CreateStructure(); articol.SetValue("FIELDNAME", "USEFLAG"); table.Append(articol); exportBapi.SetValue("FIELDS", table); exportBapi.SetValue("OPTIONS", tableOptions); exportBapi.Invoke(sapRfcDestination); IRfcTable detail2 = exportBapi.GetTable("DATA"); string[] value; foreach (var item in detail2) { value = item.GetString("WA").Replace(" ", "").Split(delimiter); if (((string)value.GetValue(0)).Length != 10) { continue; } if ((string)value.GetValue(2) != "X") { continue; } if (((string)value.GetValue(1)).ToUpper() != warehouseCode.ToUpper()) { continue; } location = new Location(); location.Code = (string)value.GetValue(0); location.WarehouseCode = (string)value.GetValue(1); //using (var db = new DbManager("HandHeldDB")) //{ // //insert new data // db.SetCommand(GetSql(88), // db.Parameter("@LocationCode", location.Code), // db.Parameter("@WarehouseCode", location.WarehouseCode), // db.Parameter("@isUse", location.IsUse) // ).ExecuteNonQuery(); //} break; } } return(location); //List<SAPProxyII.ZLOCSTRC> locations; //string key = string.Format(LOCATION_ALL_KEY, DateTime.Now.Date.Day); //string keyOld = string.Format(LOCATION_ALL_KEY, DateTime.Now.AddDays(-1).Day); //object obj1 = _cacheManager.Get(keyOld); //object obj2 = _cacheManager.Get(key); //if (obj1 != null) // _cacheManager.Remove(keyOld); //if (obj2 != null) // locations = (List<SAPProxyII.ZLOCSTRC>)obj2; //else //{ // using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination)) // { // using (var prx = new SAPProxyII.UWProxy()) // { // prx.Connection = sapConnection; // SAPProxyII.ZLOCSTRCTable Tables = new SAPProxyII.ZLOCSTRCTable(); // prx.Zdd_Handheld_Get_Zlockstrc(ref Tables); // locations = (List<SAPProxyII.ZLOCSTRC>)CollectionHelper.ConvertTo<SAPProxyII.ZLOCSTRC>(Tables.ToADODataTable()); // _cacheManager.Add(key, locations); // } // } //} //var location = locations.Find(p => p.Binloc == locationCode); //if (location != null) //{ // var locat = new Location(); // locat.Code = location.Binloc; // locat.LocationType = location.Loctype; // return locat; //} //else // return null; }
public static Hashtable SAPExecuteTableData_Common(Hashtable[] arrht, Hashtable ImportData, string Function_Name, string RfcStructure_Name, string Table_Name, string GetTable_Name, string GetTable_Name2) { RfcConfigParameters configParam = GetConfigParam(); RfcDestination destination = RfcDestinationManager.GetDestination(configParam); IRfcFunction function = destination.Repository.CreateFunction(Function_Name); IRfcTable rfcTable = function.GetTable(Table_Name); for (int i = 0; i < arrht.Length; i++) { RfcStructureMetadata strMeta = destination.Repository.GetStructureMetadata(RfcStructure_Name); IRfcStructure rfcStructure = strMeta.CreateStructure(); //if (arrht[i] == null) // continue; IDictionaryEnumerator ie = arrht[i].GetEnumerator(); while (ie.MoveNext()) { if (ie.Value.ToString().Length <= 4000) { rfcStructure.SetValue(ie.Key.ToString(), ie.Value); } } rfcTable.Append(rfcStructure); } if (ImportData.Count > 0) { IDictionaryEnumerator ie = ImportData.GetEnumerator(); while (ie.MoveNext()) { if (ie.Value.ToString().Length <= 4000) { function.SetValue(ie.Key.ToString(), ie.Value); } } } function.Invoke(destination); IRfcTable rfcTable2 = function.GetTable(GetTable_Name); IRfcTable rfcTable3 = null; if (GetTable_Name2 != null) { rfcTable3 = function.GetTable(GetTable_Name2); } Hashtable ht = new Hashtable(); switch (Function_Name) { case "ZMM_SKD_PO_AND_GR": ht.Add("I_EBELN", function.GetString("I_EBELN")); ht.Add("I_MBLNR", function.GetString("I_MBLNR")); ht.Add("FT_RETURN_PO", rfcTable2); ht.Add("FT_RETURN_GR", rfcTable3); break; case "ZMM_SKD_PO": ht.Add("I_EBELN", function.GetString("I_EBELN")); ht.Add("FT_RETURN_PO", rfcTable2); break; case "ZMM_SKD_BAPI_GOODSMVT_CREATE": ht.Add("I_MBLNR", function.GetString("I_MBLNR")); ht.Add("FT_RETURN_GR", rfcTable2); break; } return(ht); }