cancel
Showing results for 
Search instead for 
Did you mean: 

Scripting with Vbscript against SAPGUI

Former Member
0 Kudos

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,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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 Kudos

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 Kudos

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.

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Guillermo,

Is there a similar scripting for attaching a file in mm03 or mm43

Former Member
0 Kudos

Hi Guillermo Riojas ,

We also have the same requirement. Did you get any solution for this. Please can you share some more inputs on this.

Regards,

Naveen

Former Member
0 Kudos

Hi Gregor,

Well, i have been using ECATT tool, which i found useful, but it is a little bit difficult for people who is not involved in the sap world to understand or use it. That is way i would like to learn how to use the sap api with VB or VBscript in order to create automated scripts, easy to understand and use for people who is not involved with sap but know vb or vbscript.

Is there any way to use sap api, with these tools? (VBscript, VB)

Regards,

Former Member
0 Kudos

Hi guys,

Basically, the purpose of trying to create scripts using the sap api scripting guide, is because, im involved in the functional testing field. So im trying to create a new way to script against sap using descriptive programming style, without using the gui

i would like to browse across sap tcodes, fields, etc, and automate any process i.e. creating a sales order, usign functions of the api.

It might sound a little bit strange, but that is my job, lol,

so, did i explain what im trying to get?

Regards,

gregorw
Active Contributor
0 Kudos

Hi Guillermo,

SAP provides an integrated Testing Tool called CATT. I think you should have a look at the CATT Weblog Series from <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/u/37984">sapna Modi</a>.

Regards

Gregor

gregorw
Active Contributor
0 Kudos

Hi Guillermo,

can you tell us more about your Business Case?

I think a possible solution can also be Batch Input which can be recorded in Transaction SHDB. From this recording you can create a Program or Function Module.

Regards

Gregor