SAP GUI Scripting

 1. Go to customize layout option on the application tool bar of SAP Logon Pad,click it and a drop down menu will pop up.

2. Click on script recording and playback.



3. Mention the file name where the recorded file you want to save in the system with .vbs as the extension name

4. And execute the tcode like SU01,perform the steps by copying data from the excel file where the user's data is saved and it should look something like below.

User ID     Last Name     First Name so on..
XYZ           AAAA             BBBB

You will get code like below..

Need to add this in italics

Set objExcel = CreateObject("Excel.Application")
strPathExcel = "add the file path of the excel saved in your system"
objExcel.Workbooks.open strPathExcel
Set objSheet = objExcel.ActiveWorkbook.worksheet(1)


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

intRow=06 /* add the row where the data begins in the excel excluding the title names

Do While objSheet.Cells(intRow, 1).Value <> ""


session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "su01"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtUSR02-BNAME").text = objSheet.Cells(intRow, 1).Value
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_LAST").text = objSheet.Cells(intRow, 3).Value
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_FIRST").text = objSheet.Cells(intRow, 2).Value
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_LAST").setFocus
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_LAST").caretPosition = 5
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO").select
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/pwdG_PASSWORD1").text = objSheet.Cells(intRow, 4).Value
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/pwdG_PASSWORD2").text = objSheet.Cells(intRow, 5).Value
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/pwdG_PASSWORD2").setFocus
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/pwdG_PASSWORD2").caretPosition = 8
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG").select
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG/ssubMAINAREA:SAPLSUU5:0106/tblSAPLSUU5TC_AGR/ctxtUSAGR-AGR_NAME[1,0]").text = objSheet.Cells(intRow, 6).Value
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 11

intRow=intRow+1
Loop
objExcel.Quit





Comments Comments