cancel
Showing results for 
Search instead for 
Did you mean: 

Problems selecting tab via script

Former Member
0 Kudos

Hi everyone,

I've started scripting a few days ago and it works quite well.

But there is one issue I'm still fighting with:

I would like to run the transaction MM01 via VBA Excel script to create part numbers full automatically.

The code works fine until the following bold line:

.....

session.findById("wnd[0]/tbar[1]/btn[30]").press 'Select Button "Zusatzdaten"

session.findById("wnd[0]/usr/tabsTABSPR1/tabpZU05").Select 'Jump to Tab 5 "Grunddatentext"

session.findById("wnd[0]/usr/tabsTABSPR1/tabpZU05/ssubTABFRA1:SAPLMGMM:2110/subSUB2:SAPLMGD1:2031/cntlLONGTEXT_GRUNDD/shellcont/shell").Text = TEXTVARIABLE

session.findById("wnd[0]/tbar[0]/btn[11]").press 'Enter to Save and Close Session.

Selecting tab no. 5 works just a few times but after some loops (<10) the screen looks like this and my code stops working:

Instead of jumping to tab 5 the SAP screen looks like a freezed mixture of tab no. 1 an tab no. 5. And then it stops working.

Selecting tabs is (in my case) always a problem.

Can anyone please tell me how to select a tab without freezing? Why is it not working?

Thanks in advance.

Matthias

Accepted Solutions (1)

Accepted Solutions (1)

stefan_schnell
Active Contributor
0 Kudos

Hello Matthias,

welcome in the Scripting Languag forum.

I don't know your problem. I check in a loop with one of my testcases the using of tabstrip without any problems.

'-Begin-----------------------------------------------------------------

session.findById("wnd[0]/tbar[0]/okcd").text = "/nGUIBIBS"

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

For i = 1 To 27

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

Next

WScript.Sleep 1000

For i = 1 To 100

  session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB6").select

  session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB5").select

  session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB4").select

  session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB3").select

  session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB2").select

  session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB1").select

  WScript.Sleep 250

Next

'-End-------------------------------------------------------------------

Pleasy try this script also and tell us your results.

I try the same test procedure with MM01, but the result is the same, no problem with tab switching.

'-Begin-----------------------------------------------------------------

For i = 1 To 100

  session.findById("wnd[0]/usr/tabsTABSPR1/tabpZU01").select

  session.findById("wnd[0]/usr/tabsTABSPR1/tabpZU02").select

  session.findById("wnd[0]/usr/tabsTABSPR1/tabpZU03").select

  session.findById("wnd[0]/usr/tabsTABSPR1/tabpZU04").select

  session.findById("wnd[0]/usr/tabsTABSPR1/tabpZU05").select

  session.findById("wnd[0]/usr/tabsTABSPR1/tabpZU06").select

  session.findById("wnd[0]/usr/tabsTABSPR1/tabpZU07").select

  session.findById("wnd[0]/usr/tabsTABSPR1/tabpZU08").select

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

  'WScript.Sleep 250

  session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP01/ssubTABFRA1:SAPLMGMM:2004/subSUB7:SAPLMGD1:2033/btnPUSH_GRUNDDATENTEXT").press

Next

'-End-------------------------------------------------------------------

Please try it also.

Otherwise you can find more information here and here. What version of SAP GUI for Windows do you use?

Cheers

Stefan

Former Member
0 Kudos

Hello Stefan,

Thank you very much for your help.

The GUI Version is: 7300.3.9.1084

I've tried both of your codes without any freezing (but only as VBS).

Could it be a problem to run the code in Excel?

I would like to use only VBA and not VBS.

The second link you have mentioned says: checkmark  "retrieve field type information from sap".

I have no idea where to find the options menu...Can you tell me where to find it?


Only changing the network settings to "low speed connection" doesn't make a difference.

This is really frustrating...

Matthias

stefan_schnell
Active Contributor
0 Kudos

Hello Matthias,

there is not really a difference between VBS and VBA. As you can see you can use the complete VBS code inside VBA.

Here the first code in VBA:

