on 08-06-2020 3:13 PM
Hi I am new to SAP GUI. I want to run loop until the next screen appears. Below I am sharing the GUI script I recorded and highlighted the area where I need the loop and also sharing the screen where I want to use that loop. Your help will be appreaciated.
Need this repetitively until next screen appears
"session.findById("wnd[1]").sendVKey 0"
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 = "va01"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtVBAK-AUART").text = "ZCRE"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[1]/usr/tabsMYTABSTRIP/tabpRFAK/ssubSUB1:SAPLV45C:0304/ctxtVBRK-VBELN").text = "6214557"
session.findById("wnd[1]/usr/tabsMYTABSTRIP/tabpRFAK/ssubSUB1:SAPLV45C:0304/ctxtVBRK-VBELN").caretPosition = 7
session.findById("wnd[1]/tbar[0]/btn[5]").press
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4415/cmbVBAK-FAKSK").key = " "
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4415/cmbVBAK-FAKSK").setFocus
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4415/subSUBSCREEN_TC:SAPMV45A:4902/subSUBSCREEN_BUTTONS:SAPMV45A:4050/btnBT_PKON").press
session.findById("wnd[0]/mbar/menu[1]/menu[12]").select
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").setCurrentCell -1,""
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectColumn "ANZEIGEPOS"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectColumn "AUSGABETEXT"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectColumn "FELD"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectedRows = "0"
session.findById("wnd[0]/tbar[1]/btn[2]").press
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\01/ssubSUBSCREEN_BODY:SAPMV45A:4301/cmbVBAK-AUGRU").key = "001"
session.findById("wnd[0]/tbar[0]/btn[3]").press
session.findById("wnd[0]").sendVKey 11
session.findById("wnd[0]/tbar[0]/btn[15]").press
session.findById("wnd[0]/tbar[0]/okcd").text = "VF01"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 11
this snippet will check the existence of a thing, then do something.
If Not session.findById("wnd[1]", False) Is Nothing Then
session.findById("wnd[1]").sendVKey 0
End If
or if smashing enter till gone...
Do While Not Session.FindById("wnd[1]", False) Is Nothing
Session.FindById("wnd[1]").sendVKey 0
Loop
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
though that's just hitting enter in this context, I'd suggest checking for buttons & pressing them.
If Not session.findById("wnd[1]/usr/btnBUTTON_2", False) Is Nothing Then
session.findById("wnd[1]/usr/btnBUTTON_2").press
End If
& you can get in infinite loops if the enter doesnt get rid of the pop-up.
another strategy is to check for meaning in the pop-up & make decisions
Dim pop As SAPFEWSELib.GuiModalWindow
'check for popups, IE Table is cross Client, locked, etc
If Not Session.FindById("wnd[1]", False) Is Nothing Then
Set pop = Session.FindById("wnd[1]")
If InStr(pop.text, "Locked Data") > 0 Then
'Table locked
Call SetScriptStatus(pop.text)
Session.FindById("wnd[1]/usr/btnBUTTON_2").press
Session.FindById("wnd[0]/tbar[0]/btn[15]").press
Session.FindById("wnd[0]/tbar[0]/btn[15]").press
End
ElseIf InStr(pop.PopupDialogText, "not modifiable") > 0 Then
'Table not modifiable
Call SetScriptStatus(pop.PopupDialogText)
Cells(1, MsgCol) = pop.PopupDialogText
Session.FindById("wnd[1]/tbar[0]/btn[0]").press
Session.FindById("wnd[0]/tbar[0]/btn[15]").press
Session.FindById("wnd[0]/tbar[0]/btn[15]").press
End
Else:
'other conditions
End If
End If
Hi Daniel,
Thanks for your answer.
But the same issue still persist. For more clarity I am here by explaining steps in more detail.
Code works fine without this particular screen. I am sharing more details.
Code works fine till this
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 = "va01"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtVBAK-AUART").text = "zcre"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[1]/usr/tabsMYTABSTRIP/tabpRFAK/ssubSUB1:SAPLV45C:0304/ctxtVBRK-VBELN").text = "6211603"
session.findById("wnd[1]/usr/tabsMYTABSTRIP/tabpRFAK/ssubSUB1:SAPLV45C:0304/ctxtVBRK-VBELN").caretPosition = 7
session.findById("wnd[1]/tbar[0]/btn[5]").press
After this if the below screen appears I have to hit Enter repetitively till the next screen comes like 3 times this screen appeared it may be 50 or 100. I need to hit Enter till it gone. GUI Script was below
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[1]").sendVKey 0
After this screen gone. This below code works fine
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4415/cmbVBAK-FAKSK").key = " "
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4415/cmbVBAK-FAKSK").setFocus
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4415/subSUBSCREEN_TC:SAPMV45A:4902/subSUBSCREEN_BUTTONS:SAPMV45A:4050/btnBT_PKON").press
session.findById("wnd[0]").sendVKey 32
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").setCurrentCell -1,""
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectColumn "ANZEIGEPOS"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectColumn "AUSGABETEXT"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectColumn "FELD"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectedRows = "0"
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\01/ssubSUBSCREEN_BODY:SAPMV45A:4301/cmbVBAK-AUGRU").key = "001"
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 11
session.findById("wnd[0]/tbar[0]/btn[15]").press
session.findById("wnd[0]/tbar[0]/okcd").text = "vf01"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 11
banerjee.supriya001 You say "issue still persist" but Daniel code checks the presence of a modal window at level 1 (If Not session.findById("wnd[1]", False) Is Nothing Then ...), could you clarify why it wouldn't work?
Getting the "Loop without Do" error
Do While Not Session.FindById("wnd[1]", False) Is Nothing
Session.FindById("wnd[1]").sendVKey 0
Loop
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.