Working around limitations of TableReader / RFC_READ_TABLE Symptoms
The TableReader component of RfcConnector uses the SAP-provided RFC_READ_TABLE function module internally, which allows to read SAP tables without modifying the SAP system.
Unfortunately, RFC_READ_TABLE has some limitations, namely
- the combined length of the retrieved columns must not exceed 512 characters
- when working with columns of type FLOAT, the module may cause an ABAP exception ASSIGN_BASE_WRONG_ALIGNMENT
Solution
There are three options to work around these limitations:
- Limit the columns to be retrieved
- Use BBP_RFC_READ_TABLE to retrieve the table content
- Use a custom function module to retrieve the table content
Option 1: Limit the columns to be retrieved
Advantages
No need for modification of the SAP system
Disadvantages
Not suitable or cumbersome if you need the content of all columns
Procedure
Use TableReader.Fields to limit the retrieved columns:
tr = s.GetTableReader("some_table") tr.Fields.Add("COLUMN1") tr.Fields.Add("COLUMN2") ' ... tr.Read(0,0)
Option 2: Use BBP_RFC_READ_TABLE to retrieve the table content
Prerequisites
BBP_RFC_READ_TABLE
must be present in your SAP system (use transaction SE37
to check)
Advantages
No need for modification of the SAP system
Disadvantages
BBP_RFC_READ_TABLE
does only solve the FLOAT problem, but does not increase the 512 character limit
Procedure
Set the tablereader.transportcall
option to BBP_RFC_READ_TABLE
:
tr = s.GetTableReader("some_table") tr.Option("tablereader.transportcall") = "BBP_RFC_READ_TABLE" tr.Read(0,0)
Option 3: Use a custom function module to retrieve table content
Advantages
Solves both character limit and FLOAT problem
Disadvantages
Requires development user, and creation of a custom function module
Procedure
1. Use transaction SE37 to copy the module RFC_READ_TABLE
to a custom name, for example ZRFC_READ_TABLE
2. Use transaction SE11
to copy the structure TAB512
to a custom name, for example ZTAB4096
3. Modify the WA
member of ZTAB4096
to component type CHAR
with length 4096
4. Save and activate the new structure with Ctrl+F3
5. Open the newly created ZRFC_READ_TABLE
and change the type of the TABLES
parameter DATA
to ZTAB4096
6. In the Source code tab, locate the statement ASSIGN WORK TO CASTING TYPE (QUERY_TABLE)
(around line 165) and replace it with the following code:
DATA: BEGIN OF WORK, BUFFER(30000), END OF WORK. FIELD-SYMBOLS: <WA> TYPE ANY, <COMP> TYPE ANY. " --- begin of modification " ASSIGN WORK TO <WA> CASTING TYPE (QUERY_TABLE). DATA: tab_ref TYPE REF TO data. CREATE DATA tab_ref TYPE (query_table). ASSIGN tab_ref->* TO <wa>. " --- end of modification IF ROWCOUNT > 0. ROWCOUNT = ROWCOUNT + ROWSKIPS. ENDIF. SELECT * FROM (QUERY_TABLE) INTO <WA> WHERE (OPTIONS).
7. Save and activate the new function module with Ctrl+F3
8. Set the tablereader.transportcall option to the name of your custom module:
tr = s.GetTableReader("some_table") tr.Option("tablereader.transportcall") = "ZRFC_READ_TABLE" tr.Read(0,0)