on 02-26-2016 9:55 AM
Hi,
I am creating the automation templates using SAP GUI Scripting. For the business case, I need to evaluate the selected / Current tab from SAP. Based on that value, I want to do specific tasks. Could you please help me in this regard to identify the selected tab name using SAP GUI Scripting.
Hello.
You can use Scripting Tracker Application (an tool developed from Stefan Schnell) to identify tab Name.
As well you can do this by identify them via script. Can you give us an example where you want to identify them. Then it´s much easier to check and give some Input.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Holger,
Thanks a lot for your reply. Please refer below updates,
From Excel, I am feeding the required information and then using the loop, each transaction will be filled with respective values. In this case, I have created the automation template in Excel for the Transcation "MM01". If the material is already extended, some of tab like "Sales: sales org. 1", "Plant Data / Stor.1" tab will be loaded first. Based on the loading screens I have to fill the respective values.
I have validated the selected Tab using the below code,
If Trim(session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP04").Text) = "Sales: sales org. 1" Then
<Code>
Endif
This code checks for the availability of the tab not the selected tab. I want to ensure the Selected tab from the SAP using VBA.
Note: I have used another validation text to check the selected tab,
If IsError(Trim(session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP01").Text)) = True Then
GoTo K
Else
Endif
This is also not not helps.
Let me know, if you need any more information.
Regards,
Vijay.
Hello.
This is a bit more tricky. But you should be able to modify below code to your requirements:
This code I have in an Excel Module.
'-Start of Code-----------------------------------------------------------------
Sub ScanTabs(Area As Object, Application_SAP As SAPFEWSELib.GuiApplication)
Dim Children As Object
Dim i As Integer
Dim Obj As Object
Dim ObjChildren As Object
Dim NextArea As Object
Set Children = Area.Children()
For i = 0 To Children.Count() - 1
Set Obj = Children(CInt(i))
If Obj.Type = "GuiTab" Then
'If Obj.Name = "MyTab" Then
Obj.SetFocus
Debug.Print Obj.Name & " " & Obj.Type & " " & Obj.Text
'End If
End If
If Obj.ContainerType() = True Then
Set ObjChildren = Obj.Children()
If ObjChildren.Count() > 0 Then
Set NextArea = Application_SAP.findByID(Obj.ID)
ScanTabs NextArea, Application_SAP
Set NextArea = Nothing
End If
Set ObjChildren = Nothing
End If
Set Obj = Nothing
Next
Set Children = Nothing
End Sub
'---------------------------------------------------------------------
Sub Test()
Dim SapGuiAuto As Object
Dim Application_SAP As SAPFEWSELib.GuiApplication
Dim Connection As SAPFEWSELib.GuiConnection
Dim Session As SAPFEWSELib.GuiSession
Dim UserArea As SAPFEWSELib.GuiUserArea
Dim TabStrip As SAPFEWSELib.GuiTabStrip
Set SapGuiAuto = GetObject("SAPGUI")
If Not IsObject(SapGuiAuto) Then
Exit Sub
End If
Set Application_SAP = SapGuiAuto.GetScriptingEngine()
If Not IsObject(Application_SAP) Then
Exit Sub
End If
Set Connection = Application_SAP.Connections(0)
If Not IsObject(Connection) Then
Exit Sub
End If
Set Session = Connection.Sessions(0)
If Not IsObject(Session) Then
Exit Sub
End If
'-Get user or tab strip area and scan it recursively
'Set UserArea = Session.findByID("wnd[0]")
'ScanTabs UserArea, Application_SAP
Set TabStrip = Session.findByID("wnd[0]/usr/tabsTABSPR1")
ScanTabs TabStrip, Application_SAP
Set TabStrip = Nothing
Set UserArea = Nothing
End Sub
'-End of Code-------------------------------------------------------------------
You Need to reference to SAP Scripting API:
Then you got an Output like this:
Where 'SP01' is Name, 'GuiTab' is Type and 'Basic Data 1' is Text of object.
You should be able to make your own code for checking all available Tabs and perform required updates. E.g. With 'Select Case'.method.
Hope this helps.
Br, Holger
Thanks Holger. Your code is working fine. But it gives the available tabs in the View. My requirement is, I want know which Tab I am currently in. The use case is,
If the Material is being modified first time,
In this case, user will see "Basic Data 1" always in the screen and then the available tabs will be selected sequentially.
If the Material is being modified more than one time:
In this case, Basic Data 1 will be displayed. If the Tax values are not there, then it will go to "Tax Data" tab and then it will return to Basic Data 1 tab, and then the available tabs will be selected sequentially.
If the Material is not extended to the plant, while extending it will be in Specific tab:
In this case, Plant Storage 1 tab is displayed by default. User have to enter a data and save the view.
To address the above cases, I want to ensure the the current tab where users is accessing the details.
Is it possible to get that tab name using your code?
Regards,
Vijay.
Hello.
Sure. This is much easier as you just Need to get Text from selected tab:
This can be achieved with below code or one single line in your existing Code
Session.findByID("wnd[0]/usr/tabsTABSPR1").SelectedTab.Text
'-Start of Code-------------------------------------------------------
Sub Test()
Dim SapGuiAuto As Object
Dim Application_SAP As SAPFEWSELib.GuiApplication
Dim Connection As SAPFEWSELib.GuiConnection
Dim Session As SAPFEWSELib.GuiSession
Dim TabStrip As SAPFEWSELib.GuiTabStrip
Dim SelectedTab As SAPFEWSELib.GuiTab
Set SapGuiAuto = GetObject("SAPGUI")
If Not IsObject(SapGuiAuto) Then
Exit Sub
End If
Set Application_SAP = SapGuiAuto.GetScriptingEngine()
If Not IsObject(Application_SAP) Then
Exit Sub
End If
Set Connection = Application_SAP.Connections(0)
If Not IsObject(Connection) Then
Exit Sub
End If
Set Session = Connection.Sessions(0)
If Not IsObject(Session) Then
Exit Sub
End If
Set TabStrip = Session.findByID("wnd[0]/usr/tabsTABSPR1")
Set SelectedTab = TabStrip.SelectedTab
MsgBox SelectedTab.Text
Set SelectedTab = Nothing
Set TabStrip = Nothing
End Sub
'-End of Code-------------------------------------------------------------------
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.