cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with SAP session numbers by VBA

aleksandra-0601
Explorer
0 Kudos
299

Hello,

I have a big problem with an issue which should be very simple, I think. I cannot set session to get transaction by a number. After a lot of tests a conclusion is that my SAP does not accept the number of session which I retrieve, but assign to each session other number - depending of the order of opening the sessions. Is it possible that this is a matter of settings? Can I adjust it? Please help

Dim SessionNumber As Long

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.createSession

SessionNumber = session.info.SessionNumber

Set session = Connection.Children(CLng(SessionNumber - 1))

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

session.findById("wnd[0]/tbar[0]/okcd").Text = "/nva02"

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

session.findById("wnd[0]/usr/ctxtVBAK-VBELN").Text = Target.Offset(0, -12).Value

session.findById("wnd[0]/usr/ctxtVBAK-VBELN").caretPosition = 10

session.findById("wnd[0]/usr/btnBT_SUCH").press

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

Set session = Connection.Children(CLng(SessionNumber))

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

session.findById("wnd[0]/tbar[0]/okcd").Text = "/nZOTC0207_01"

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

session.findById("wnd[0]/usr/tabsTABSTRIP_B12/tabpPUSH_A/ssub%_SUBSCREEN_B12:ZEOTC0092_01_NEW:0200/ctxtS_MATNR2-LOW").SetFocus

session.findById("wnd[0]/usr/tabsTABSTRIP_B12/tabpPUSH_A/ssub%_SUBSCREEN_B12:ZEOTC0092_01_NEW:0200/ctxtS_MATNR2-LOW").caretPosition = 0

session.findById("wnd[0]/usr/tabsTABSTRIP_B12/tabpPUSH_C").Select

session.findById("wnd[0]/usr/tabsTABSTRIP_B12/tabpPUSH_C/ssub%_SUBSCREEN_B12:ZEOTC0092_01_NEW:0100/ctxtS_MATNR1-LOW").Text = Target.Offset(0, iGTINposition - 13).Value

session.findById("wnd[0]/usr/tabsTABSTRIP_B12/tabpPUSH_C/ssub%_SUBSCREEN_B12:ZEOTC0092_01_NEW:0100/ctxtS_WERKS1-LOW").Text = Target.Offset(0, -2).Value

session.findById("wnd[0]/usr/tabsTABSTRIP_B12/tabpPUSH_C/ssub%_SUBSCREEN_B12:ZEOTC0092_01_NEW:0100/ctxtS_WERKS1-LOW").SetFocus

session.findById("wnd[0]/usr/tabsTABSTRIP_B12/tabpPUSH_C/ssub%_SUBSCREEN_B12:ZEOTC0092_01_NEW:0100/ctxtS_WERKS1-LOW").caretPosition = 4

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

End If

Accepted Solutions (0)

Answers (0)