Skip to Content
Technical Articles

SAP GUI Scripting (mass updates)

Guys, so we face this every day, we need to mass update something. I am not sure about you, but working on projects and all, I face this thing every day to update multiple users, or perform mass updating the roles.

There are 3 solutions to this viz. LSMW, ecatt and GUI scripting. The least used one is GUI scripting; we end up using LSMW and ecatt whereas they are too time consuming and more prone to errors.

GUI scripting is very quick, it takes almost 5 minutes to make a script. I will be taking you guys through a script to create multiple users.

Firstly, an RZ11 parameter needs to be set to 1, which is usually 1 in non-prod systems. If not, set that to 1 in rz11 by clicking on change value:

 

RZ11%20Parameter%20Update

RZ11 Parameter Update

 

Click on Settings -> Script Recording and Playback

This window will open

Click on More and give the path where you want to save the script and click on Record:

 

Perform the action you want to do, here I am creating a user with first name, last name, email ID, password and a role.

Here I have created a user with ID TEST_SCRIPT.

 

 

Stop the recording, and the script would have been generated in VB.

 

Open the file with notepad and it would be something like this:

Now the script has recorded all the actions, not the password because of encryption. We have to put a loop on these actions and data to be read from an excel file.

I have the excel file ready:

Change the code as following, mentioned what all to be changed in screenshots, and have pasted the code too for your reference. It seems a lot, but it takes only two minutes. Save the file as name.vbs:

 

Here is the code

 

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




Dim intRow




Set objExcel = CreateObject("Excel.Application")

Set objWorkbook = objExcel.Workbooks.Open("C:\Temp\filename.xlsx")




intRow = 2




Do Until objExcel.Cells(intRow,1).Value = ""




session.findById("wnd[0]").maximize

session.findById("wnd[0]/tbar[0]/okcd").text = "/nsu01"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/ctxtSUID_ST_BNAME-BNAME").text = objExcel.Cells(intRow,1).Value

session.findById("wnd[0]/usr/ctxtSUID_ST_BNAME-BNAME").caretPosition = 11

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 = objExcel.Cells(intRow,3).Value

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_PERSON_NAME-NAME_FIRST").text = objExcel.Cells(intRow,2).Value

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_COMM_DATA-SMTP_ADDR").text = objExcel.Cells(intRow,5).Value

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_COMM_DATA-SMTP_ADDR").setFocus

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_COMM_DATA-SMTP_ADDR").caretPosition = 13

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO").select

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/pwdSUID_ST_NODE_PASSWORD_EXT-PASSWORD").text = objExcel.Cells(intRow,4).Value

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/pwdSUID_ST_NODE_PASSWORD_EXT-PASSWORD2").text = objExcel.Cells(intRow,4).Value

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/pwdSUID_ST_NODE_PASSWORD_EXT-PASSWORD2").setFocus

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/pwdSUID_ST_NODE_PASSWORD_EXT-PASSWORD2").caretPosition = 10

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG").select

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG/ssubMAINAREA:SAPLSUID_MAINTENANCE:1106/cntlG_ROLES_CONTAINER/shellcont/shell").modifyCell 0,"AGR_NAME",objExcel.Cells(intRow,6).Value

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG/ssubMAINAREA:SAPLSUID_MAINTENANCE:1106/cntlG_ROLES_CONTAINER/shellcont/shell").currentCellColumn = "AGR_NAME"

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG/ssubMAINAREA:SAPLSUID_MAINTENANCE:1106/cntlG_ROLES_CONTAINER/shellcont/shell").pressEnter

session.findById("wnd[0]/tbar[0]/btn[11]").press

session.findById("wnd[0]/tbar[0]/okcd").text = "/n"

session.findById("wnd[0]").sendVKey 0

intRow = intRow + 1

Loop

objExcel.Quit

 

Again go to settings, click on Play the script:

The script will create the users as mentioned in file accordingly with the password and the email.

Voila… Please comment in case you need any help, will try to get back as soon as possible.

1 Comment
You must be Logged on to comment or reply to a post.
  • Thanks for your blogpost!

    I would recommend to additionally set the profile parameter sapgui/user_scripting_per_user = TRUE to restrict gui scripting for dedicated users identified by the auth object “S_SCR” which must be assigned to them. This helps to reduce the risk of misuse especially in productive systems.