'-Begin---------------------------------------------------------------

  '-Directives--------------------------------------------------------

    Option Explicit

  '-External functions------------------------------------------------

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

  '-Main--------------------------------------------------------------

    Sub Main()

      '-Variables-----------------------------------------------------

        Dim SapGuiAuto As Object

        Dim App As SAPFEWSELib.GuiApplication

        Dim connection As SAPFEWSELib.GuiConnection

        Dim session As SAPFEWSELib.GuiSession

        Dim i As Long

      If App Is Nothing Then

        Set SapGuiAuto = GetObject("SAPGUI")

        Set App = SapGuiAuto.GetScriptingEngine

      End If

      If connection Is Nothing Then

        Set connection = App.Children(0)

      End If

      If session Is Nothing Then

        Set session = connection.Children(0)

      End If

      session.FindById("wnd[0]/tbar[0]/okcd").Text = "/nGUIBIBS"

      session.FindById("wnd[0]").SendVKey 0

      For i = 1 To 27

        session.FindById("wnd[0]/tbar[1]/btn[19]").Press

      Next

      Sleep 1000

      For i = 1 To 100

        session.FindById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB6").Select

        session.FindById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB5").Select

        session.FindById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB4").Select

        session.FindById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB3").Select

        session.FindById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB2").Select

        session.FindById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB1").Select

        Sleep 250

      Next

    End Sub

'-End-----------------------------------------------------------------

And here the second code in VBA:

  '-Directives--------------------------------------------------------

    Option Explicit

  '-Main--------------------------------------------------------------

    Sub Main()

      '-Variables-----------------------------------------------------

        Dim SapGuiAuto As Object

        Dim App As SAPFEWSELib.GuiApplication

        Dim connection As SAPFEWSELib.GuiConnection

        Dim session As SAPFEWSELib.GuiSession

        Dim i As Long

      If App Is Nothing Then

        Set SapGuiAuto = GetObject("SAPGUI")

        Set App = SapGuiAuto.GetScriptingEngine

      End If

      If connection Is Nothing Then

        Set connection = App.Children(0)

      End If

      If session Is Nothing Then

        Set session = connection.Children(0)

      End If

      '---------------------------------------------------------------

      '-

      '- Preparation: Open TAC MM01 with your new material ID and

      '-              switch to additional data before you execute

      '-              this script.

      '-

      '---------------------------------------------------------------

      For i = 1 To 100

        session.FindById("wnd[0]/usr/tabsTABSPR1/tabpZU01").Select

        session.FindById("wnd[0]/usr/tabsTABSPR1/tabpZU02").Select

        session.FindById("wnd[0]/usr/tabsTABSPR1/tabpZU03").Select

        session.FindById("wnd[0]/usr/tabsTABSPR1/tabpZU04").Select

        session.FindById("wnd[0]/usr/tabsTABSPR1/tabpZU05").Select

        session.FindById("wnd[0]/usr/tabsTABSPR1/tabpZU06").Select

        session.FindById("wnd[0]/usr/tabsTABSPR1/tabpZU07").Select

      Next

    End Sub

'-End-----------------------------------------------------------------

In both cases it works without any problems on my system. Please try it again and tell us your results. Freeze the screen in your case here too? If not, maybe place a Sleep after your command session.findById("wnd[0]/tbar[0]/btn[11]").press, because I see you add data.

To your questions:

  • I don't know exactly if it is a problem of Excel or not, but I don't suppose it.
  • The checkmark is a special option of WinShuttle.

Cheers

Stefan

Former Member
0 Kudos

Hi Stefan,

your code works fine

It's probably the well known hanging problem (mentioned on your windshuttle link).

What I'm going to do next is: Asking my SAP basis team to apply these notes:

  • sapnote_1584498
  • sapnote_1659422

I'm not sure if my basis team will be cooperative. But this is probably the only way to fix this issue.

I've tried everything, also "sleeps" (or better say "application.wait's" in Excel) before each code line.

Nothing helped. Thank you very much for your support. I will reply soon to help other users.

Matthias

Answers (0)