Skip to Content
Technical Articles
Author's profile photo Sahil Taneja

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.

Assigned tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Johannes Goerlich
      Johannes Goerlich

      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.

      Author's profile photo VIDYAVATI NAGINENI
      VIDYAVATI NAGINENI

      Hello,

      Suppose I have 5 users with different number of roles need to assign. How do i build vba script.

      So far i could assign role line by line item from the given excel. And that takes long time to update for each role line item via script. Is there any way the script pics all 10 roles in one go for a given user. Likewise need to update 20 roles maybe for another user in one go.

       

      test1 test_role1
      test1 test_role2
      test1 test_role3
      test1 test_role4
      test1 test_role5
      test1 test_role6
      test1 test_role7
      test1 test_role8
      test1 test_role9
      test1 test_role10

      Kindly help me

      Author's profile photo Sahil Taneja
      Sahil Taneja
      Blog Post Author

      Ok to answer ur query i will tell u the problem i faced.. i had a list of 500 users to be assigned to different 50 roles.

      Means. User 1 gets role1 role2 and role30.

      User2 gets role6 role20 and role33.

       

      Means random.

       

      So what you can do is.. be it 5 users be it 100 users. Sort them by role... and use ***SU10*** for scripting. Means assign users to the role...

      Su10 script for each role entry...

      Author's profile photo VIDYAVATI NAGINENI
      VIDYAVATI NAGINENI

      Do you have script ready for it? Though i will give a try to create vbs script via su10. My doubt is how will script identify the next id and assign roles mapped from the excel sheet.