SAP — Run transaction
SAP — Run transaction
Section titled “SAP — Run transaction”Type: sap-run-transaction · Package: SAP Activities v1.0.5
Opens an SAP transaction by its code, just like typing SE16 in the command field and pressing Enter. It is the usual step to reach the screen you are going to automate, without depending on menus or favorites. It also checks that the transaction really opened, something SAP doesn’t always make clear.
How it works
Section titled “How it works”- It waits for SAP to finish processing and looks for the command field (
wnd[0]/tbar[0]/okcd). If it can’t find it, it fails: almost always because a modal window is in front; close it first with SAP — Close modal. - It types the code with the
/nprefix (replaces the current transaction) or/oif you turn onnewWindow(opens it in a new mode), and presses Enter. If you type/nor/oat the start yourself, it is kept. Codes with a namespace, such as/SCWM/MON, also get their prefix (/n/SCWM/MON), so you write them just as they appear in SAP. Other command-field commands starting with/(for example/*SE16) are typed as is. - It checks the result:
- If the status bar shows a message of type E or A, the activity fails with SAP’s text.
- If the session is still on the same transaction as before and SAP left a message, the activity fails saying the transaction didn’t open. This catches cases such as “Transaction XXXX does not exist” or missing authorization, which SAP announces with a message of type S (success).
- Any other message is written to the log.
With newWindow on, the transaction opens in another mode and the current session doesn’t change, so step 3’s check is skipped in that case.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
code | string | — | Transaction code, without the /n prefix. Ex: "SE16", "/SCWM/MON". If you type /n or /o at the start yourself, it is kept. It also accepts parameters after the code (anything after the first space is ignored by the check). |
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. |
newWindow | bool | false | Open it in a new SAP mode (/o) instead of replacing the current one (/n). Also accepts an expression that returns true or false. |
Output
Section titled “Output”This activity does not return a value. It logs the transaction it opened (Transaction … opened.) and, if SAP left a notice in the status bar, its type and code.
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
Transaction '…' did not open: the session is still on '…'. SAP said [S …]: … | The code doesn’t exist or the user lacks authorization: SAP announces it with a type S message and the session stays where it was. Check the code and the user’s permissions. |
SAP replied [E …]: … | SAP rejected the command with an error. |
The command field (wnd[0]/tbar[0]/okcd) was not found. Is a modal window open in front? Close it with sap-close-modal. | A dialog covers the main window. Close it first with SAP — Close modal. |
'code' is required. | code arrived empty. |
Plus the errors common to all activities.
Example
Section titled “Example”SAP Attach system = "DEV" client = "001" └─ body: SAP Run Transaction code = "SE16" SAP Set Text selector = "wnd[0]/usr/ctxtDATABROWSE-TABLENAME" value = "T000" SAP Send Key key = EnterRelated activities
Section titled “Related activities”- SAP — Attach and SAP — Log on — get the session.
- SAP — Close modal — clear a dialog that blocks the command field.
- SAP — Press toolbar button — execute the selection screen.