Currently Being Moderated

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:


        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 = readTable.GetTable("FIELDS");
            if (field_names.Length > 0) {
                int i = 0;
                foreach (string n in field_names) {
                    t.CurrentIndex = i++;
                    t.SetValue(0, n);
            t = readTable.GetTable("OPTIONS");
            t.CurrentIndex = 0;
            t.SetValue(0, filter);
            //Log.Debug(string.Format("SELECT {0} FROM {1} WHERE {2}",
            //    fields, table, filter));
            t = readTable.GetTable("DATA");
            int a = t.Count; 
            rows = new List<string>();
            for (int i = 0; i < t.RowCount; i++) {
                t.CurrentIndex = i;
            return true;



Filter Blog

By author: By date:
By tag: