Skip to Content
author's profile photo Former Member
Former Member

Scripting with Vbscript against SAPGUI

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,

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Feb 08, 2007 at 02:45 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 16, 2006 at 10:07 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 16, 2006 at 11:39 PM

    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,

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 21, 2006 at 05:25 PM

    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,

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 27, 2006 at 04:35 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 27, 2016 at 03:13 AM

    Hi Guillermo,

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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.