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

Addrees to certain session

Hi everbody,

now I'm also a meber of this blog.

I've a Problem to address a certain SAP session via VBA code.

I've written a VBA code to control and getting some Information from the MM003 (Material) but VBA looks always to the first SAP session.

I start the VBA code with GUIXT in MM03. But if this session not the first session, the code try to operate from the first one.

Because of the reason, that I'm not able to insert the copy of my code here I gave the textfile enclose.

Thank you in advance.

Michael

SAP.txt.zip (412 B)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Apr 01, 2016 at 10:13 PM

    Hello.

    I Have add an guidance how To prepare an Macro-entblödet Excel Template To select an specific SAP Session for Exekution.

    I Gutes Review my Code will Five you some Idea how To achieve such requirement.

    Interactive and dynamic Excel VBA template - SAP GUI Scripting -

    Best regards

    Holger

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Apr 07, 2016 at 02:43 PM

    Hello Michael,

    the session in your code is being set to the first "child" of the connection (session = sapConnection.Children(0)).

    In order to have a certain session being selected, you need to identify it and there are a couple of approaches to do this.

    One of the simplier ones would be to get the session in which a certain transaction is being executed. the property "transaction" of the GuiSessionInfo object (which is a member of any GuiSession) gives you this information.

    What’s left to do is, to iterate over all sessions (aka "children") of a GuiConnection, compare the current transaction being executed with the desired one (this would be „MM03“ in your case, if I’m correct) and if it the desired one, you have the session you need.

    Kind regards

    Alkis

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 08, 2016 at 09:59 PM

    My method for dealing with this is always launch a new instance of SAP and then use the code below to get the last window opened

        Set SapGuiAuto = GetObject("SAPGUI")
        Set SapApp = SapGuiAuto.GetScriptingEngine
        Set SapCon = SapApp.Children(SapApp.Children.Count - 1)
        Set Session = SapApp.Children(SapApp.Children.Count - 1).sessions(SapApp.Children(SapApp.Children.Count - 1).sessions.Count - 1)
    
    
    
    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.