Skip to content

Read Tables

This section shows how to use the ReadTable class.
A recurrent task when working with SAP and .NET applications is to read directly from tables of the SAP system. The ReadTable class enables access to that data.

Read Data From Tables

To read tables from SAP using ERPConnect:

  1. Connect to the SAP system using R3Connection.
  2. Create a table object using ReadTable().
  3. Specify the name of the SAP table using TableName.
  4. Specify the columns you want to read using AddField().
  5. Optional: Specify additional parameters, e.g., WHERE Clause (WhereClause or maximum number of rows RowCount).
  6. Optional: Specify the function module that is used to read the table using SetCustomFunctionName(). The default is RFC_READ_TABLE.
  7. Read the SAP table using Run().
  8. Access the table using the Result attribute.
Table MAKT
using System;
using System.Data;
using ERPConnect;
using ERPConnect.Utils;

// Set your ERPConnect license
LIC.SetLic("xxxx");

// Open the connection to SAP
using var connection = new R3Connection(
    host: "server.acme.org",
    systemNumber: 00,
    userName: "user",
    password: "passwd",
    language: "EN",
    client: "001")
{
    Protocol = ClientProtocol.NWRFC,
};

connection.Open();

var table = new ReadTable(connection)
{
    WhereClause = "SPRAS = 'EN'",
    TableName = "MAKT",
    RowCount = 10
};

// Select columns to read
table.AddField("MATNR");
table.AddField("MAKTX");

// Specify a function module that is used to read the table
table.SetCustomFunctionName("RFC_READ_TABLE");

table.Run();

DataTable result = table.Result;
for (int i = 0; i < result.Rows.Count; i++)
{
    Console.WriteLine($"{result.Rows[i]["MATNR"]} {result.Rows[i]["MAKTX"]}");
}

Console.ReadLine();

Output:

000000000000000023 Pawan Kalyan_08
000000000000000038 Test US colleagues upd4
000000000000000043 English Check 25_01
000000000000000058 Ventilation, complete build
000000000000000059 Filter Ereteam
000000000000000068 a portable 1 ton crane
000000000000000078 Component Full Repair Service ...
000000000000000088 AS-100 T-shirt XL
000000000000000089 AS-100 T-shirt
000000000000000098 PCB Subassembly

Data Type Mapping

The following table shows the data type mapping between ABAP / RFC and .NET.

ABAP ABAP Dictionary ERPConnect .NET Remarks
b INT1 RFCTYPE INT1 System Byte
s INT2, PREC RFCTYPE INT2 System Int16
i INT4 RFCTYPE INT System Int32
p DEC, CURR, QUAN RFCTYPE BCD System Decimal Max. supported length is 28 digits
decfloat16 DF16_DEC, DF16_RAW, DF16_SCL RFCTYPE BYTE System Byte[] No ReadTable support
decfloat34 DF34_DEC, DF34_RAW, DF34_SCL RFCTYPE BYTE System Byte[] No ReadTable support
f FLTP RFCTYPE FLOAT System Double
c CUKY, UNIT, CHAR, LCHR, CLNT, LANG RFCTYPE CHAR System String
string STRING RFCTYPE STRING System String No ReadTable support
n NUMC, ACCP RFCTYPE NUM System String Only characters 0_9 ACCP format is YYYYMM
d DATS RFCTYPE DATE System String Format is YYYYMM
t TIMS RFCTYPE TIME System String Format is HHMMSS
x RAW, LRAW RFCTYPE BYTE System Byte[]
xstring RAWSTRING RFCTYPE XSTRING System Byte[] No ReadTable support


Last update: June 25, 2026