Example 

Procedure

To run the following example, create a new Visual Basic project by following these steps:

  1. Right-click on tool box and choose Component s. The Component s dialog box appears.
  2. In the Control tab, search for SAPBrowser in the list.
  3. Select the SAPBrowser check box and choose OK .
  4. Drag (or double click) the SAPBrowser icon in the tool box to Form1.
  5. Resize the control properly on Form1.
  6. Create two command buttons and name them cmdBrowse and cmdProperty .
  7. Double click anywhere on Form1 to see the Visual Basic code window.
  8. Copy the code below and paste it into the code window.
  9. Save and run the project. If all the required components are installed on your machine, you should see the R/3 logon screen when you run the project.

Code

Option Explicit

Private moRepObj As Object

Private moLogonObj As Object

Dim moConn As Object

Private Sub cmdBrowse_Click()

Dim oAppHiers As Object

Dim oAppHier As Object

Set moRepObj = CreateObject("SAP.RepositoryServicesonline.1")

If moRepObj Is Nothing Then

MsgBox "Could not create Repository object", vbInformation

Exit Sub

End If

Set moLogonObj = CreateObject("SAP.LogonControl.1")

If Not moLogonObj Is Nothing Then

Set moConn = moLogonObj.NewConnection

If Not moConn Is Nothing Then moConn.Logon

Else

MsgBox "Could not create logon object", vbInformation

Exit Sub

End If

moRepObj.Connection = moConn

SAPBrowse1.EnableBAPITab True

Set oAppHiers = moRepObj.ApplicationHierarchies()

If SAPBrowse1.Connect(moRepObj) Then

For Each oAppHier In oAppHiers

SAPBrowse1.AddBAPIAppObject oAppHier

Next

End If

End Sub

Private Sub cmdProperty()

SAPBrowse1.ShowPropertyWindow Me.Hwnd

End Sub

Private Sub Form_Unload(Cancel As Integer)

moConn.Logoff

End Sub