SAP APIs
SAP GUI automation is supported since Sahi Pro SAP Engine.
Launch SAP GUI
Section titled “Launch SAP GUI”Modes SAP
Launches SAP GUI logon pad.
Parameters
| Name | Type | Description |
|---|---|---|
None |
Raw script
_launchSAPGUI();Sahi Pro Classic API _launchSAPGUI
Close SAP GUI
Section titled “Close SAP GUI”Modes SAP
Closes SAP GUI logon pad launched earlier using _launchSAPGUI.
Parameters
| Name | Type | Description |
|---|---|---|
None |
Raw script
_closeSAPGUI();Sahi Pro Classic API _closeSAPGUI
Open a SAP GUI connection
Section titled “Open a SAP GUI connection”Modes SAP
Opens the specified SAP GUI connection.
Parameters
| Name | Type | Description |
|---|---|---|
$connectionName | string | Name of the connection to open |
Raw script
_openSAPConnection("Connection1");Sahi Pro Classic API _openSAPConnection
Close SAP GUI connection
Section titled “Close SAP GUI connection”Modes SAP
Closes the currently open SAP GUI connection.
Parameters
| Name | Type | Description |
|---|---|---|
None |
Raw script
_closeSAPConnection();Sahi Pro Classic API _closeSAPConnection
Create a SAP GUI session
Section titled “Create a SAP GUI session”Modes SAP
Opens a new SAP GUI session from the existing SAP GUI session.
Parameters
| Name | Type | Description |
|---|---|---|
None |
Raw script
_createNewSAPSession();Sahi Pro Classic API _createNewSAPSession
Maximize a SAP GUI window
Section titled “Maximize a SAP GUI window”Modes SAP
Maximizes an existing SAP GUI window having the specified title. If title is not specified, it maximizes the current window.
Parameters
| Name | Type | Description |
|---|---|---|
$title | stringoptional | Title of the window to maximize |
Raw script
_maximizeWindow();_maximizeWindow("Create Order");_maximizeWindow("/Purchase Order No./");_maximizeWindow("/Purchase Order No. [0-9]{5}/");Sahi Pro Classic API _maximizeWindow
Minimize a SAP GUI window
Section titled “Minimize a SAP GUI window”Modes SAP
Minimizes an existing SAP GUI window having the specified title. If title is not specified, it minimizes the current window.
Parameters
| Name | Type | Description |
|---|---|---|
$title | stringoptional | Title of the window to minimize |
Raw script
_minimizeWindow();_minimizeWindow("Create Inquiry");_minimizeWindow("/Purchase Order No./");_minimizeWindow("/Purchase Order No. [0-9]{5}/");Sahi Pro Classic API _minimizeWindow
Restore a SAP GUI window
Section titled “Restore a SAP GUI window”Modes SAP
Restores an existing SAP GUI window having the specified title from its minimized state. If title is not specified, it restores the current window.
Parameters
| Name | Type | Description |
|---|---|---|
$title | stringoptional | Title of the window to restore |
Raw script
_restoreWindow();_restoreWindow("Create Order");_restoreWindow("/Purchase Order No./");_restoreWindow("/Purchase Order No. [0-9]{5}/");Sahi Pro Classic API _restoreWindow
Resize a SAP GUI window
Section titled “Resize a SAP GUI window”Modes SAP
Resizes an existing SAP GUI window having the specified title with the specified dimensions.
Parameters
| Name | Type | Description |
|---|---|---|
$title | string | Title of the window to resize |
$width | integer | New width for the window |
$height | integer | New height for the window |
Raw script
_resizeWindow("Create Order", 800, 400);_resizeWindow("/Purchase Order No./", 380, 250);_resizeWindow("/Purchase Order No. [0-9]{5}/", 640, 300);Sahi Pro Classic API _resizeWindow
Read status from SAP GUI
Section titled “Read status from SAP GUI”Modes SAP
Gets the status information from the status bar of the current SAP GUI window. It returns the status message, message type, message id, message number. It also returns up to eight parameters of the status message.
Parameters
| Name | Type | Description |
|---|---|---|
None |
Returns
mp | Status information object |
Raw script
// Read status informationvar $statusInfo = _getStatusInformation();var $statusMessage = $statusInfo.Message; // e.g Inquiry 10000267 has been savedvar $statusMessageType = $statusInfo.MessageType; // e.g Success, Information, Warning, Error, Abortvar $statusMessageId = $statusInfo.MessageId;var $statusMessageNumber = $statusInfo.MessageNumber;var $statusMessageParameter0 = $statusInfo.MessageParameter0;var $statusMessageParameter1 = $statusInfo.MessageParameter1;var $statusMessageParameter2 = $statusInfo.MessageParameter2;var $statusMessageParameter3 = $statusInfo.MessageParameter3;var $statusMessageParameter4 = $statusInfo.MessageParameter4;var $statusMessageParameter5 = $statusInfo.MessageParameter5;var $statusMessageParameter6 = $statusInfo.MessageParameter6;var $statusMessageParameter7 = $statusInfo.MessageParameter7;
// Verify status messagevar $pattern = "/^Inquiry (.*) has been saved$/";_assertEqual($pattern, $statusMessage);
// Extract inquiry number from status messagevar $inquiryNumber = _extract($statusMessage, $pattern, true);Sahi Pro Classic API _getStatusInformation
Select rows in a SAP GUI table
Section titled “Select rows in a SAP GUI table”Modes SAP
Selects the specified row(s) in the specified table element.
Parameters
| Name | Type | Description |
|---|---|---|
$element | HTML DOM element | Table element |
$rows | string | Comma separated list of row numbers to be selected |
Raw script
_selectRows(_gridView("wnd[0]/usr/cntlBCALVC_TOOLBAR_D100_C1/shellcont/shell"), "2,3");Sahi Pro Classic API _selectRows
Select columns in a SAP GUI table
Section titled “Select columns in a SAP GUI table”Modes SAP
Selects the specified columns in the specified table element.
Parameters
| Name | Type | Description |
|---|---|---|
$element | HTML DOM element | Table element |
$columns | string | Comma separated list of column titles to be selected |
Raw script
_selectColumns(_gridView("wnd[0]/usr/cntlBCALVC_TOOLBAR_D100_C1/shellcont/shell"), "Price,Order Quantity");Sahi Pro Classic API _selectColumns
Submit a HTML form in SAP GUI
Section titled “Submit a HTML form in SAP GUI”Modes SAP
Submits an HTML form for an _htmlViewer element.
Parameters
| Name | Type | Description |
|---|---|---|
$element | HTML DOM element | HtmlViewer element |
$frameName | string | Name of the parent frame of the HTML form to be submitted |
$postData | string | Post data to be submitted |
$url | string | Url to be submitted to the SAP server. |
Raw script
_htmlFormSubmit(_htmlViewer("wnd[0]/usr/cntlHTML/shellcont/shell"), "Frame1", "FirstName=John&LastName=Smith", "sapevent:SUBMIT_FORM_AS_POST_METHOD");Sahi Pro Classic API _htmlFormSubmit

