Consider the below code for educational purposes only. Avoid using RFC_READ_TABLE as it's not released by SAP - see note 382318 - FAQ|Function module RFC_READ_TABLE.
Find below a simple RFC_READ_TABLE call using the SAP .net connector 3.x
ReadTable("PR1", "MARA", "MATNR,MTART,MATKL", "MTART EQ 'HAWA'", rows);
where "PR1" - destination system
"MARA" - string, table to query
"MATNR,xxx" - string, coma separated column names. If empty "", then all table fields are retrieved.
"MTART EQ 'HAWA'" - string, WHERE clause in ABAP SQL syntax
rows - output variable, list of strings to hold the result table rows. Columns delimited by "~"
Current limitation: in the below version of the code, the filter can be only upto 72 characters long. If you need longer, I suggest to involve a word wrapping function like this one: http://bryan.reynoldslive.com/post/Wrapping-string-data.aspx
public bool ReadTable(string dest, string table, string fields, string filter, out List<string> rows) {
string[] field_names = fields.Split(",".ToCharArray());
RfcDestination destination = RfcDestinationManager.GetDestination(dest);
IRfcFunction readTable;
try {
readTable = destination.Repository.CreateFunction("BBP_RFC_READ_TABLE");
} catch (RfcBaseException ex) {
//Log.Error(String.Format("\nError in function module RFC_READ_TABLE ({0})", ex.Message));
rows = null;
return false;
}
readTable.SetValue("query_table", table);
readTable.SetValue("delimiter", "~");
IRfcTable t = readTable.GetTable("DATA");
t.Clear();
t = readTable.GetTable("FIELDS");
t.Clear();
if (field_names.Length > 0) {
t.Append(field_names.Length);
int i = 0;
foreach (string n in field_names) {
t.CurrentIndex = i++;
t.SetValue(0, n);
}
}
t = readTable.GetTable("OPTIONS");
t.Clear();
t.Append(1);
t.CurrentIndex = 0;
t.SetValue(0, filter);
//Log.Debug(string.Format("SELECT {0} FROM {1} WHERE {2}",
// fields, table, filter));
readTable.Invoke(destination);
t = readTable.GetTable("DATA");
int a = t.Count;
rows = new List<string>();
for (int i = 0; i < t.RowCount; i++) {
t.CurrentIndex = i;
rows.Add(t.GetString(0));
}
return true;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |