Now accepting guest editorial from SAP, Oracle, Workday and ServiceNow practitioners.Pitch a guide
The Sign-Off Table

Lesson 1 of 5

SAP GUI Scripting overview

11 min

Listen to this lesson

0:00 / 8:00

Classic SAP transactions still carry a large share of daily work in most SAP S/4HANA Private Edition and on-premise systems: VA01, VL02N, MIGO, FB60 and hundreds more. To automate them you need a way to drive SAP GUI for Windows from a program. SAP provides one: the SAP GUI Scripting API, an automation interface built into SAP GUI for Windows.

SAP's security guide for the interface describes its purpose in two halves. End users can automate repetitive tasks by recording and running macro-like scripts; administrators and developers can build tools for server-side application testing or client-side integration. SAP's own eCATT uses it: eCATT's SAPGUI command records transactions with UI controls and requires scripting support to be installed and active.

What the server sees

The most important fact about GUI Scripting is in the first page of SAP's security guide: from the SAP server's point of view there is no difference between SAP GUI communication generated by a script and communication generated by a user. A script therefore has exactly the rights of the user who starts it, and the same data validation rules apply. The script does not bypass authorizations, and it cannot see data the user cannot see. It can, however, act much faster than a person and run unattended, so a bad script can create bad data quickly.

  1. ScriptA test or macro calls the SAP GUI Scripting API on the client PC
  2. SAP GUI for WindowsTranslates API calls into the same screen events a user would trigger
  3. Application serverReceives normal dialog steps; checks authorizations and validations as usual
  4. ResultScreen output, messages and documents come back to SAP GUI, where the script reads them
GUI Scripting works through SAP GUI. The server treats a script like the user who runs it.
The Sign-Off Table · thesignofftable.com/academy/sap-tau-201

The object model

The API exposes SAP GUI as a tree of objects. At the top sits the application object, which is the scripting engine of the running SAP GUI. Under it are connections (one per system you are logged on to through SAP Logon), under each connection the sessions (the separate windows you open with "new session"), and under each session its windows: the main window and any popups. Each window contains areas such as the menu bar, the system and application toolbars, the title bar, the user area holding the screen fields, and the status bar. Controls such as fields, buttons, tabs, table controls, grids and trees sit inside those areas.

ApplicationThe scripting engine of the running SAP GUI; the root of the tree
Connectioncon[0], con[1]: one per open system connection, for example CMQ client 100
Sessionses[0], ses[1]: one per SAP GUI session window on that connection
Windowwnd[0] is the main window; wnd[1] and higher are popups and dialogs
Areasmenu bar, toolbars (tbar[0], tbar[1]), user area (usr), status bar (sbar)
ControlsInput fields, buttons, checkboxes, tabs, table controls, ALV grids, trees
The SAP GUI Scripting object hierarchy from application down to individual controls.
The Sign-Off Table · thesignofftable.com/academy/sap-tau-201

IDs: how a control is addressed

Every object has an ID that describes its path in this tree. A full ID looks like /app/con[0]/ses[0]/wnd[0]/usr/ctxtVBAK-AUART: application, first connection, first session, main window, user area, and then a control. The control part combines a short type prefix with the control's name. For classic screen fields the name usually comes from the ABAP Dictionary, such as VBAK-AUART for the sales document type. Where a name is not unique, an index is added in square brackets. Scripts usually call a "find by ID" method on a session object with a relative path that starts at the window, such as wnd[0]/usr/ctxtVBAK-AUART.

The short prefix in each control ID tells you the control type before you read its name.
The Sign-Off Table · thesignofftable.com/academy/sap-tau-201
Part of the IDMeaningContoso example
con[0]First open connectionCMQ, client 100
ses[0]First session on that connectionThe tester's first SAP GUI window
wnd[0] / wnd[1]Main window / first popupVA01 screen / a "save changes?" dialog
usrUser area of the windowWhere order type and sales area are entered
Type prefix + nameControl type and its technical nameAn input field for VBAK-AUART

Reading a GUI Scripting ID. Record a short script in your own system to see the exact IDs on each screen.

You do not have to work out IDs by hand. SAP GUI's script recorder writes scripts in VBScript or JScript, and a recorded script is the quickest way to see the IDs on a screen. Treat recordings as a source of IDs and a first draft, not as finished tests; later lessons explain why.

A recording is a source of IDs and a first draft; the engineer moves the IDs into reusable screen objects.
The Sign-Off Table · thesignofftable.com/academy/sap-tau-201

What would you do?

Priya's automation engineer records VA01 in CMQ and plays it back successfully, then asks whether the script could create orders that the test user would not be allowed to create manually. What is the correct answer?

Key points
  • SAP GUI Scripting is SAP's automation interface for SAP GUI for Windows; eCATT's SAPGUI command relies on it.
  • The server cannot distinguish a script from its user: same rights, same validations.
  • Object tree: application, connection, session, window, areas, controls.
  • IDs encode the path; recordings show them, but recordings are not finished tests.

Check your understanding · not graded

Lesson check

  1. 1. From the SAP server's point of view, how does script-generated SAP GUI communication differ from a user's?

  2. 2. In the ID wnd[0]/usr/ctxtVBAK-AUART, what does usr refer to?

  3. 3. What does wnd[1] usually represent?

  4. 4. Which SAP tool uses SAP GUI Scripting to record transactions with UI controls?

  5. 5. A Contoso key user runs VA01 in SAP GUI for HTML (WebGUI) in a browser. How is that screen automated?