on 11-13-2017 6:44 AM
Any ideas how to debug OpenConnection
i.e.
'connect to target SAP System
Set SAPConn = SAPApp.OpenConnection(System)
I am getting an error when connecting to a target system, however the error is throwing up the following
Hostname '/SYSID=ABC /H/(ipaddresshere)/S/(porthere)' unknown
when using OpenConnectionByConnectionString & declaring ''/H/(ipaddresshere)/S/(porthere)"
it will connect as expected.
The System ID in the error is the declared System, & the host appears correct apart from the leading "/SYSID=ABC" component of the string.
Any ideas why the OpenConnection fucntion is failing?
I've crafted a connectionstring parser for the xml that will launch the connection to the expected SAP system, any suggestions on improvements gratefully received.
Sample code below.
Connector logic:
'connect to target SAP System
Set SAPConn = SAPApp.OpenConnection(system, True, True)
If SAPConn Is Nothing Then
systemString = SAPUILandscape(system)
If systemString <> "" Then
Set SAPConn = SAPApp.OpenConnectionByConnectionString(systemString)
Else:
Call Show_Script_status(system & " Not Found")
Exit Sub
End If
End If
'Fill out SAP Logon screen
Set session = SAPConn.Sessions(0)
session.findById("wnd[0]/usr/txtRSYST-MANDT").text = clientID
session.findById("wnd[0]/usr/txtRSYST-BNAME").text = userID
session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = Password
<br>
SAPUILandscape function below:
Function SAPUILandscape(system)
Dim fpath As String
Dim sapfiles As String
Dim SAPUILandscapefile As String
Dim ConnString As String
Dim id As Variant
Dim isValid As Boolean
Dim testing As Boolean
Dim AttribName As String
Dim AttribServer As String
Dim CurrentXpath As String
Dim xmlDoc As MSXML2.DOMDocument60
Dim xmlSelection As MSXML2.IXMLDOMSelection
Dim xmlAttributes As MSXML2.IXMLDOMNamedNodeMap
Dim xmlItems As MSXML2.IXMLDOMAttribute
Set xmlDoc = New MSXML2.DOMDocument60
testing = False
'xml structures
AttribName = "systemid"
AttribServer = "server"
'alt AttribTag = "systemid"
CurrentXpath = "//Landscape/Services/Service[@" & AttribName & "='" & system & "']"
'find SAPUILandscape.xml
fpath = Environ$("AppData")
sapfiles = "SAP\Common\"
SAPUILandscapefile = "SAPUILandscape.xml"
If Right(fpath, 1) <> "\" Then
fpath = fpath & "\"
End If
fpath = fpath & sapfiles & SAPUILandscapefile
xmlDoc.async = False
If xmlDoc.Load(fpath) Then
'successfully loaded xml
Set xmlSelection = xmlDoc.SelectNodes(CurrentXpath)
If xmlSelection.Length = 0 Then
'path not found
isValid = False
Else:
Set xmlAttributes = xmlSelection.Item(0).Attributes
For Each xmlItems In xmlAttributes
If xmlItems.BaseName = AttribServer Then
ConnString = xmlItems.NodeValue
isValid = True
Exit For
End If
Next xmlItems
End If
Else:
If testing = True Then
' The document failed to load.
Dim strErrText As String
Dim xPE As IXMLDOMParseError
' Obtain the ParseError object
Set xPE = xmlDoc.parseError
With xPE
strErrText = "Your XML Document failed to load" & _
"due the following error." & vbCrLf & _
"Error #: " & .ErrorCode & ": " & xPE.reason & _
"Line #: " & .Line & vbCrLf & _
"Line Position: " & .linepos & vbCrLf & _
"Position In File: " & .filepos & vbCrLf & _
"Source Text: " & .srcText & vbCrLf & _
"Document URL: " & .Url
End With
MsgBox strErrText, vbExclamation
isValid = False
Else:
isValid = False
End If
End If
If isValid = True Then
'connection found in landscape
SAPUILandscape = formatConnString(ConnString)
Else:
'connection not found in landscape
SAPUILandscape = ""
End If
End Function
Function formatConnString(ConnectionString)
Dim hostPrefix As String
Dim host As String
Dim id As Variant
Dim portPrefix As String
Dim port As String
Dim delimiter As String
hostPrefix = "/H/"
portPrefix = "/S/"
delimiter = ":"
id = Split(ConnectionString, delimiter, -1, vbTextCompare)
host = id(0)
port = id(1)
formatConnString = hostPrefix & host & portPrefix & port
End Function
<br>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got this working without modifying this snippet. I just dealt with the various objects better before getting to this chunk of code.
User | Count |
---|---|
90 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.