How to work with SAP (robocorp.com)

How to work with SAP

Robocorp supports automating SAP. The RPA.SAP library is based on the SapGuiLibrary that enables automating the SAP GUI application.

 

 

Enable SAP Scripting Engine

SAP scripting must be enabled on the server and on the client.

SAP user with the required authorization should set the sapgui/user_scripting for the system. It is also recommended to set sapgui/user_scripting_per_user to allow scripting on per user basis and then set the authorization object S_SCR for defined users.

Server

Set two parameters (sapgui/user_scripting and sapgui/user_scripting_per_user):

  • Execute saplogon.exe.
  • Log in to access SAP Easy Access.
  • From the transaction dropdown, select and run RZ11.
  • Enter sapgui/user_scripting as the parameter name.
  • Press the Display button.
  • Press the Change Parameter Value button.
  • Set New value to TRUE.
  • Click the save icon.
  • Add the sapgui/user_scripting_per_user parameter the same way and set it to TRUE.
  • Log out.
  • Log in.

SAP GUI Scripting Security Guide (PDF):

In some cases, it is not possible to enable SAP GUI Scripting for lack of a dedicated application server. This implies that users who are allowed to use SAP GUI Scripting work on the same server as others, so the support cannot be enabled for the server.

The problem can be solved by setting the rights to run SAP GUI Scripting per user. The new profile parameter sapgui/user_scripting_per_user allows the administrator then to enable SAP GUI Scripting support for specific users. Unless the administrator explicitly changes the value, this parameter is set to FALSE. If the profile parameter is set to TRUE the following happens:

  • On the login screen SAP GUI Scripting is available for every user.
  • After login, SAP GUI Scripting only remains available for those users that have the authorization for the Execute(16) action of the authorization object S_SCR in class BC_A.

Client

After user scripting is enabled on the server, each user with S_SCR authorization can enable the scripting in the SAP GUI client:

  • Press the Customise Local Layout button.
  • Select Options.
  • Navigate to Accessibility & Scripting -> Scripting.
  • Check Enable scripting.
  • Uncheck both of the notification options if they are checked.
  • Click OK.

Opening a connection / Before running automation

Start the SAP Logon Pad application. Use the Connect To Session keyword to connect to the SAP Session.

After successful connection, use the Open Connection keyword to open a new connection from the SAP Logon Pad or Connect To Existing Connection to connect to a connection that is already open.

Here's an example for logging into SAP:

 
*** Settings ***
Library    RPA.SAP    WITH NAME    SAP
Library    RPA.Desktop.Windows    WITH NAME    Windows

*** Keywords ***
SAP Gui Login
    Disable Screenshots On Error
    Windows.Open Executable    ${EXE_PAD}    ${TITLE_PAD}
    Connect To Session
    ${secrets}=    Get Secret    sap
    SAP.Open Connection    ${secrets}[connection]
    SAP.Input Text    ${FIELD_CLIENT}    ${secrets}[client]
    SAP.Input Text    ${FIELD_USER}    ${secrets}[user]
    SAP.Input Password    ${FIELD_PASSWORD}    ${secrets}[password]
    SAP.Send Vkey    0
  • ${EXE_PAD}: An absolute filepath to saplgpad.exe
  • ${TITLE_PAD}: The window title of the saplgpad.exe application once it has started
  • ${FIELD_CLIENT}: A locator for the Client input field, wnd[0]/usr/txtRSYST-MANDT
  • ${FIELD_USER}: A locator for the User input field, wnd[0]/usr/txtRSYST-BNAME
  • ${FIELD_PASSWORD}: A locator for the Password input field, wnd[0]/usr/pwdRSYST-BCODE

Also check the SAP Logon & Login example by Robocorp community member RoboHeart!

Locating or specifying elements

Specify elements starting from the window ID, for example, wnd[0]/tbar[1]/btn[8]. In some cases, the SAP ID contains backslashes. Escape these backslashes by adding another backslash in front of them.

Check the SAP - MM01 - Create Material example by Robocorp community member RoboHeart!

Screenshots (on error)

The RPA.SAP library has an option for automatic screenshots on error. This option is enabled by default. Use Disable Screenshots On Error to skip the screenshot functionality.

Alternatively, this option can be set when importing the library:

 
*** Settings ***
Library    RPA.SAP    screenshots_on_error=True    screenshot_directory=None

Example robots

Learn more about the libraries mentioned on this page:

2021年4月28日
posted on 2022-01-21 09:23  ricoo  阅读(202)  评论(0编辑  收藏  举报