Reading database tables

With the TableReader object it is possible to read data from SAP tables quite easily.

Simple call

To read all rows of a database table, simply call the Read() method, leaving all other parameters unchanged

Dim tr As TableReader
tr = session.GetTableReader("SFLIGHT")
tr.Read(0,0)
For Each row in tr.Rows
    Console.WriteLine(row("FLDATE").value & " " & row("CONNID").value)
    ' ...
Next

Limiting the number of rows

The parameters of the Read method can be used to limit the number of rows to be read, and to determine the starting row:

Dim tr As TableReader
tr = session.GetTableReader("SFLIGHT")    
' read 20 rows, starting with row #10
tr.Read(20,10)

Reading only some columns

To reduce the amount of transfered data and to overcome the 500 character width limit (see below), it is possible to specify the desired columns with the Fields property:

Dim tr As TableReader
tr = mySession.GetTableReader("SFLIGHT")
' read only CONNID and FLDATE
tr.Fields.Add("CONNID")
tr.Fields.Add("FLDATE")
tr.Read(0,0)

Filtering rows

With the Query property, it is possible to only read rows which meet certain criteria. The Query property consists of one or more rows (max. 72 characters per row) which together form an ABAP/Open SQL WHERE statement:

Dim tr As TableReader
tr = mySession.GetTableReader("SFLIGHT")
' read only rows where CARRID has the value 'LH'
' note that constant values must be quoted with single quotes
tr.Query.Add("CARRID EQ 'LH'")
tr.Read(0,0)

TableReader permissions

The TableReader internally uses the RFC_READ_TABLE function module, which is present in every SAP system. The user which is used in the TableReader‘s session must have the necessary permissions to call the RFC_READ_TABLE function module, and must also have S_TABU_DIS and S_TABU_CLI permissions (activity '03') for the table(s) being read.

Transfering data in raw format

As with function calls, TableReader will convert received SAP datatypes to VARIANT, as described in Parameter Conversion. If this conversion is not desired, it can be turned off with the tablereader.rawstrings option. In this case, there will be no conversion and all fields are transmitted as strings in the internal SAP format.

tr.Option("tablereader.rawstrings") = "1"

Limitations of TableReader

RFC_READ_TABLE limits the width of the columns being read to 500 characters. If your table is wider than 500 characters, you will get a DATA_BUFFER_EXCEEDED exception.

For possible workarounds for this problem please refer to KB #0007.