I am getting Session count zero at code line :
SAPActive.SapSession = (GuiSession)SAPActive.SapConnection.Sessions.Item(0);
Can somebody tell the reason?
I am getting Session count zero at code line :
SAPActive.SapSession = (GuiSession)SAPActive.SapConnection.Sessions.Item(0);
Can somebody tell the reason?
That means you dont have active sessions. After a connection is stablished a session is made over it and for it to be made the scripts must be enabled on the server. The easiest way to check its loging manualy to the instance then press Alt+F12 and check if the "Script Recording and Playback..." its enabled, if its grayed out it means scripting its disabled on the serverside. to activate them set the parameter "sapgui/user_scripting" to True using tcode RZ11. Remember if you want the parameter to stay that way after the instance is restarted you have to add it to the profile using tcode RZ10.
with that parameter enabled use this code:
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
set connection= application.openconnection("SapGui connection Descrition here", True) 'error
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
this will open a new connection and then select the respective session for you to work.