
📎 This article includes 1 downloadable practice file ↓
Real automation runs the same report for several company codes or periods, exports each, and tells you what happened.
Loop over inputs
Put company codes in A2:A10 and loop: for each, set the field, execute, export, and write a status in column B.
Exports
Record the export once (List › Export › Spreadsheet, or the ALV export button), then paste those lines into the loop with the file name built from the company code: "C:\Reports\FBL1N_" & cc & ".xlsx".
Check what happened
msg = session.findById("wnd[0]/sbar").Text ' status bar
If session.Children.Count > 1 Then ' a popup window opened
session.findById("wnd[1]/tbar[0]/btn[0]").press ' e.g. confirm (check which button!)
End If
Where people go wrong
| Problem | Fix |
|---|---|
| Export dialog differs between reports | Record the export for each report |
| Excel file already open | Close or use unique names |
That’s the SAP GUI scripting course. Next: SAP basics.
Use SAP GUI scripting only where your company allows it, on a test/quality system first, and never to bypass authorisations. Examples use standard transactions and made-up data.
Practice
Import the module, list a few company codes and adapt the export lines from your own recording.
📎 Practice files for this article
- 💾Lesson 5 scriptExample script with comments; adjust transaction fields to your system. Test in a non-production client.⬇ BAS · 979 B
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.
Stuck on a step? Ask a question and the AI answers using this article.