public IRfcTable Rfc_Qdt_Dal(RFC_QDT_Model qdtModel, out RFC_IN_Message rfcMessage) { rfcMessage = new RFC_IN_Message(); try { _configurationId = new RFC_SetUp(); RfcDestinationManager.RegisterDestinationConfiguration(_configurationId); _dest = RfcDestinationManager.GetDestination("SAPMS"); _repository = _dest.Repository; IRfcFunction rfc = _repository.CreateFunction(qdtModel.FunctionModule); //调用函数名 IRfcTable table = rfc.GetTable(qdtModel.E_SAP_QDT); //RFC表数据 rfc.SetValue("I_MESKEY", qdtModel.I_MESKEY); //KEY随机号 不能重复 rfc.SetValue("I_USER", qdtModel.I_USER); //登录名 rfc.SetValue("I_MATNR", qdtModel.I_MATNR); rfc.SetValue("I_CHARG", qdtModel.I_CHARG); rfc.Invoke(_dest); rfcMessage.E_RETURN_CODE = rfc.GetString("E_RETURN_CODE").ToString(); rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString(); rfcMessage.E_COUNT = rfc.GetInt("E_COUNT").ToString(); rfcMessage.E_SUM = rfc.GetInt("E_SUM").ToString(); return(table); } catch (Exception exception) { rfcMessage.E_RETURN_MESSAGE = "接口QDT 错误:" + exception.ToString(); return(null); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId); } }
public IRfcTable Rfc_Del_Dal(RFC_DEL_Model delModel, out RFC_IN_Message rfcMessage) { rfcMessage = new RFC_IN_Message(); try { _configurationId = new RFC_SetUp(); RfcDestinationManager.RegisterDestinationConfiguration(_configurationId); _dest = RfcDestinationManager.GetDestination("SAPMS"); _repository = _dest.Repository; IRfcFunction rfc = _repository.CreateFunction(delModel.FunctionModule); //调用函数名 IRfcTable table = rfc.GetTable(delModel.E_SAP_DEL); //RFC表数据 rfc.SetValue("I_MESKEY", delModel.I_MESKEY); //KEY随机号 不能重复 rfc.SetValue("I_DATE", delModel.I_DATE); //日期 rfc.SetValue("I_TIME", delModel.I_TIME); //时间 rfc.SetValue("I_USER", delModel.I_USER); //登录名 rfc.SetValue("I_VBELN", delModel.I_VBELN); rfc.Invoke(_dest); rfcMessage.E_RETURN_CODE = rfc.GetString("E_RETURN_CODE").ToString(); //rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString(); rfcMessage.E_COUNT = rfc.GetInt("E_COUNT").ToString(); rfcMessage.E_SUM = rfc.GetInt("E_SUM").ToString(); return(table); } catch (Exception exception) { rfcMessage.E_RETURN_MESSAGE = "接口DEL 错误:" + exception.ToString(); return(null); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId); } }
public RFC_OUT_Message Rfc_Gpr_Dal(List <RFC_GPR_Model.RFC_GPR_ITEM_Model> gprItemModel, RFC_GPR_Model.RFC_GPR_HEADER_Model gprHeaderModel) { RFC_OUT_Message rfcMessage = new RFC_OUT_Message(); try { _configurationId = new RFC_SetUp(); RfcDestinationManager.RegisterDestinationConfiguration(_configurationId); _dest = RfcDestinationManager.GetDestination("SAPMS"); _repository = _dest.Repository; IRfcFunction rfc = _repository.CreateFunction(gprHeaderModel.FunctionModule); //调用函数名 IRfcTable table = rfc.GetTable(gprHeaderModel.E_SAP_GRP); //RFC表数据 IRfcStructure structure = rfc.GetStructure("I_HEADER"); //RFC表头数据 structure.SetValue("ZMESKEY", gprHeaderModel.ZMESKEY); structure.SetValue("EBELN", gprHeaderModel.EBELN); structure.SetValue("BUKRS", gprHeaderModel.BUKRS); structure.SetValue("BSART", gprHeaderModel.BSART); structure.SetValue("EKORG", gprHeaderModel.EKORG); structure.SetValue("AEDAT", gprHeaderModel.AEDAT); structure.SetValue("LIFNR", gprHeaderModel.LIFNR); structure.SetValue("ZCOUNT", gprHeaderModel.ZCOUNT); structure.SetValue("ZUSER", gprHeaderModel.ZUSER); foreach (var _gprItemModel in gprItemModel) { table.Insert(); table.CurrentRow.SetValue("ZMESITEM", _gprItemModel.ZMESITEM); table.CurrentRow.SetValue("EBELP", _gprItemModel.EBELP); table.CurrentRow.SetValue("LOEKZ", _gprItemModel.LOEKZ); table.CurrentRow.SetValue("MATNR", _gprItemModel.MATNR); table.CurrentRow.SetValue("WERKS", _gprItemModel.WERKS); table.CurrentRow.SetValue("LGORT", _gprItemModel.LGORT); table.CurrentRow.SetValue("MENGE", _gprItemModel.MENGE); table.CurrentRow.SetValue("MEINS", _gprItemModel.MEINS); table.CurrentRow.SetValue("EINDT", _gprItemModel.EINDT); table.CurrentRow.SetValue("LICHA", _gprItemModel.LICHA); table.CurrentRow.SetValue("ZJPSONO", _gprItemModel.ZJPSONO); table.CurrentRow.SetValue("ZJPSOITEM", _gprItemModel.ZJPSOITEM); gprHeaderModel.ZSUM += _gprItemModel.MENGE;//所有数据全部相加,取总数 } structure.SetValue("ZSUM", gprHeaderModel.ZSUM); rfc.Invoke(_dest); rfcMessage.E_RETURN_CODE = rfc.GetString("E_RETURN_CODE").ToString(); //rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString(); rfcMessage.E_PO_NUMBER = rfc.GetInt("E_COUNT").ToString(); rfcMessage.E_EXPROC = rfc.GetInt("E_SUM").ToString(); return(rfcMessage); } catch (Exception exception) { rfcMessage.E_RETURN_MESSAGE = "接口GPR 错误:" + exception.ToString(); return(null); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId); } }
static void Main(string[] args) { try { SAPSystemConnect sapCfg = new SAPSystemConnect(); RfcDestinationManager.RegisterDestinationConfiguration(sapCfg); RfcDestination destination = RfcDestinationManager.GetDestination("ECQ"); RfcRepository repository = destination.Repository; IRfcFunction function = repository.CreateFunction("Z_SSRT_SUM"); function.SetValue("i_num1", 2); function.SetValue("i_num2", 4); function.Invoke(destination); int result = function.GetInt("e_result"); destination.Ping(); var rfcRepository = destination.Repository; var rfcFunction = rfcRepository.CreateFunction("RFC_CUSTOMER_DATA"); rfcFunction.SetValue("COUNTRY", "india"); rfcFunction.Invoke(destination); var table = rfcFunction.GetTable(0); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }
/// <summary> /// FUNCTION BAPI_USER_GETLIST /// </summary> /// <param name="ROWS">No. of users selected</param> /// <param name="MAX_ROWS">Maximum Number of Lines of Hits</param> /// <param name="WITH_USERNAME">Read User with Name</param> /// <param name="RETURN">Return Parameter</param> /// <param name="SELECTION_EXP">Search for Users with Free Selections</param> /// <param name="SELECTION_RANGE">Search for Users with a Ranges Table</param> /// <param name="USERLIST">User List</param> public static bool Invoke(ConnectionInformations ci, out string exception, out int ROWS, int MAX_ROWS, string WITH_USERNAME, ref SapTable <BAPIRET2> RETURN, ref SapTable <BAPIUSSEXP> SELECTION_EXP, ref SapTable <BAPIUSSRGE> SELECTION_RANGE, ref SapTable <BAPIUSNAME> USERLIST) { exception = ""; ROWS = default(int); try { SapConnections.Init(ci); RfcRepository rfcRep = SapConnections.Get(ci.Name).Repository; IRfcFunction function = rfcRep.CreateFunction("BAPI_USER_GETLIST"); function.SetValue("MAX_ROWS", MAX_ROWS); function.SetValue("WITH_USERNAME", WITH_USERNAME); if (RETURN != null) { function.SetValue("RETURN", RETURN.ToSapObject(ci.Name)); } if (SELECTION_EXP != null) { function.SetValue("SELECTION_EXP", SELECTION_EXP.ToSapObject(ci.Name)); } if (SELECTION_RANGE != null) { function.SetValue("SELECTION_RANGE", SELECTION_RANGE.ToSapObject(ci.Name)); } if (USERLIST != null) { function.SetValue("USERLIST", USERLIST.ToSapObject(ci.Name)); } function.Invoke(SapConnections.Get(ci.Name)); ROWS = function.GetInt("ROWS"); if (RETURN == null) { RETURN = new SapTable <BAPIRET2>(); } RETURN.FromSapObject(function.GetTable("RETURN")); if (SELECTION_EXP == null) { SELECTION_EXP = new SapTable <BAPIUSSEXP>(); } SELECTION_EXP.FromSapObject(function.GetTable("SELECTION_EXP")); if (SELECTION_RANGE == null) { SELECTION_RANGE = new SapTable <BAPIUSSRGE>(); } SELECTION_RANGE.FromSapObject(function.GetTable("SELECTION_RANGE")); if (USERLIST == null) { USERLIST = new SapTable <BAPIUSNAME>(); } USERLIST.FromSapObject(function.GetTable("USERLIST")); return(true); } catch (Exception ex) { exception = ex.Message; return(false); } }
public void initializeConfiguration() { ECCDestinationConfig config = new ECCDestinationConfig(); if (!isDestinationInitialized()) { RfcDestinationManager.RegisterDestinationConfiguration(config); destinationInitialized = true; } RfcDestination destination = RfcDestinationManager.GetDestination(getSystem()); RfcRepository repository = destination.Repository; IRfcFunction configurationFunction = repository.CreateFunction("ZBAPI_GET_PDM_CONFIG"); configurationFunction.Invoke(destination); setPDMInterval(configurationFunction.GetInt("INTERVAL")); }
public void cierreTempo(string P_UNAME, string P_PASSWORD, string P_IDSISTEMA, string P_INSTANCIA, string P_MANDANTE, string P_SAPROUTER, string P_SERVER, string P_IDIOMA, string P_ID_CAJA, string P_LAND, string P_MONTO_CIERRE, string P_MONTO_DIF, string P_COMENTARIO_DIF, string P_COMENTARIO_CIERRE) { try { T_Retorno.Clear(); errormessage = ""; status = ""; message = ""; stringRfc = ""; IRfcTable lt_CIERRE_CAJA_DET_EFECT; ESTATUS retorno; //Conexion a SAP connectorSap.idioma = P_IDIOMA; connectorSap.idSistema = P_IDSISTEMA; connectorSap.instancia = P_INSTANCIA; connectorSap.mandante = P_MANDANTE; connectorSap.paswr = P_PASSWORD; connectorSap.sapRouter = P_SAPROUTER; connectorSap.user = P_UNAME; connectorSap.server = P_SERVER; string retval = connectorSap.connectionsSAP(); //Si el valor de retorno es nulo o vacio, hay conexion a SAP y la RFC trae datos if (string.IsNullOrEmpty(retval)) { RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination(connectorSap.connectorConfig); RfcRepository SapRfcRepository = SapRfcDestination.Repository; IRfcFunction BapiGetUser = SapRfcRepository.CreateFunction("ZSCP_FM_REG_CIERRE"); BapiGetUser.SetValue("ID_CAJA", P_ID_CAJA); BapiGetUser.SetValue("USUARIO", P_UNAME); BapiGetUser.SetValue("LAND", P_LAND); BapiGetUser.SetValue("MONTO_CIERRE", P_MONTO_CIERRE); BapiGetUser.SetValue("MONTO_DIF", P_MONTO_DIF); BapiGetUser.SetValue("COMENTARIO_DIF", P_COMENTARIO_DIF); BapiGetUser.SetValue("COMENTARIO_CIERRE", P_COMENTARIO_CIERRE); BapiGetUser.Invoke(SapRfcDestination); //LLenamos los datos que retorna la estructura de la RFC //lt_CIERRE_CAJA = BapiGetUser.GetTable("ESTATUS"); diasatraso = BapiGetUser.GetInt("DIAS_ATRASO"); lt_CIERRE_CAJA_DET_EFECT = BapiGetUser.GetTable("ESTATUS"); for (int i = 0; i < lt_CIERRE_CAJA_DET_EFECT.Count(); i++) { lt_CIERRE_CAJA_DET_EFECT.CurrentIndex = i; retorno = new ESTATUS(); retorno.TYPE = lt_CIERRE_CAJA_DET_EFECT.GetString("TYPE"); if (i == 0) { status = lt_CIERRE_CAJA_DET_EFECT.GetString("TYPE"); } retorno.ID = lt_CIERRE_CAJA_DET_EFECT.GetString("ID"); retorno.NUMBER = lt_CIERRE_CAJA_DET_EFECT.GetString("NUMBER"); retorno.MESSAGE = lt_CIERRE_CAJA_DET_EFECT.GetString("MESSAGE"); retorno.LOG_NO = lt_CIERRE_CAJA_DET_EFECT.GetString("LOG_NO"); retorno.LOG_MSG_NO = lt_CIERRE_CAJA_DET_EFECT.GetString("LOG_MSG_NO"); retorno.MESSAGE_V1 = lt_CIERRE_CAJA_DET_EFECT.GetString("MESSAGE_V1"); retorno.MESSAGE_V2 = lt_CIERRE_CAJA_DET_EFECT.GetString("MESSAGE_V2"); retorno.MESSAGE_V3 = lt_CIERRE_CAJA_DET_EFECT.GetString("MESSAGE_V3"); retorno.MESSAGE_V4 = lt_CIERRE_CAJA_DET_EFECT.GetString("MESSAGE_V4"); retorno.PARAMETER = lt_CIERRE_CAJA_DET_EFECT.GetString("PARAMETER"); retorno.ROW = lt_CIERRE_CAJA_DET_EFECT.GetString("ROW"); retorno.FIELD = lt_CIERRE_CAJA_DET_EFECT.GetString("FIELD"); retorno.SYSTEM = lt_CIERRE_CAJA_DET_EFECT.GetString("SYSTEM"); T_Retorno.Add(retorno); } } } catch (Exception ex) { Console.WriteLine("{0} Exception caught.", ex); System.Windows.MessageBox.Show(ex.Message + ex.StackTrace); } //return T_Retorno; GC.Collect(); }