cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Scripting with Vbscript against SAPGUI

Former Member
0 Likes
8,378

Hello everyone,

Im new in this field, the thing is that i want to create scripts with vbscript in order to automate some business processes.

I have been reading the SAP GUI Scripting API guide, and some other documents, but i dont know how to use the classes, methods, functions, etc. of the sapfewselib.

Somebody, know how to make reference to this library in order to use it on Vbscript??

If you can put some code examples, that will be great.

Thanx,

View Entire Topic
Former Member
0 Likes

Please find sapfewse.ocx

(C:\Program Files\SAP\FrontEnd\SAPgui\sapfewse.ocx)

and try this code:

Dim sap As New GuiApplication

Set conexion = sap.OpenConnection("name_of_the_server_in_SAP Logon")

Set sesion = conexion.Children(0)

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

sesion.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "Client"

sesion.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "User" '

sesion.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "password"

sesion.findById("wnd[0]/usr/pwdRSYST-BCODE").SetFocus

sesion.findById("wnd[0]/usr/pwdRSYST-BCODE").caretPosition = 8

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

or try this:

Set gi = CreateObject("SAPGUI.ScriptingCtrl.1")

the better way to work with SAP GUI Scripting is with a record. Please go to RZ11 transaction and change the following parameter to TRUE:

sapgui/user_scripting

then Logoff an Logon again

then Alt+F12 (Customizing for Local Layout), click in Script Recording and Playback and record some transaction

the generated code is itself executable and you can modify o attach this code to another software that supports VBScripting like MSExcel

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 = "/nMM01"

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

session.findById("wnd[0]/usr/cmbRMMG1-MBRSH").key = "1"

session.findById("wnd[0]/usr/cmbRMMG1-MTART").key = "ROH"

session.findById("wnd[0]/usr/cmbRMMG1-MTART").setFocus

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

session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW").getAbsoluteRow(0).selected = true

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

session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP01/ssubTABFRA1:SAPLMGMM:2004/subSUB1:SAPLMGD1:1002/txtMAKT-MAKTX").text = "TEST"

session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP01/ssubTABFRA1:SAPLMGMM:2004/subSUB2:SAPLMGD1:2001/ctxtMARA-MEINS").text = "UN"

session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP01/ssubTABFRA1:SAPLMGMM:2004/subSUB2:SAPLMGD1:2001/ctxtMARA-MEINS").setFocus

session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP01/ssubTABFRA1:SAPLMGMM:2004/subSUB2:SAPLMGD1:2001/ctxtMARA-MEINS").caretPosition = 2

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

If you have any doubts please feel free to send me an email, I have worked some years with SAP GUI Scripting.

Regards,

Arturo Bernal

abmemail@yahoo.com

Former Member
0 Likes

Hi, i have a question. I have a code in VBa, where Combobox selection is showing error, ie not list is being loaded to the combobox. Plz tell me how to fix the problem

thanks

Rajkumar

holger_khn
Contributor
0 Likes

Hello. Please open a new thread for your issue. Provide code used and more Details about issue. May an screenshot will help People to understand your issue.