GRC
HR
SCM
CRM
BI


Article

 

SAPGUI System Definitions in DCOM Connector 4.6D

by Thomas G. Schuessler | SAPinsider

April 1, 2001

by Thomas G. Schuessler, ARASoft SAPinsider - 2001 (Volume 2), April (Issue 2)
 

There are two types of applications that can be built based on the SAP DCOM Connector (SDC): server-based applications and desktop applications. This article will be more useful to you if you are interested in the latter type, but some of the information will also apply to the former.

     Before 4.6D, you had to define any SAP system you wanted to log on to from an SDC-based application in the Windows Registry. This was accomplished using either the SDC Administration facilities (see Figure 1) or the API provided by the SDC CCADMINLib.CCRegistry component.¹

     SDC originally did not take into account SAP systems already defined in the saplogon.ini file for SAPGUI. As a consequence, these systems had to be defined redundantly in the Windows Registry and any changes had to be made in two locations. While this is only a minor issue for server applications, since SAPGUI is typically not used a lot on server machines, it was somewhat annoying for developers and users of SDC-based desktop applications. The 4.6D version of SDC, which can be used with any SAP back-end system running release 3.1 or later, has been extended to automatically leverage any SAP system defined in saplogon.ini. Redundant system definitions are no longer necessary!

Figure 1 Destination Administration with the SAP DCOM Connector

The Freeware Logon Component

A while ago, I had written a freeware component (the ARAsoft DCOM Connector Logon Component for SAP R/3) that can be used in desktop applications to provide a user dialog encapsulating the logon process. Figure 2 shows a screen shot of that component in action.

Figure 2 The ARAsoft DCOM Connector Logon Component

     All destinations (SAP systems) are listed on the left-hand side. The user can look at the destination details and enter the required information for logon (client, userid, password, and language). Instead of requiring users to memorize the ISO code of the language they want to use, the component offers a drop-down combo box that lists the name of the language in the language itself.

     Writing a client program that uses the component is very easy. Listing 1 shows the required code in Visual Basic. 

     Instead of IRFC32Lib.RfcSession, any session class generated by SDC into a proxy DLL could be used.

     Originally, the component immediately retrieved not only the list of destinations, but also the details of each destination. This performed nicely, since each access to a destination's details just required one access to the Windows Registry, which is a reasonably fast endeavor. Once I started to use SDC 4.6D, though, I noticed that it took several seconds for the logon dialog to come up. The reason for this performance degradation is that the CCADMINLib.CCRegistry API opens and closes the saplogon.ini file every time the details of a destination taken from that file are accessed. The obvious solution is to retrieve only the list of destinations initially, and access the detail data "just-in-time" as needed.

     Since you may want to build your own visual logon component for desktop applications, or build a non-visual component that accesses destinations for use in a server-based application, I have decided to share the required source code with you.



Dim oSession As IRFC32Lib.RfcSession
Dim sErrorMessage As String
Dim ldSuccess As ARAsoftDLC.LOGONDIALOGRESULT
 
  Set oSession = New IRFC32Lib.RfcSession
  ldSuccess = ARAsoftDLC.LogonDialog(oSession, sErrorMessage)
 
  If ldSuccess = Success Then
    MsgBox "Okay"
  ElseIf ldSuccess = Failure Then
    MsgBox sErrorMessage
  ElseIf ldSuccess = Cancel Then
    ' User cancelled the logon dialog
  End If
Listing 1 Sample Client Code

     Listing 2 contains the source code of the GetDestinations method that initially retrieves the list of all destinations. The method returns an object of type Destinations, the source code of which is given in Listing 3.



Private Function GetDestinations() As Destinations
Dim rsX As Variant
Dim destinationX As Destination
Dim destinationsX As Destinations
  On Error GoTo EH
  Set rsX = oCCRegistry.GetDestinations
  rsX.MoveFirst
  Set destinationsX = New Destinations
  Do Until rsX.EOF
    If Not destinationsX.Exists(CStr(rsX("Destination"))) Then
      Set destinationX = New Destination
      destinationX.Name = rsX("Destination")
      destinationX.ConnectString = rsX("Options")
      destinationsX.AddInternal destinationX
    End If
    rsX.MoveNext
  Loop
  Set GetDestinations = destinationsX
  Exit Function
EH:
  Err.Raise Err.Number, ERRSOURCE, _
    ERRSOURCE & ".GetDestinations (Line " & CStr(Erl) & ")" & _
    vbCrLf & Err.Description
End Function
Listing 2 The GetDestinations Method



Private colX As Collection

Public Property Get Item(vntIndexKey As Variant) As Destination
  Set Item = colX(vntIndexKey)
End Property

Public Property Get NewEnum() As IUnknown
  Set NewEnum = colX.[_NewEnum]
End Property

Friend Sub AddInternal(ByVal Item As Destination)
  colX.Add Item, Item.Name
End Sub

Friend Function Exists(ByVal Name As String) As Boolean
  On Error Resume Next
  colX.Item Name
  Exists = IIf(Err.Number = 0, True, False)
  Err.Clear
End Function

Private Sub Class_Initialize()
  Set colX = New Collection
End Sub
Private Sub Class_Terminate()
  Set colX = Nothing
