The sample code is located in the ERPConnect installaltion directory in the ReadSAPTable directory
A recurrent task in daily work with SAP and .Net applications is to read directly from tables of the SAP system. You can use the ReadTable class to manage this demand.
The sample below shows how to select data from the table. The result is passed back via an easy-to-use ADO.NET table object.
In this sample we want to read material description texts, which are located in the table MAKT. So we need the two columns MATNR (material number) and MAKTX (material description).
Furthermore we want only the English texts so we have to add the WHERE statement SPRAS=’EN’. SPRAS is the column which contains the language keys.
The method Run executes the query and passes back the ADO.NET table.
Click to open C# example.
Click to open VB example.
The screenshot shows the output of the sample program.
Table Access Restrictions
Unfortunately following restrictions apply if you read tables with the ReadTable class:
- Tables that should be read from may not have any floating point number (FLTP) type of column (as in the case of e.g. the VBAK table).
- The overall width of the columns to be extracted may not exceed 512 bytes.
- Some special tables like TCURR return false values.
If anyone of these cases occur, the table call will throw an exception. To deal with this problem, it is possible to install a Z-module in the SAP system, please see chapter Installing the Z-function module.
To enable an installed Z-module, e.g. Z_XTRACT_IS_TABLE, when using the ReadTable class, use the method
Online Help: Installing the custom function module
KnowledgeBase: Transferring data packets with ReadTable class
KnowledgeBase: Get meta data of a table