public responce_ZMOV_10000 sapRun(request_ZMOV_10000 import) { RfcDestination configSap = RfcDestinationManager.GetDestination("SCLEM"); RfcRepository SapRfcRepository = configSap.Repository; IRfcFunction rfcFunction = SapRfcRepository.CreateFunction("ZMOV_10000"); rfcFunction.SetValue("CHARG", import.CHARG); rfcFunction.SetValue("MATNR", import.MATNR); rfcFunction.Invoke(configSap); string aa = rfcFunction.ToString(); responce_ZMOV_10000 res = new responce_ZMOV_10000(); IRfcTable rfcTable_CHAR_OF_BATCH = rfcFunction.GetTable("CHAR_OF_BATCH"); res.CHAR_OF_BATCH = new ZMOV_10000_CHAR_OF_BATCH[rfcTable_CHAR_OF_BATCH.RowCount]; int i_CHAR_OF_BATCH = 0; foreach (IRfcStructure row in rfcTable_CHAR_OF_BATCH) { ZMOV_10000_CHAR_OF_BATCH datoTabla = new ZMOV_10000_CHAR_OF_BATCH(); datoTabla.ATNAM = row.GetString("ATNAM"); datoTabla.ATWTB = row.GetString("ATWTB"); datoTabla.XDELETE = row.GetString("XDELETE"); datoTabla.CHAR_NOT_VALID = row.GetString("CHAR_NOT_VALID"); datoTabla.ATINN = row.GetInt("ATINN"); datoTabla.ATWTB_LONG = row.GetString("ATWTB_LONG"); res.CHAR_OF_BATCH[i_CHAR_OF_BATCH] = datoTabla; ++i_CHAR_OF_BATCH; } return(res); }
public override RfcPreparedFunction Prepare() { try { this.function = this.repository.CreateFunction(this.FunctionName); foreach (var parameter in this.Parameters) { int idx = this.function.Metadata.TryNameToIndex(parameter.Name); if (idx == -1) throw new UnknownRfcParameterException(parameter.Name, this.FunctionName); RfcDataType pType = this.function.Metadata[idx].DataType; switch (pType) { case RfcDataType.STRUCTURE: RfcStructureMetadata structureMetadata = this.function.GetStructure(idx).Metadata; IRfcStructure structure = this.structureMapper.CreateStructure(structureMetadata, parameter.Value); this.function.SetValue(parameter.Name, structure); break; case RfcDataType.TABLE: RfcTableMetadata tableMetadata = this.function.GetTable(idx).Metadata; IRfcTable table = this.structureMapper.CreateTable(tableMetadata, parameter.Value); this.function.SetValue(parameter.Name, table); break; default: object formattedValue = this.structureMapper.ToRemoteValue(this.function.Metadata[idx].GetAbapDataType(), parameter.Value); this.function.SetValue(parameter.Name, formattedValue); break; } } return this; } catch (Exception ex) { if (ex.GetBaseException() is SharpRfcException) throw ex; throw new SharpRfcCallException(ex.Message, function == null ? "null" : function.ToString(), ex); } }
public string conSAP2(string funcionCall, List <ParamsCallSAP> listParam, List <TablasCallSAP> listTabls) { this.mensaje = ""; try //Establece conexion con SAP { RfcConfigParameters rfc = GetParameters(); //a la configuracion se le pasan los parametros de conexion RfcDestination rfcDest = null; rfcDest = RfcDestinationManager.GetDestination(rfc); RfcRepository repo = rfcDest.Repository; //Crea repositorio para la función IRfcFunction conexion = repo.CreateFunction(funcionCall); for (int i = 0; i < listParam.Count; i++) //save_settings.SetValue("BUKRS", ""); { switch (listParam[i].TipVar) //S-tring B-oolean Y-byte D-ecimal { case "S": conexion.SetValue(listParam[i].NameVar, listParam[i].ValVar); break; case "B": conexion.SetValue(listParam[i].NameVar, listParam[i].ValBool); break; case "Y": conexion.SetValue(listParam[i].NameVar, listParam[i].ValVarb); break; case "D": conexion.SetValue(listParam[i].NameVar, listParam[i].ValVard); break; //default: // ; // break; } } for (int u = 0; u < listTabls.Count; u++) { IRfcTable Tabls = conexion.GetTable(listTabls[u].tablaVar); //IRfcTable PROVEEDOR_TB = conexion.GetTable("PROVEEDOR_TB"); for (int z = 0; z < listTabls[u].CamposVar.Count; z++) { Tabls.Append(); //PROVEEDOR_TB.Append(); switch (listTabls[u].CamposVar[z].TipVar) //S-tring B-oolean Y-byte D-ecimal { case "S": Tabls.SetValue(listTabls[u].CamposVar[z].NameVar, listTabls[u].CamposVar[z].ValVar); //PROVEEDOR_TB.SetValue("LIFNR", "1000037"); break; case "B": Tabls.SetValue(listTabls[u].CamposVar[z].NameVar, listTabls[u].CamposVar[z].ValBool); break; case "Y": Tabls.SetValue(listTabls[u].CamposVar[z].NameVar, listTabls[u].CamposVar[z].ValVarb); break; case "D": Tabls.SetValue(listTabls[u].CamposVar[z].NameVar, listTabls[u].CamposVar[z].ValVard); break; } } } conexion.Invoke(rfcDest); //Se ejecuta la consulta return(conexion.ToString()); } catch (RfcCommunicationException xe) { mensaje = xe.ToString(); //return IRfcFunction; return(mensaje); } catch (RfcLogonException xe) // user could not logon... { mensaje = xe.ToString(); return(mensaje); } catch (RfcAbapRuntimeException xe) // serious problem on ABAP system side.. { mensaje = xe.ToString(); return(mensaje); } catch (RfcAbapBaseException xe) // The function module returned an ABAP exception, an ABAP message or an ABAP class-based exception... { mensaje = xe.ToString(); return(mensaje); } catch (Exception xe) { mensaje = xe.ToString(); return(mensaje); } }