SAP — Export ALV grid
SAP — Export ALV grid
Section titled “SAP — Export ALV grid”Type: sap-grid-export · Package: SAP Activities v1.0.5 · Output: boolean
Triggers an ALV grid’s export: it opens its export menu and picks the option you specify, for example “local file”. It is the quick way to get all of an ALV grid’s content into a file, instead of reading it cell by cell. It is usually followed by an SAP — Save file dialog, which picks the format, sets the file path and name, and confirms.
How it works
Section titled “How it works”- It waits for SAP to finish processing and looks up the ALV by its selector, waiting for it to appear up to
timeout. - It presses the ALV toolbar menu button given in
toolbarButton(by default&MB_EXPORT, the export one). If the ALV doesn’t have that button, it fails with a message explaining it. - It picks the
menuItemoption in that menu (by default&PC, local file). If the menu doesn’t have it, it fails. - It checks whether the “Save File” dialog is open, notes it in the log and returns it as output.
What comes next depends on the option and the system. With &PC, SAP usually asks for the format first and then shows the “Save File” dialog: SAP — Save file dialog handles both.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
selector | selector | — | The ALV grid (GuiGridView). Ex: "wnd[0]/usr/cntlGRID1/shellcont/shell". |
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. |
menuItem | string | "&PC" | Export menu item code. &PC = local file, &XXL = spreadsheet, &XXL_TXT = text. Depends on what the system has installed. |
toolbarButton | string | "&MB_EXPORT" | ALV toolbar menu button that opens the export menu. |
timeout | number | — | Seconds to wait for the ALV grid 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 boolean: true if, when it finishes, the “Save File” dialog is already open (its wnd[1]/usr/ctxtDY_PATH field exists); false if the next screen is something else (for example, the format question, which SAP — Save file dialog also handles, or an option that doesn’t write a file).
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
This ALV did not answer the context button '…'. Not every program puts export on its toolbar; list the buttons it does have with sap-grid-toolbar, or export the list with sap-export-list. (…) | The ALV doesn’t have the toolbarButton. Check it with SAP — ALV toolbar. |
The export menu has no '…' entry. Each system publishes only the formats it has installed. (…) | menuItem doesn’t exist on that system. Try &PC. |
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 Export ALV Grid selector = "wnd[0]/usr/cntlGRID1/shellcont/shell" menuItem = "&PC"SAP Save File Dialog path = "C:\output\" fileName = "report.txt" format = Text with Tabs → output: fileLog message = "Report downloaded to " + fileUse the output when the chosen option might not end in the save dialog:
SAP Export ALV Grid selector = "wnd[0]/usr/cntlGRID1/shellcont/shell" menuItem = "&XXL" → output: hasDialogIf condition = hasDialog ├─ then: │ SAP Save File Dialog path = "C:\output\" fileName = "report.xlsx" → output: file └─ else: Log level = warning message = "The export did not open the save dialog"Related activities
Section titled “Related activities”- SAP — Save file dialog — finish the export with path and name.
- SAP — Export list — the equivalent for classic lists.
- SAP — ALV toolbar — discover the ALV’s buttons.