SAP package guide
Version 2.17.1. Installed versions can differ. Examples are illustrative and not tested.
Prerequisites
Use Windows with SAP GUI already open. The package does not start it or use a browser. Turn on SAP GUI Scripting in the client and on the server, for this account. A missing scripting setup or registration, missing connection or server error fails the step.
Start with Connect. Later steps use its Session name within this Run. Use another name for another connection. Disconnect removes the local name; it does not sign out, close the connection or close SAP GUI.
Get each Field path from the SAP scripting tools for your actual screen. It is a scripting ID, not a title, CSS selector or position on screen. Replace these sample IDs with IDs from a test screen; the package does not create them.
| Control | Sample ID | Sample content |
|---|---|---|
| Text field | wnd[0]/usr/txtSAMPLE | Sample |
| Checkbox | wnd[0]/usr/chkSAMPLE | Not checked |
| Radio option | wnd[0]/usr/radSAMPLE | Not selected |
| Button | wnd[0]/tbar[0]/btn[0] | A button safe to click |
| Combo | wnd[0]/usr/cmbSAMPLE | Alpha, key A1; two entries |
| Tree | wnd[0]/usr/cntlTREE/shellcont/shell | A node named Alpha |
| Table | wnd[0]/usr/cntlGRID/shellcont/shell | Columns Code and Text; rows A1/Alpha and B2/Beta |
| Container | wnd[0]/usr/cntlSAMPLE | Children First and Second, with text Alpha and Beta |
Table rows, columns, item numbers and cell positions start at 1. Menu paths use SAP's own numbers, usually from 0. Menu, tree and item text must match exactly, with case. A control must support the action, or the step fails. The effect depends on the active SAP screen. Use test data for clicks, keys and edits. Create samples before a CSV export. Relative paths start in the Run working folder.
Shared fields
Each example, except Connect and Disconnect, starts with Connect Default and the test screen above.
- Select (
select):TEXTpicks exact, case-sensitive visible item or tree-node text.INDEXpicks its number, from1, in the item collection or tree key list. - Item text (
itemByText): used only withTEXT. The first match is used, for exampleAlpha. - Item number (
itemByIndex): used only withINDEX. A whole number, at least1, that exists in the collection. - Row (
row) and Column (column): a number from1that exists in the table. Set table cell text ignores them withTEXT.
Session and control
All actions use Session name. All except Connect, Disconnect and Send virtual key also use Field path.
| ID | Field | Type; default; requirement | Value |
|---|---|---|---|
session | Session name | Stringdefault DefaultOptional. | Connect gives the connection this local name. Later steps use it. It is not an account or server. |
field | Field path | Stringdefault emptyRequired. | The exact scripting ID of the control. Spaces at the ends are removed. The control must exist and support this action. |
Actions
This package has no conditions.
Check/uncheck checkbox (sapCheckboxActions)
Check, uncheck or reverse a checkbox.
Inputs
Also uses the session and control fields.
| ID | Field | Type; default; requirement | Value |
|---|---|---|---|
action | Action | Checkboxdefault CheckOptional. | Check checks it, Uncheck clears it and Toggle reverses it. |
Outputs
None.
Example
Set Field path=wnd[0]/usr/chkSAMPLE, Action=Check.
Expected result
The checkbox is checked. A missing control or one that cannot be checked fails.
Click (sapClick)
Clicks a button. On a grid, clicks the current cell.
Inputs
Also uses the session and control fields.
Outputs
None.
Example
Set Field path=wnd[0]/tbar[0]/btn[0] on the disposable screen.
Expected result
The button or current grid cell is clicked. The screen sets the effect. An unsupported control or a SAP error fails.
Click menu (sapClickMenu)
Select a nested SAP menu by exact names or SAP menu indexes.
Inputs
Also uses the session and control fields.
| ID | Field | Type; default; requirement | Value |
|---|---|---|---|
select | Select | Menudefault NAMEOptional. | NAME selects a menu by exact visible text segments. INDEX builds a scripting path from indexPath and selects that menu directly. Choices: NAME, INDEX. |
name | namePath | Stringdefault emptyOptional. | For Select=NAME, enter a path such as System > Status or System/. Segments are trimmed and compared exactly, with case sensitivity. INDEX ignores this input. |
index | indexPath | Stringdefault emptyOptional. | For Select=INDEX, enter SAP menu indexes such as 0/. The action extracts digit groups and appends menu[0]/ to Field path. These are SAP indexes, not the 1-based table indexes. |
Outputs
None.
Example
With a test menu path System > Status, set Field path=wnd[0]/mbar, Select=NAME, namePath=System > Status. Alternatively use Select=INDEX and the actual indexPath, for example 0/2.
Expected result
The last matching menu is selected. The number example gives wnd[0]/mbar/menu[0]/menu[2]. Missing names, no number or a missing menu fails.
Connect (sapConnect)
Use or open a SAP GUI session and give it a local name.
Inputs
| ID | Field | Type; default; requirement | Value |
|---|---|---|---|
session | Session name | Stringdefault DefaultOptional. | A name for this connection in this Run. |
connection | Select connection type | Connectiondefault AutomaticOptional. | Automatic uses the first session of the first connection, already signed in. SAP_ opens the named SAP Logon connection with working SSO. SAP_ opens it and fills Client, User name, Password and Language. |
sap | Name | Stringdefault emptyOptional. | For SAP_SSO, enter the exact configured SAP Logon connection name, for example SAP Training. Required in that mode. Ignored by Automatic and SAP_GUI. |
sap | Name | Stringdefault emptyOptional. | For SAP_GUI, enter the exact configured SAP Logon connection name, for example SAP Training. Required in that mode. It is not a hostname. |
client | Client | Stringdefault emptyOptional. | For SAP_GUI, enter one to three digits, for example 100. Other connection modes ignore it. |
secure | User name | Credentialdefault emptyOptional. | For SAP_GUI, bind a Credential with a nonempty username for the test account. Its password part is ignored in this field. |
secure | Password | Credentialdefault emptyOptional. | For SAP_GUI, bind a Credential with the nonempty account password. Its username part is ignored in this field. |
language | Language | Stringdefault emptyOptional. | For SAP_GUI enter exactly two letters, for example EN. Other modes ignore it. |
Outputs
None.
Example
Sign into a test connection in SAP GUI. Set Session name=Default, Select connection type=Automatic. For a new login, use SAP_GUI, Name=SAP Training, Client=100, Language=EN and Credential variables for the test account.
Expected result
The first session is available as Default. SAP_GUI fills the login screen and presses Enter; later dialogs can still need handling. A non-Windows system or missing SAP scripting fails.
Disconnect (sapDisconnect)
Release the session and remove its local name. It does not sign out, close the connection or close SAP GUI.
Inputs
| ID | Field | Type; default; requirement | Value |
|---|---|---|---|
session | Session name | Stringdefault DefaultOptional. | The name given in Connect. |
Outputs
None.
Example
After the sample actions set Session name=Default.
Expected result
The local name is removed; SAP stays open and signed in. Later steps with Default fail until Connect runs again. An unknown name fails Disconnect.
Double click (sapDoubleClick)
Double-clicks a control. On a grid, double-clicks the current cell.
Inputs
Also uses the session and control fields.
Outputs
None.
Example
Select a disposable sample row first. Set Field path=wnd[0]/usr/cntlGRID/shellcont/shell.
Expected result
The selected control or current grid cell receives a double click. This action does not choose a row itself. An unsupported control fails.
Expand (sapExpand)
Expand one node in a SAP tree.
Inputs
Also uses the session and control fields.
| ID | Field | Type; default; requirement | Value |
|---|---|---|---|
select | Select | Itemdefault TEXTOptional. | Shared. |
item | itemByText | Stringdefault emptyOptional. | Shared. |
item | itemByIndex | Numberdefault 1Optional. | Shared. |
Outputs
None.
Example
Prepare a node with text Alpha. Set Field path=wnd[0]/usr/cntlTREE/shellcont/shell, Select=TEXT, itemByText=Alpha.
Expected result
The first exact Alpha node opens. INDEX=1 uses the first key in the tree key list. Missing text or a bad number fails.
Export table (sapExportTable)
Read all table cells into a Table and optionally write CSV.
Inputs
Also uses the session and control fields.
| ID | Field | Type; default; requirement | Value |
|---|---|---|---|
export | Export As | Exportdefault CSVOptional. | CSV writes a CSV file and returns the Table. Datatable returns the Table without a file. The output table is populated in both modes. Choices: CSV, Datatable. |
file | File Path | Stringdefault emptyRequired. | Always required. For CSV, a local path such as samples/, in an existing folder. Datatable does not write it; give any path, such as samples/. |
encoding | Encoding | Encodingdefault ANSIOptional. | For CSV use ANSI for Windows-1252, UNICODE for UTF-16, or UTF8 for UTF-8 without a byte-order mark. Datatable ignores this field. Choices: ANSI, UNICODE, UTF8. |
with | Export data with header | Booleandefault falseOptional. | For CSV, true writes column names before rows. False writes rows only. Headers use SAP column titles when available, then column keys or generated names. |
overwrite | Overwrite the file | Booleandefault trueOptional. | For CSV, true replaces the whole file; false appends rows to the existing file, not skips or fails. With Header=true each appended export adds another header. |
Outputs
| ID | Type | Result |
|---|---|---|
table | Table | Table. Bind to a Table variable such as sap. All cell values are Strings; column names come from titles, keys or generated names. Returned for CSV and Datatable. |
Example
Set Field path=wnd[0]/usr/cntlGRID/shellcont/shell, Export As=CSV, File Path=samples/sap-grid.csv, Encoding=UTF8, Export data with header=true, Overwrite the file=true. Bind table to sapData. For no file, choose Export As=Datatable.
Expected result
sapData has String columns Code and Text and two rows A1/Alpha and B2/Beta. The CSV has header Code,Text and those rows. Overwrite=false appends, including another header when enabled. A missing parent folder fails CSV writing.
Get cell count (sapGetCell)
Return the number of cells: rows times columns.
Inputs
Also uses the session and control fields.
Outputs
| ID | Type | Result |
|---|---|---|
result | Number | Rows times columns. Bind to Number cell. |
Example
Set Field path=wnd[0]/usr/cntlGRID/shellcont/shell; bind result to Number variable cellCount.
Expected result
cellCount=4. An empty table gives 0. A count too large for a whole number or an unsupported control fails.
Get children names (sapGetChildrenNames)
Read the names of the direct child controls, not their children.
Inputs
Also uses the session and control fields.
Outputs
| ID | Type | Result |
|---|---|---|
result | List | Strings from direct children only, in control order. Uses Name, or Id if there is no Name. Bind to a List variable. |
Example
Set Field path=wnd[0]/usr/cntlSAMPLE for the prepared two-child container. Bind result to List variable childNames.
Expected result
childNames contains First and Second in their control order. It does not include grandchildren. A container with no children returns an empty List.
Get children text (sapGetChildrenText)
Read the text of each direct child, in control order.
Inputs
Also uses the session and control fields.
Outputs
| ID | Type | Result |
|---|---|---|
result | List | Strings from direct children only, in control order. Uses text, then value, then empty if neither exists. Bind to a List variable. |
Example
Set Field path=wnd[0]/usr/cntlSAMPLE for the prepared two-child container. Bind result to List variable childTexts.
Expected result
childTexts holds Alpha and Beta. No children gives an empty List.
Get column count (sapGetColumn)
Return the number of columns.
Inputs
Also uses the session and control fields.
Outputs
| ID | Type | Result |
|---|---|---|
result | Number | The number of columns. Bind to Number column. |
Example
Set Field path=wnd[0]/usr/cntlGRID/shellcont/shell; bind result to Number columnCount.
Expected result
columnCount=2. A table with no columns gives 0; a control that cannot count columns fails.
Get item count (sapGetItemCount)
Count combo entries, tree keys or direct children.
Inputs
Also uses the session and control fields.
Outputs
| ID | Type | Result |
|---|---|---|
result | Number | The number of combo entries, or tree keys, or direct children, in that order. Bind to a Number variable. |
Example
Use a sample combo with two entries. Set Field path=wnd[0]/usr/cmbSAMPLE; bind result to Number itemCount.
Expected result
itemCount=2. An empty collection gives 0; an unsupported control can fail.
Get row count (sapGetRow)
Return the number of rows.
Inputs
Also uses the session and control fields.
Outputs
| ID | Type | Result |
|---|---|---|
result | Number | The number of rows. Bind to Number row. |
Example
Set Field path=wnd[0]/usr/cntlGRID/shellcont/shell; bind result to Number rowCount.
Expected result
rowCount=2. A table with no rows gives 0; a control that cannot count rows fails.
Get selected item (sapGetSelectedItem)
Read the selection. It can be a key, not the visible text.
Inputs
Also uses the session and control fields.
Outputs
| ID | Type | Result |
|---|---|---|
result | String | The combo key, selected-rows text, selected-node text or tab number (from 1), using the first that the control supports. No selected tab gives empty. Bind to a String variable. |
Example
Prepare a combo whose visible Alpha entry has key A1 and select it. Use Field path=wnd[0]/usr/cmbSAMPLE; bind result to String selectedItem.
Expected result
selectedItem=A1. Other control errors can fail.
Get status (sapGetStatus)
Read whether a checkbox or other control is selected.
Inputs
Also uses the session and control fields.
Outputs
| ID | Type | Result |
|---|---|---|
result | Boolean | true means selected, false means not selected. Bind to a Boolean variable. This is an action, not a condition. |
Example
Check the sample checkbox, then set Field path=wnd[0]/usr/chkSAMPLE; bind result to Boolean isSelected.
Expected result
isSelected=true; after Uncheck it is false. A control with no selection state or an unreadable state fails.
Get table cell index (sapGetTableCellIndexByText)
Find exact whole-cell text and return its first position or every position.
Inputs
Also uses the session and control fields.
| ID | Field | Type; default; requirement | Value |
|---|---|---|---|
search | Search text | Stringdefault emptyRequired. | Enter the entire cell text to match, for example Alpha. This is an exact match, not a substring or regular expression. Empty is rejected. |
case | Case sensitive search | Booleandefault falseOptional. | true needs exact case. false ignores case for the whole cell. |
all | All occurrences | Booleandefault falseOptional. | False returns the first matching row, String, or empty String. True returns a List of all such Strings, or an empty List, in row-first scan order. |
Outputs
| ID | Type | Result |
|---|---|---|
result | Any | Any carrying a String row, when All occurrences=false, or a List of those Strings when true. Positions start at 1. Bind to an Any variable, or a matching String/List variable for the chosen mode. |
Example
Set Field path=wnd[0]/usr/cntlGRID/shellcont/shell, Search text=alpha, Case sensitive search=false, All occurrences=false; bind result to Any cellPosition.
Expected result
cellPosition is String 1,2. With All occurrences=true it is a List containing 1,2. No match gives empty String or empty List for that mode. Search text empty fails.
Get table cell text (sapGetTableCellTextByIndex)
Read the text at a 1-based table row and column.
Inputs
Also uses the session and control fields.
| ID | Field | Type; default; requirement | Value |
|---|---|---|---|
row | Row | Numberdefault 1Optional. | Shared. |
column | Column | Numberdefault 1Optional. | Shared. |
Outputs
| ID | Type | Result |
|---|---|---|
result | String | String containing the selected cell text. Bind to a String variable. Invalid indexes fail rather than return an empty placeholder. |
Example
Set Field path=wnd[0]/usr/cntlGRID/shellcont/shell, Row=2, Column=2; bind result to String cellText.
Expected result
cellText=Beta. Row=0 or Column=0 fails validation; a position beyond the table fails in the control.
Get text (sapGetText)
Read the text of a control.
Inputs
Also uses the session and control fields.
Outputs
| ID | Type | Result |
|---|---|---|
result | String | Uses text, then value if text is not supported, then empty if neither is supported. Bind to a String variable. Other control errors fail. |
Example
Put Sample in the test text field. Set Field path=wnd[0]/usr/txtSAMPLE; bind result to String fieldText.
Expected result
fieldText=Sample. A missing control fails.
Left click (sapLeftClick)
Same as Click. It does not move the mouse.
Inputs
Also uses the session and control fields.
Outputs
None.
Example
Set Field path=wnd[0]/tbar[0]/btn[0] on the disposable screen.
Expected result
The button or current grid cell is clicked. SAP sets the screen change; an unsupported control fails.
Right click (sapRightClick)
Open the control's right-click menu.
Inputs
Also uses the session and control fields.
Outputs
None.
Example
Set Field path=wnd[0]/usr/cntlGRID/shellcont/shell for a grid that has a right-click menu.
Expected result
The right-click menu opens. No item is selected. A control without this menu fails.
Select item (sapSelectItem)
Select a combo entry, tree node or tab by exact text or 1-based index.
Inputs
Also uses the session and control fields.
| ID | Field | Type; default; requirement | Value |
|---|---|---|---|
select | Select | Itemdefault TEXTOptional. | Shared. |
item | itemByText | Stringdefault emptyOptional. | Shared. |
item | itemByIndex | Numberdefault 1Optional. | Shared. |
Outputs
None.
Example
Use the test combo whose Alpha entry has key A1. Set Field path=wnd[0]/usr/cmbSAMPLE, Select=TEXT, itemByText=Alpha.
Expected result
The combo key becomes A1. INDEX with itemByIndex=1 selects its first entry. It also selects tree nodes and tabs. A missing item or invalid index fails.
Select radio option (sapSelectRadioOption)
Select a radio option.
Inputs
Also uses the session and control fields.
Outputs
None.
Example
Set Field path=wnd[0]/usr/radSAMPLE.
Expected result
The option is selected. SAP controls changes to other options. A missing control or one that cannot be selected fails.
Send virtual key (sapSendVirtualkey)
Send one SAP virtual key to the main session window wnd[0].
Inputs
Also uses the session and control fields (Session name only).
| ID | Field | Type; default; requirement | Value |
|---|---|---|---|
virtual | Select | Virtualdefault EnterOptional. | Choose the named SAP virtual key sent to wnd[0]. Enter is code 0, F11_ code 11 and F12_ code 12. Modifier names select those combinations; Shift_ is the retained value with SAP code 22. The screen decides each key effect. Choices: Enter, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11_, F12_, Shift_, Shift_, Shift_, Shift_, Shift_, Shift_, Shift_, Shift_, Shift_, Shift_, Shift_, Shift_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Ctrl_, Page, Page, Ctrl_, Ctrl_, Ctrl_, Ctrl_. |
Outputs
None.
Example
Use the disposable training screen. Set Select=Enter.
Expected result
The main window receives Enter. SAP can submit or check the screen. No field is selected by this action. A missing window or a SAP error fails.
Set table cell text (sapSetTableCellText)
Replace one editable table-cell text by an index or the first exact current value.
Inputs
Also uses the session and control fields.
| ID | Field | Type; default; requirement | Value |
|---|---|---|---|
set | Select | Itemdefault TEXTOptional. | TEXT finds the first cell whose whole text exactly equals Find Text, with case sensitivity. INDEX uses the 1-based Row and Column. Choices: TEXT, INDEX. |
find | Find Text | Stringdefault emptyOptional. | Required at runtime with Select=TEXT. Enter the current whole cell value, for example Alpha. Empty or no matching cell fails. INDEX ignores it. |
row | Row | Numberdefault 1Optional. | Shared. |
column | Column | Numberdefault 1Optional. | Shared. |
set | Set Text | Stringdefault emptyRequired. | Enter the replacement cell text, for example Changed. It must be nonempty, so this action cannot clear a table cell to an empty string. |
Outputs
None.
Example
Set Field path=wnd[0]/usr/cntlGRID/shellcont/shell, Select=INDEX, Row=2, Column=2, Set Text=Changed. Alternatively use Select=TEXT and Find Text=Beta.
Expected result
The second row Text cell becomes Changed. TEXT uses exact case-sensitive matching and changes only the first hit. Empty Set Text, no matching Find Text, bad indexes or read-only cells fail.
Set text (sapSetText)
Replace or add to the text of a control.
Inputs
Also uses the session and control fields.
| ID | Field | Type; default; requirement | Value |
|---|---|---|---|
field | Field value | Stringdefault emptyOptional. | Enter the text to write, for example Sample. Empty clears the field when Append text=false. |
is | Append text | Booleandefault falseOptional. | False replaces the current field text. True reads the current text and appends Field value with no separator. |
Outputs
None.
Example
With the sample field containing Sample, set Field path=wnd[0]/usr/txtSAMPLE, Field value= note, Append text=true.
Expected result
The field becomes Sample note. Append=false writes only Field value; an empty value clears it. A noneditable or absent control fails.