End Sub
Listing 3 The Destinations Class

     In Listing 2, note the code (Line 10) that checks whether a destination with the specified name already exists in the collection. This is necessary because duplicate names can exist if - using a previous version of SDC - an SDC destination was created with a name that is also used in saplogon.ini. Since - according to SAP - only the first entry can ever be used to log on to SAP, we simply ignore any subsequent entries with the same name.

     Destinations is a simple collection class that allows a client program to access an individual destination via the (default) Item property.

     Class Destination offers all relevant properties of a destination. Method Initialize contains the code that retrieves the detail information for a destination. See Listing 4.



Const CLASSNAME = "Destination"
Const ERRSOURCE = LIBNAME + "." + CLASSNAME

Private sName As String
Private sConnectString As String

Private sUserId As String
Private sClient As String
Private sLanguage As String

Private bUsesLoadBalancing As Boolean
Private bTrace As Boolean
Private sHostName As String

Private sSystemNumber As String

Private sSystemId As String
Private sGroupName As String

Private bInitialized As Boolean
Public Function CreateConnectionString(pPassword As String, _
		Optional pUserId, _
		Optional pClient, _
		Optional pLanguage, _
		Optional pTrace) As String
Dim s As String
  Initialize
  s = "{ type=3"
  If bUsesLoadBalancing Then
    s = s & " mshost=" & sHostName & " group=" & sGroupName & " r3name=" & sSystemId
  Else
    s = s & " ashost=" & sHostName & " sysnr=" & sSystemNumber
  End If
  s = s & " passwd=" & pPassword
  If IsMissing(pUserId) Then
    s = s & " user=" & sUserId
  Else
    s = s & " user=" & pUserId
  End If
  If IsMissing(pClient) Then
    s = s & " client=" & sClient
  Else
    s = s & " client=" & pClient
  End If
  If IsMissing(pLanguage) Then
    s = s & " lang=" & sLanguage
  Else
    s = s & " lang=" & pLanguage
  End If
  If IsMissing(pTrace) Then
    s = s & " trace=" & IIf(bTrace, "1", "0")
  Else
    s = s & " trace=" & IIf(pTrace, "1", "0")
  End If
  s = s & " }"
  CreateConnectionString = s
End Function

Public Property Get Name() As String
  Name = sName
End Property
Friend Property Let Name(ByVal sNewValue As String)
  If sName = "" Then
    sName = sNewValue
  Else
    Err.Raise ERR3110, ERRSOURCE, ERR3110Text
  End If
End Property
Public Property Get ConnectString() As String
  ConnectString = sConnectString
End Property
Friend Property Let ConnectString(ByVal sNewValue As String)
  sConnectString = sNewValue
End Property

Public Property Get UserId() As String
  Initialize
  UserId = sUserId
End Property
Public Property Get Client() As String
  Initialize
  Client = sClient
End Property
Public Property Get Language() As String
  Initialize
  Language = sLanguage
End Property

Public Property Get UsesLoadBalancing() As Boolean
  Initialize
  UsesLoadBalancing = bUsesLoadBalancing
End Property

Public Property Get Trace() As Boolean
  Initialize
  Trace = bTrace
End Property

Public Property Get HostName() As String
  Initialize
  HostName = sHostName
End Property

Public Property Get SystemNumber() As String
  Initialize
  SystemNumber = sSystemNumber
End Property

Public Property Get SystemId() As String
  Initialize
  SystemId = sSystemId
End Property

Public Property Get GroupName() As String
  Initialize
  GroupName = sGroupName
End Property

Private Sub Initialize()
Dim rsX As Recordset
  If bInitialized Then Exit Sub
  Set rsX = oCCRegistry.GetOptionsAsRecord(sName)
  rsX.MoveFirst
  bUsesLoadBalancing = IIf(rsX("loadbal") = 0, False, True)
  bTrace = IIf(rsX("trace") = 1, True, False)
  sClient = rsX("client")
  sGroupName = rsX("group")
  sHostName = IIf(bUsesLoadBalancing, rsX("mshost"), rsX("ashost"))
  sLanguage = rsX("lang")
  sSystemId = rsX("r3name")
  sSystemNumber = rsX("sysnr")
  sUserId = rsX("user")
  bInitialized = True
End Sub
Listing 4 The Destinations Class

Build Your Own Components

Based on the source code, you can now build your own components that offer optimum performance even when used with SDC 4.6D.

     If you want to save some time and would like to receive a free copy of the ARAsoft DCOM Connector Logon Component for SAP R/3, please send an e-mail to products@arasoft.de.


Thomas G. Schuessler is the founder of ARAsoft (www.arasoft.de), a company offering products, consulting, custom development, and training to a worldwide base of customers. The company specializes in integration between SAP and non-SAP components and applications. ARAsoft offers various products for BAPI-enabled programs on the Windows and Java platforms. These products facilitate the development of desktop and Internet applications that communicate with R/3. Thomas is the author of SAP's CA925 "Developing BAPI-enabled Web Applications with Visual Basic" and CA926 "Developing BAPI-enabled Web Applications with Java" classes, which he teaches in Germany and in English-speaking countries. Thomas is a regularly featured speaker at SAP TechEd and SAPPHIRE conferences. Prior to founding ARAsoft in 1993, he worked with SAP AG and SAP America for seven years. Thomas can be contacted at thomas.schuessler@sap.com or at tgs@arasoft.de.
¹ Cf. my article "Destination and Session Managment for the SAP DCOM Connector" in the March/April 2000 issue of the SAP Professional Journal (www.SAPpro.com) for the documentation of this API.

An email has been sent to:






More from SAPinsider



COMMENTS

Please log in to post a comment.

No comments have been submitted on this article. Be the first to comment!


SAPinsider
FAQ