Skip to content

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.

  1. It waits for SAP to finish processing and looks up the ALV by its selector, waiting for it to appear up to timeout.
  2. 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.
  3. It picks the menuItem option in that menu (by default &PC, local file). If the menu doesn’t have it, it fails.
  4. 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.

ParameterTypeDefaultDescription
selectorselector—The ALV grid (GuiGridView). Ex: "wnd[0]/usr/cntlGRID1/shellcont/shell".
ParameterTypeDefaultDescription
sessionZoanSapSession—SAP session. Omit it inside the body of an SAP — Attach or SAP — Log on.
menuItemstring"&PC"Export menu item code. &PC = local file, &XXL = spreadsheet, &XXL_TXT = text. Depends on what the system has installed.
toolbarButtonstring"&MB_EXPORT"ALV toolbar menu button that opens the export menu.
timeoutnumber—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.

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).

MessageCause 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.

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: file
Log message = "Report downloaded to " + file

Use 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: hasDialog
If 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"