public SapResult <List <FunctionModel> > GetFunctions(string functionName) { var result = new SapResult <List <FunctionModel> >(); try { using (var conn = new SapConnection(_destinationName)) { // NOTE: https://www.sapdatasheet.org/abap/func/rfc_function_search.html var rfcFunction = conn.Repository.CreateFunction("RFC_FUNCTION_SEARCH"); rfcFunction.SetValue("FUNCNAME", functionName); rfcFunction.SetValue("LANGUAGE", "KO"); rfcFunction.Invoke(conn.Destination); var functions = rfcFunction.GetTable("FUNCTIONS"); foreach (var function in functions) { result.Export.Add(new FunctionModel { Name = function.GetString("FUNCNAME"), Group = function.GetString("GROUPNAME"), Application = function.GetString("APPL"), RemoteHost = function.GetString("HOST"), ShortText = function.GetString("STEXT") }); } } } catch (Exception ex) { result.AddError(ex); } return(result); }
public SapResult <DataTable> GetTable(string tableName, int rowSkips = 0, int rowCount = 0) { var result = new SapResult <DataTable>(); try { using (var conn = new SapConnection(_destinationName)) { // NOTE: https://www.sapdatasheet.org/abap/func/rfc_read_table.html var rfcFunction = conn.Repository.CreateFunction("RFC_READ_TABLE"); rfcFunction.SetValue("QUERY_TABLE", tableName); rfcFunction.SetValue("DELIMITER", DATA_SEPARATOR); rfcFunction.SetValue("ROWSKIPS", rowSkips); rfcFunction.SetValue("ROWCOUNT", rowCount); rfcFunction.Invoke(conn.Destination); var fields = rfcFunction.GetTable("FIELDS"); var datas = rfcFunction.GetTable("DATA"); var table = ToTable(tableName, fields, datas); result.Export = table; } } catch (Exception ex) { result.AddError(ex); } return(result); }
public SapResult <List <ParameterModel> > GetFunctionParameters(string functionName) { var result = new SapResult <List <ParameterModel> >(); try { using (var conn = new SapConnection(_destinationName)) { var parameters = new List <ParameterModel>(); var meta = conn.Repository.GetFunctionMetadata(functionName); for (int i = 0; i < meta.ParameterCount; i++) { StructureModel structureModel = null; if (meta[i].DataType == RfcDataType.STRUCTURE) { string structureName = meta[i].ValueMetadataAsStructureMetadata.Name; structureModel = LoadStructureMetadata(conn.Repository, structureName); } else if (meta[i].DataType == RfcDataType.TABLE) { string structureName = meta[i].ValueMetadataAsTableMetadata.LineType.Name; structureModel = LoadStructureMetadata(conn.Repository, structureName); } var parameter = new ParameterModel() { Name = meta[i].Name, DataType = meta[i].DataType.ToString(), Direction = meta[i].Direction.ToString(), DefaultValue = meta[i].DefaultValue, Optional = meta[i].Optional, Documentation = meta[i].Documentation, Structure = structureModel }; parameters.Add(parameter); } // 정렬순서 var sortOrder = new List <string>() { "IMPORT", "EXPORT", "CHANGING", "TABLES" }; result.Export = parameters.OrderBy(x => sortOrder.IndexOf(x.Direction)).ToList(); } } catch (Exception ex) { result.AddError(ex); } return(result); }