--- name: sap-ui-automation-cli description: Drives SAP screens from a shell using the sap-ui-automation CLI. Use when the user requests terminal commands or needs to perform a live SAP task through the CLI because MCP tools are unavailable. --- # Driving SAP screens with the `sap-ui-automation` CLI `sap-ui-automation` works in the SAP sessions the user has open, as that user and under their authorisations. It never logs on: with no session open, ask the user to open SAP. `npx -y sap-ui-automation ` is the same program. `look` prints a few short lines (header, status bar) and the path of a file with the whole screen. `act`, `okcode` and `open` print their whole answer: what ran, then the new screen, or only the lines that changed. ``` $ sap-ui-automation act set ctxtVBAK-AUART OR set ctxtVBAK-AUART CHANGED 1 of 48 lines on VA01 · "Create Standard Order: Overview" (same screen; sap_look shows all of it): ~ ctxtVBAK-AUART field Order Type = "OR" (edit) screen: .sap-gui/screens/7-act.txt ``` Read the printed lines. Open the file only when you need the screen: to find an id, read values or see a list. ## One screen, one command 1. **Identify the target.** List sessions with `sap-ui-automation sessions`, then inspect the intended screen using `sap-ui-automation look --session --print`. Check system, client, user, transaction and any popup. If the target disappears, list sessions again and verify the new id. Keep existing work intact. To start another transaction use a fresh session (`new-session VA03`). Use `/n` only in a known clean session or with permission to discard its contents. 2. **Send the whole screen in one `act`**: the fields, then the key that submits them, as one JSON list in single quotes. ```sh sap-ui-automation act --session '' '[{"do":"set","id":"ctxtVBAK-AUART","value":"OR"},{"do":"set","id":"ctxtVBAK-VKORG","value":"1000"},{"do":"key","key":0}]' ``` 3. **Read the answer, not the screen again.** It prints what ran, then the new screen or `CHANGED n of m lines` (`~` changed, `+` new, `-` gone, `=` context). `Ran k of n actions. Stopped: ...` means the list ended early: go on from the screen it shows with the actions that did not run. 4. **Read the `STATUS` line.** `E`: inspect the reported error and correct the field it names. `W`: Enter accepts it, when the warning is acceptable for the task. `A`: an abort. Success is the status bar line (`sbar status S: ...`). 5. **Report** what you read or saved, with the document number from the status bar. A list ends at the first surprise: a failure, a refusal, a popup, an E/W/A status, or another screen (unless the next action's id is on it and it does not write). `okcode /n` and `open` go on into the screen they open. To go on through a screen you know comes, add `"expect":{"screen":"4001"}` to the step (`{"screen":"*"}`: any screen). A write on a screen the list reached after you sent it does not run: read that screen, then send the write, or add `"unseen":true` when you know it. A `look` right after an `act`, on the same screen, prints only `Unchanged since your last sap_act` and a file containing that session’s complete current view. ## Commands ``` sap-ui-automation sessions the open sessions; * marks the active one sap-ui-automation use make one the active session sap-ui-automation look [--full] [--diff] the screen (file); --print prints it sap-ui-automation look --id [--rows 100-150] [--cols VBELN,NETWR] one control whole, a range of rows sap-ui-automation look --id mbar | --id 'menu[2]' the menus and their entries; one menu whole sap-ui-automation act '' [--full] one action (below); '[...]' one screen's actions (20 at most) sap-ui-automation okcode /nVA03 same as act okcode: starts a transaction (no Enter after it) sap-ui-automation open '#Intent-action' same as act open: a Fiori launchpad app sap-ui-automation screenshot a PNG (charts, HTML panels the text cannot show) sap-ui-automation record start "" | assert '' | stop | list | status a repeatable test sap-ui-automation replay run a recorded test again, no model sap-ui-automation daemon status | stop ``` `look`, `act`, `okcode`, `open`, `screenshot` and `record` take `--session `. Exit codes: 0 done, 1 error or refused (the message is on stderr), 2 usage. ## Actions Shorthands for the common ones: `act set `, `press `, `key `, `select `, `check true|false`, `combo [key]`, `f4 `, `dblclick `, `scroll `. Everything else is JSON: ``` {"do":"set","id":"ctxtVBAK-AUART","value":"OR"} type into a field {"do":"set","id":"","row":0,"col":"SEATSOCC","value":"12"} a cell of an input grid {"do":"press","id":"btn[8]"} a button (btn[N] is function key N) {"do":"key","key":0} 0 Enter, 3 Back, 4 F4, 8 F8, 11 Save, 12 Cancel {"do":"select","id":"tabpT\\08"} tab, radio button, menu entry, list item {"do":"select","id":"","row":2} select a row {"do":"check","id":"...","value":true} checkbox {"do":"combo","id":"...","key":"PROG"} dropdown entry; without key: lists the entries {"do":"okcode","value":"/nVA03"} the command field (the only way to type into it) {"do":"f4","id":"..."} value help {"do":"grid","id":"...","row":0,"col":"VBELN","how":"double|select|cell"} {"do":"tree","id":"...","node":"","how":"double|select|expand|collapse"} {"do":"toolbar","id":"...","button":""} {"do":"scroll","id":"...","to":120} a row from 0, or next/prev/first/last {"do":"open","app":"#SalesOrder-manage"} Fiori: a launchpad app by its intent ``` ## How SAP screens behave - **Fields take effect on Enter.** `set` only types. Fill the screen, then `act key 0` once. - **Do not guess codes**: open the value help (`act f4 `) and pick. - **`okcode /n` drops unsaved input** in the current transaction. - **Popups come first.** A `WINDOW wnd[1]` blocks the screen below until it is answered. - **A list shows the rows on screen and the total.** Never conclude that an entry is missing from the rows on screen: scroll, or `look --id --rows 100-150`. A wide grid shows its first 15 columns and names the others: read them with `--cols`. - **Numbers follow the user's notation.** Trust the `NUMBERS` line: with `NUMBERS 1.234,56`, "1.000" is one thousand and "312,000" is 312. When it says `NUMBERS unknown`, find the notation first (an amount with decimals on another screen, or the user's defaults in SU3). - **Leaving without saving:** `act key 3` (Back) or `act key 12` (Cancel). When SAP asks whether to save, answer No unless the user asked to save. ## Several sessions `sap-ui-automation new-session VA03 --session ` opens a fresh Web GUI tab in launched or attached Chrome, or another desktop SAP window, and that session becomes the active one. Send it on its own: inside a list it is refused. Then pass `--session ` on every command instead of relying on the active session. A Web GUI session that `sap-ui-automation sessions` marks "not verified" is still loading or shows a popup: list again before you work in it. If SAP reports a session limit, dismiss its information popup. In Web GUI, open the system’s normal Web GUI start URL in a separate tab. List sessions, verify the new tab and use its ID. Repeating `/o` or closing another agent’s tab can disrupt work. On desktop, use an available session or another logon. ## Writing to SAP Saving, posting, releasing and deleting change the system for real. The user's `SAP_WRITE` setting decides what happens: - **on** (default): the action runs, and the user's approval of your command is the check. Only perform a save the user requested. Afterwards say what you saved, with the document number. - **off** (read-only): the action is refused. Tell the user what you would have saved and whether the document may be locked. Discard only your own disposable input or edits the user authorized you to discard. Save with `sap-ui-automation act key 11` on every surface (in Web GUI the CLI presses the toolbar's Save button for it). Never work around the setting, for example with a save code in the command field. The `SAP_*` settings are the user's decision: never set, export or change them yourself (no `SAP_WRITE=on` in front of a command), not even to repeat what is already set. Report a refused write to the user, who decides. The CLI keeps a background daemon per directory, started on the first call with that call's `SAP_*` settings. A call with other settings is refused. Run `sap-ui-automation daemon stop` only when the user asked for the new settings.