cancel
Showing results for 
Search instead for 
Did you mean: 

Using If condition to check if a particular window is displayed in vbs

Former Member
0 Kudos

Hi All,

Am new to scripting and SAP. So tolerate with me if i am asking the obvious.

I have recorded the function of triggering a IDOC using the recording option in SAP GUI. The code is like,

session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "xxx"

session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "xxx"

session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "xxx"

session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"

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

session.findById("wnd[1]/usr/radMULTI_LOGON_OPT2").select

session.findById("wnd[1]/usr/radMULTI_LOGON_OPT2").setFocus

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

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

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

My question is how to use IF or any other conditional statement to check if a window is displayed and then proceed with a particular action. Something like,

If wnd1 is displayed do

session.findById("wnd[1]/usr/radMULTI_LOGON_OPT2").select

session.findById("wnd[1]/usr/radMULTI_LOGON_OPT2").setFocus

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

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

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

Else do

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

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

Thanks in advance

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Or you can use the window title as a checkpoint.. like in the example below I am running a process until at some point the window with title "Change PM Orders: List of Orders" is displayed, at which point the loop is exited: You can use variations of this logic:

do while not session.findById("wnd[0]/titl").Text = "Change PM Orders: List of Orders"

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

session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/subSUB_KOPF:SAPLCOIH:1102/btn%#AUTOTEXT001").press

session.findById("wnd[1]/usr/btnADOWN").press

session.findById("wnd[1]/usr/sub:SAPLBSVA:0201[0]/radJ_STMAINT-ANWS[0,0]").select

session.findById("wnd[1]/usr/sub:SAPLBSVA:0201[0]/radJ_STMAINT-ANWS[0,0]").setFocus

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

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

session.findById("wnd[1]/usr/subNOTIFICATION:SAPLIQS0:7010/tabsTSTRIP_7010/tabp$TS02").select

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

loop

Hope this helps..

Umur

Former Member
0 Kudos

Hi there,

although not the most elegant solution, this could work:

Set SAPsession = session.Children

windowCnt = SAPsession.Count

if windowCnt = 1 then

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

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

Else

session.findById("wnd[1]/usr/radMULTI_LOGON_OPT2").select

session.findById("wnd[1]/usr/radMULTI_LOGON_OPT2").setFocus

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

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

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

End if

cheers,

graeme