cancel
Showing results for 
Search instead for 
Did you mean: 

Untill Loop in SAP GUI

0 Kudos

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


Accepted Solutions (1)

Accepted Solutions (1)

daniel_mccollum
Active Contributor

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
daniel_mccollum
Active Contributor
0 Kudos

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
0 Kudos

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



Sandra_Rossi
Active Contributor

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

Sandra_Rossi
Active Contributor
Supriyo Banerjee use "do while"
Do While Not Session.FindById("wnd[1]", False) Is Nothing
    Session.FindById("wnd[1]").sendVKey 0
Loop
0 Kudos

@Sandra Rossi Thanks a ton. It works like magic. Really appreciate your help. 🙂

0 Kudos

Thanks a ton Daniel !!

Answers (0)