cancel
Showing results for 
Search instead for 
Did you mean: 

Find session with VBScript

Former Member
0 Kudos

I recorded a code which does a GL line item entry via t-code MIRO. I've 5 sessions running, each session is a different t-code.

I am using the 3rd session for t-code MIRO. All other sessions use a different t-codes, e.g. 1st = VA03, 2nd = MB5B, 4th = F.01 & 5th = ME23N.

I know that SAP refers to the first session as Set session = connection.Children(0).

So, in order to refer to the 3rd session, I amended the code to be like this:

Set session = connection.Children(2)

When I double-click on the .vbs file, it works perfectly.

However, if I changed to another session to use MIRO, say, the 5th session, then the code does not work anymore, as now, the 3rd session is F.01 and the VBScript does not apply to t-code F.01 because it's a completely different layout.

Double-clicking the file does not work. However, drag & drop does work.

I do not want to drag & drop all the time, I just want to double-click it.

How do I actually write a loop in order to cycle through all the sessions and find the right session to execute the code perfectly?

I don't plan to use the VBScript to open the t-code MIRO as I'm in the middle of entering some other things in MIRO and I just want to run the script to automate some part of the process in MIRO only.

Any ideas that I can do this?

Thanks in advance for your help.


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(2)
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]/usr/subHEADER_AND_ITEMS:SAPLMR1M:6005/subITEMS:SAPLMR1M:6010/tabsITEMTAB/tabpITEMS_G/L/ssubTABS:SAPLMR1M:6040/ssubSACHKONTO:SAPLFSKB:0100/tblSAPLFSKBTABLE/ctxtACGL_ITEM-HKONT[1,0]").setFocus
session.findById("wnd[0]/usr/subHEADER_AND_ITEMS:SAPLMR1M:6005/subITEMS:SAPLMR1M:6010/tabsITEMTAB/tabpITEMS_G/L/ssubTABS:SAPLMR1M:6040/ssubSACHKONTO:SAPLFSKB:0100/tblSAPLFSKBTABLE").verticalScrollbar.position = 0
session.findById("wnd[0]/usr/subHEADER_AND_ITEMS:SAPLMR1M:6005/subITEMS:SAPLMR1M:6010/tabsITEMTAB/tabpITEMS_G/L/ssubTABS:SAPLMR1M:6040/ssubSACHKONTO:SAPLFSKB:0100/tblSAPLFSKBTABLE/ctxtACGL_ITEM-HKONT[1,0]").text = "66100100"
session.findById("wnd[0]/usr/subHEADER_AND_ITEMS:SAPLMR1M:6005/subITEMS:SAPLMR1M:6010/tabsITEMTAB/tabpITEMS_G/L/ssubTABS:SAPLMR1M:6040/ssubSACHKONTO:SAPLFSKB:0100/tblSAPLFSKBTABLE/cmbACGL_ITEM-SHKZG[3,0]").key = "S"
session.findById("wnd[0]/usr/subHEADER_AND_ITEMS:SAPLMR1M:6005/subITEMS:SAPLMR1M:6010/tabsITEMTAB/tabpITEMS_G/L/ssubTABS:SAPLMR1M:6040/ssubSACHKONTO:SAPLFSKB:0100/tblSAPLFSKBTABLE/txtACGL_ITEM-WRBTR[4,0]").text = "84.95"
session.findById("wnd[0]/usr/subHEADER_AND_ITEMS:SAPLMR1M:6005/subITEMS:SAPLMR1M:6010/tabsITEMTAB/tabpITEMS_G/L/ssubTABS:SAPLMR1M:6040/ssubSACHKONTO:SAPLFSKB:0100/tblSAPLFSKBTABLE/ctxtACGL_ITEM-MWSKZ[6,0]").Text = "DB"
session.findById("wnd[0]/usr/subHEADER_AND_ITEMS:SAPLMR1M:6005/subITEMS:SAPLMR1M:6010/tabsITEMTAB/tabpITEMS_G/L/ssubTABS:SAPLMR1M:6040/ssubSACHKONTO:SAPLFSKB:0100/tblSAPLFSKBTABLE/ctxtACGL_ITEM-GSBER[10,0]").text = "DE74"
session.findById("wnd[0]/usr/subHEADER_AND_ITEMS:SAPLMR1M:6005/subITEMS:SAPLMR1M:6010/tabsITEMTAB/tabpITEMS_G/L/ssubTABS:SAPLMR1M:6040/ssubSACHKONTO:SAPLFSKB:0100/tblSAPLFSKBTABLE/ctxtACGL_ITEM-PRCTR[13,0]").text = "8043090000"
session.findById("wnd[0]/usr/subHEADER_AND_ITEMS:SAPLMR1M:6005/subITEMS:SAPLMR1M:6010/tabsITEMTAB/tabpITEMS_G/L/ssubTABS:SAPLMR1M:6040/ssubSACHKONTO:SAPLFSKB:0100/tblSAPLFSKBTABLE/btnACGL_ITEM-EOBJ[14,0]").press
session.findById("wnd[1]/usr/sub:SAPLKEAK:0400/ctxtRKEAK-FIELD[3,24]").text = "5901003679"
session.findById("wnd[1]/usr/sub:SAPLKEAK:0400/ctxtRKEAK-FIELD[4,24]").text = "10"
session.findById("wnd[1]/tbar[0]/btn[18]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press

Accepted Solutions (0)

Answers (2)

Answers (2)

stefan_schnell
Active Contributor
0 Kudos

Hello Edmund,

try this:

For i = 0 To connection.children().count() - 1
  MsgBox connection.children(CInt(i)).Info().Transaction()
Next

With the property transaction you get the code and this is a way to differ the sessions and select the session you need with the TAC MIRO.

Hope it works.

Cheers

Stefan

tomasz_lawrynowicz2
Discoverer
0 Kudos

Hi Edmund,

forgive me, but probably some don't understand.

Are you sure you need a few (5) concurrent sessions to perform VA03, MB5B, F01 ME23N

This method (as you descripe) uses the opened sessions and joins them

try:

- record and perform on the first Children (0)

or

- call the selector opened sessions and choose which do you want to do (ie. with MS Excel or Java)