cancel
Showing results for 
Search instead for 
Did you mean: 

How-to-guide for SAP GUI Scripting

Sahoo
Newcomer
This article provides a guide to SAP GUI Scripting, which is used to automate tasks. It outlines the prerequisites for enabling GUI Scripting, such as enabling the parameter in RZ11 and enabling scripting on the SAP Logon Pad. It also explains updating the script file to include data from an excel spreadsheet. Finally, it covers how to execute the script.

Table of Contents

1 PREREQUISITES 
1.1 Enabling GUI Scripting Parameter
1.2 Enabling Scripting on SAP Logon Pad

2 UPDATING SCRIPT FILE 
2.1 Creating an Excel File
2.2 Updating Codes in Script File

3 EXECUTING THE SCRIPT 

------------------------------------------
1 PREREQUISITES
Before recording/executing SAP GUI Script, there are certain settings to be done in SAP system which are as follows.

1.1 Enabling GUI Scripting Parameter
Transaction: RZ11
Parameter Name: sapgui/user_scripting
1.jpg










Click on Display and change the current value to TRUE
2.jpg












Please note that this task is generally done by BASIS Team. 

1.2 Enabling Scripting on SAP Logon Pad
Go to SAP Logon Pad > Options > Accessibility & Scripting > Scripting
3.jpg








 

4.jpg










As highlighted in above screen shot, Enable scripting checkbox must be checked. Other checkboxes should remain unchecked, else you will get a popup message every time a script runs.
After above two steps are done, Script Recording and Playback option is enabled to record and run scripts.
5.jpg







6.jpg








After recording is stopped,
.vbs script file will be saved in the location selected while recording.
7.jpg



2 UPDATING SCRIPT FILE
Once script recording is completed, input data needs to be prepared in an excel sheet and the codes in script file must be updated accordingly.

2.1 Creating an Excel File
Create an excel file with all the columns that are required and filled during script recording. In below example, excel file Users.xls is created with required columns.
8.jpg









Please note that the last row must contain the text as LAST

2.2 Updating Codes in Script File
Open the earlier saved .vbs file in notepad and keep below initial lines of codes as it is.
------------------------------------------
If Not IsObject(application) Then
Set SapGuiAuto  = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session    = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session,     "on"
WScript.ConnectObject application, "on"
End If
------------------------------------------
Then add following codes where the exact path of the excel file should be provided.
------------------------------------------
Dim cnnExcel, rstExcel
Dim strExcelFile
strExcelFile = "\\path of the excel file\Users.xls"
------------------------------------------
Then add below codes where the sheet range should be mentioned as per the data in excel file.
------------------------------------------
Set cnnExcel = CreateObject("ADODB.Connection")
cnnExcel.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strExcelFile & ";" & _
"Extended Properties=""Excel 8.0;HDR=NO;"""

Set rstExcel = CreateObject("ADODB.Recordset")
rstExcel.Open "Select * from [Sheet1$A2:F11]", cnnExcel, adOpenStatic

Do Until rstExcel.EOF or UCASE(rstExcel.Fields(0).Value) = "LAST"
------------------------------------------
After that keep the following codes as available in script file, but replace the hardcoded values (user ID, Email ID etc.) with excel formula as highlighted below.
------------------------------------------
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/ctxtSUID_ST_BNAME-BNAME").Text = (rstExcel.Fields(0).Value)
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_PERSON_NAME-NAME_LAST").Text = (rstExcel.Fields(1).Value)
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_PERSON_NAME-NAME_FIRST").Text = (rstExcel.Fields(2).Value)
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_COMM_DATA-SMTP_ADDR").Text = (rstExcel.Fields(3).Value)
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/btnGS_ADDR_OTHERS-PUSH_OCMP").press
session.findById("wnd[1]/tbar[0]/btn[71]").press
session.findById("wnd[2]/usr/txtRSYSF-STRING").text = (rstExcel.Fields(4).Value)
session.findById("wnd[2]/tbar[0]/btn[0]").press
session.findById("wnd[3]").sendVKey 2
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO").Select
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/btnFKT_DEL").press
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/ctxtSUID_ST_NODE_LOGONDATA-CLASS").Text = (rstExcel.Fields(5).Value)
session.findById("wnd[0]/tbar[0]/btn[11]").press
------------------------------------------
Then add the final set of codes as below and save the script file.
------------------------------------------
rstExcel.movenext
If rstExcel.EOF Then
Exit Do
End If
LOOP 
rstExcel.Close
Set rstExcel = Nothing
cnnExcel.Close
Set cnnExcel = Nothing
------------------------------------------

3 EXECUTING THE SCRIPT

Open the only SAP system where you need to execute the script and open only one session of that SAP system. This is to ensure that script runs in desired system and without any error.

Go to that screen where you recorded the script. Example: If recording was performed in SU01 screen, then t-code SU01 must be executed first before running the user provisioning script.

Click on Script Recording and Playback, browse the script file and click on Playback button to run the script.
9.jpg

      10.jpg















Thank you,
Sahoo
SAP S/4HANA SAP R/3 Security 

Accepted Solutions (0)

Answers (0)