How to Create Sap Gui Scripting

SAP GUI Scripting syntax similar like VBScript and you can used setup your testing data or data migration from legacy system to SAP. Is easy and less time to create sap gui scripting compared to LSMW. Sap Gui Scripting it can migrated master data and Transaction data as well. I will showed you how to create it.

Here the step by step to create your sap gui script


1. Click on the Script Recording and Playback
















2. Click on More button, you can changed the filename and path.









3. Click on Record button and type "SU01" to lock user id.

4. Once you have completed then click Stop button.

5. Here the script you recorded.

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
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "su01"                                 'T-code
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtUSR02-BNAME").text = "test1"             'User ID
session.findById("wnd[0]/usr/ctxtUSR02-BNAME").caretPosition = 5
session.findById("wnd[0]/tbar[1]/btn[29]").press                                          'preess the locked button
session.findById("wnd[1]/tbar[0]/btn[6]").press                                            'Locked user id
session.findById("wnd[0]/tbar[0]/btn[3]").press                                            'Exit SU01 screen

6. Copy this script into excel macros and insert extra code in the Macros. Remember to replace "Application" to SAPApp

Sub lockeduserid()

If Not IsObject(SAPApp) Then
   Set SapGuiAuto = GetObject("SAPGUI")
   Set SAPApp = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
   Set Connection = SAPApp.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 SAPApp, "on"
End If
'Manual add the rows highlight in yellow color.
For i = 1 To 10                                                           'go to next rows

Range("A" & i).Select                                                     'Column
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "su01"                     'T-code
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtUSR02-BNAME").Text = ActiveCell.Value    'User ID
session.findById("wnd[0]/usr/ctxtUSR02-BNAME").caretPosition = 5
session.findById("wnd[0]/tbar[1]/btn[29]").press                          'preess the locked button
session.findById("wnd[1]/tbar[0]/btn[6]").press                           'Locked user id
session.findById("wnd[0]/tbar[0]/btn[3]").press                           'Exit SU01 screen
Next

End Sub

7. tried put your sap id in column A rows 1 to 10. (Don't test it in Product environment)

If you have any question please drop message in contact form. 

Comments

Popular posts from this blog

Excel VBA connect SAPRFC

Simple macros to re-arrange column into upload format