SAP — Read table
SAP — Read table
Section titled “SAP — Read table”Type: sap-read-table · Package: SAP Activities v1.0.5 · Output: List<Dictionary<string,object>>
Reads an SAP table and hands it to you as a list of rows, ready to loop through with a For Each, filter or pass to another system. It works with both kinds of table SAP uses: ALV grids and the classic tables of older screens. And it scrolls on its own when needed, so it doesn’t stop at what is visible on screen.
How it works
Section titled “How it works”It waits for SAP to finish processing, looks up the control by its selector (waiting up to timeout) and reads it according to its type:
- ALV (GuiGridView). It takes the total row count from the ALV itself and reads each cell by row and column. Columns are identified by their technical name (for example
MANDT,MTEXT). If a row isn’t loaded yet, it asks the ALV to move to it and retries; if it still can’t read the cell, it leaves it empty (null). - Classic table (GuiTableControl). SAP only keeps the visible rows in memory, so the activity reads what is visible, scrolls the table one page and goes on, until it reaches the end or
maxRows. Since SAP redraws the screen on every scroll, the activity looks up the table again before reading each page, so it always reads the data of the current page. Columns are identified by the field name of each cell (orcol0,col1… if it has none). It stops at the first completely empty row, which SAP draws as padding at the end of the table.
If the control is neither (for example, a classic report list), it fails and suggests SAP — Read classic list or SAP — Export list.
All values are returned as text, exactly as SAP shows them.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
selector | selector | — | The ALV grid or classic table. Ex: "wnd[0]/usr/cntlGRID1/shellcont/shell" (ALV) or "wnd[0]/usr/tblSAPLXYZTC_ITEMS" (classic table). |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
session | ZoanSapSession | — | SAP session. Omit it inside the body of an SAP — Attach or SAP — Log on. |
maxRows | int | 1000 | Maximum rows to read. A full table can have hundreds of thousands. |
columns | string | — | Comma-separated columns to read. Ex: "MANDT,MTEXT". Empty reads them all, which is slower on a wide ALV. On an ALV these are technical field names; on a classic table, the field name of each cell. |
timeout | number | — | Seconds to wait for the control to appear. Overrides the scope’s elementTimeout. Empty uses the scope value (30 by default); 0 fails on the first try. Decimals allowed. |
Output
Section titled “Output”Returns a List<Dictionary<string,object>>: a list of rows in table order, where each row is a column → value dictionary:
[ { "MANDT": "001", "MTEXT": "Test client", "ORT01": "Sample City" }, { "MANDT": "002", "MTEXT": "Training client", "ORT01": "Sample City" }]- Values: always text, as SAP shows it. On an ALV, a cell that could not be read is
null. - Keys on an ALV: without
columns, every column in display order. Withcolumns, exactly the ones you asked for: first those that exist, in the order you wrote them, then those that don’t, with valuenull(so a misspelled column shows up instead of vanishing). - Keys on a classic table: the field name of each cell (for example
RSYST-BNAME), orcol0,col1… if the cell has no name. Withcolumns, only cells whose name is in the list; the rest don’t appear. - Edge cases: an empty table returns an empty list. On a classic table, reading stops at the first row with no value at all.
The log shows the number of rows read, never their content.
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
The component is …, not a grid. If the screen shows a classic list (labels on a character grid), use sap-read-list, or export it with sap-export-list. | The selector points to another kind of control. Use SAP — Read classic list or SAP — Export list, or fix the selector so it points to the ALV’s shell or the table’s tbl…. |
The table '…' disappeared after scrolling to row …. | After scrolling the classic table, SAP stopped showing it (the screen changed or a dialog came up). Check what message SAP left. |
Component '…' does not exist in the SAP session. Waited … s for it to appear. The current screen is … dynpro … (transaction …). … | The element did not appear in time. The message says which screen the session is on: it is almost always a different one than expected (a dialog in front, a step that didn’t happen). If the screen is slow, raise timeout. |
Plus the errors common to all activities.
Example
Section titled “Example”SAP Read Table selector = "wnd[0]/usr/cntlGRID1/shellcont/shell" columns = "MANDT,MTEXT" maxRows = 500 → output: rowsFor Each items = rows itemVariable = row └─ activities: Log message = str(row["MANDT"]) + " — " + str(row["MTEXT"])Related activities
Section titled “Related activities”- SAP — Read classic list — for report lists, which are not tables.
- SAP — Export ALV grid — get a whole ALV into a file.
- SAP — Maximize — see more rows per screen.