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.
Note: The RFC_READ_TABLE function module for table extractions is not suitable for mass data extraction, see Table Restrictions.
Reading Data From Tables #
The following sample shows how to use the ReadTable class to select data from the SAP table MAKT and how to process the ADO.NET result table object.
- This sample reads the material description texts of the table MAKT. For this the columns MATNR (material number) and MAKTX (material text) are needed.
- To make sure only the English language texts are read, add a corresponding WHERE statement
SPRAS='EN'
(SPRAS is the column that contains the language keys).
static void Main(string[] args)
{
using (R3Connection con = new R3Connection("SAPServer", 00, "SAPUser", "Password", "EN", "800"))
{
ERPConnect.LIC.SetLic("LicenseNumber");
con.Open(false);
ReadTable table = new ReadTable(con);
table.AddField("MATNR");
table.AddField("MAKTX");
table.WhereClause = "SPRAS = 'EN' AND MATNR LIKE '%23'";
table.TableName = "MAKT";
table.RowCount = 10;
table.Run();
DataTable resulttable = table.Result;
for (int i = 0; i < resulttable.Rows.Count; i++)
{
Console.WriteLine(
resulttable.Rows[i]["MATNR"].ToString() + " " +
resulttable.Rows[i]["MAKTX"].ToString());
}
Console.ReadLine();
}
}
The screenshot below shows the output of the sample program.
Table Restrictions #
When extracting tables from older SAP releases you may encounter several restrictions when using the SAP standard function module (RFC_READ_TABLE):
- The overall length of all columns to be extracted must not exceed 512 bytes.
- It is not possible to extract data from tables that contain one or more columns of the data type f (FLTP, floating point), DEC (decimal, e.g. for percentage) or x (RAW, LRAW).
- Poor extraction performance with larger tables.
Warning! Error while converting value ‘*.0’ of row 1530, column 3
The SAP standard module RFC_READ_TABLE for table extraction can only extract the ABAP data type DEC to a limited extent. This leads to the mentioned example error during extraction.