Skip to content

SAP — Attach

Type: sap-attach  ·  Package: SAP Activities v1.0.5  ·  Output: ZoanSapSession

Connects to an SAP session that is already open so the bot can work in it. It doesn’t log on or touch passwords: the session was opened by a person, by the company’s SSO, or by an earlier SAP — Log on. It is the simplest way to start, and it is what the Designer’s Record button generates when you record in SAP GUI.

It looks through the connections and sessions open in SAP GUI for the first one that matches the given system (system) and client (client); if you give neither, it takes the first open session. The comparison is case-insensitive.

If it doesn’t find one, the error explains the exact reason:

  • SAP GUI is not running.
  • SAP GUI is open but scripting is disabled (see Requirements).
  • SAP GUI is open but no session is logged on.
  • No session matches the filter; in that case the message lists the open sessions (as system/client) so you can see which one to ask for.

By default it makes a single attempt. With timeout, it retries every half second up to that limit: useful when the robot starts at the same time as the machine and SAP is still loading. When the limit runs out, the error is the last real reason (from the list above) followed by how long it waited.

The elementTimeout you set here travels with the session: it is how long every activity that uses it waits for its element. If you leave it empty, the timeout from the project settings applies and, if that is not set either, 30 seconds.

With body, the activities inside inherit the session. When they finish —successfully or with an error— the activity detaches without closing anything: SAP stays open as it was. Without body, it returns the session as output so you can pass it in the session parameter of other activities.

None.

ParameterTypeDefaultDescription
systemstring—System ID (DEV, PRD…). Omit it to take the first open session.
clientstring—Client, leading zeros included. Ex: "001". Omit it for any.
timeoutnumber0Seconds to wait for the session to show up. With 0 (or empty) it makes a single attempt and fails immediately. Decimals allowed.
elementTimeoutnumber30Seconds every activity waits for its element to appear. Empty uses the project settings value or, if there is none, 30. With 0 they fail on the first try, useful while debugging a selector. A negative or non-numeric value is ignored.

Activities to run with this session. They inherit the session without setting session. On leaving the body, the activity detaches and restores whatever scope session there was before (for example, that of an outer SAP — Attach).

Returns the session (ZoanSapSession) when you do not use body (or the body is empty). With body, the session is used inside and the activity does not return a value.

MessageCause and fix
The SAPGUI object was not found in the Running Object Table. SAP GUI for Windows must be running and logged on to the system.SAP Logon is not running in the robot’s Windows session. Open it and have someone (or SSO) log on, or use SAP — Log on.
SAP GUI answers but does not hand over the scripting engine. Almost always it is disabled: …Scripting is disabled on the server (sapgui/user_scripting) or on the client. See Requirements.
SAP GUI is running but no session is logged on. Log on to the system first.SAP Logon is open but has no session. Use SAP — Log on, or raise timeout if someone is logging on at that moment.
No session matches system='…' client='…'. Open: A4H/001 | PRD/100.The filter matches no session. Check system and client against the list in the message.
… Waited … s.Suffix added to any of the above when you used timeout and it ran out.

With body (the usual way):

SAP Attach system = "DEV" client = "001" timeout = 60
└─ body:
SAP Run Transaction code = "SE16"
SAP Set Text selector = "wnd[0]/usr/ctxtDATABROWSE-TABLENAME" value = "T000"
SAP Send Key key = Enter

Without body, keeping the session in a variable to pass it to other activities:

SAP Attach system = "DEV" client = "001" → output: sap
SAP Run Transaction session = sap code = "SE16"
SAP Get Text session = sap selector = "wnd[0]/titl" → output: title