|
<< Click to Display Table of Contents >> Navigation: All About SAP Interface > SAP r/3 and VB 6.0 > Create SAP - VB 6.0 Connection using SAP ActiveX |
Objective |
|
Support |
|
Contributor |
Albertus Reinandang ( reinandang@yahoo.com ) |
Requirement
All step is already tested using this requirement
1.SAP GUI 6.40 Patch Level 0-21 or SAP GUI 7.10 Patch Level 0 (download)
2.Microsoft Visual Basic 6.0
3.Windows 2000 or XP
In SAP system, there are roles that we must pass through SAP Logon to access SAP feature. SAP Logon need a special codes to be a standard SAP Logon system, which is:
•Client (R/3 System, client number from logon)
> A client in the r/3 system that you want to connect to
•ApplicationServer (Name of Application Server )
> The name of the host that you want to connect to
•SystemNumber ( System Number server SAP )
> Specify the system number (e.g. 00) of the SAP System that you want to connect to
•System ( System ID)
> Specify the system ID (e.g. OSS) of the SAP System that you want to connect to
•User ( User Logon Name )
•Password ( User Password )
•Language ( System Language )
If you not completely all the condition of that code above, you can’t using/accessing a feature in SAP GUI ActiveX, especially “SAP Functions” .
Installed Component
1.Standard VB 6.0 Component
2.SAP ActiveX ( SAPLogonControl and SAPFunctions )
____________________________________________________________________________
SAPLogonControl Concept and Format:
… Declare a New Connection …
… Fill Connection Variable …
… login …
Example:
…
Dim l_Conn As SAPLogonCtrl.Connection
Set l_Conn = SAPLogonControl1.NewConnection
If l_Conn.Logon(0, False) Then
MsgBox "Connect to SAP."
End If
…
>> … LogOn(0,false) … if you set to False then Dialog Login Menu will be appear.
Note : “Connect to SAP” = it’s mean ‘You have Succeed Login to SAP !!’
The following Example show how to used SAP Login Control:
No |
Description |
|
1 |
Difficulty |
Easy ( For beginner ) |
2 |
Microsoft VB 6.0 Component |
Standard EXE |
Procedure:
1.Run Microsoft Visual Basic 6.0
2.Create New Project > "Standard EXE"
4.Add one “ SAPLogonControl ” Component to a Form

No |
Component |
Properties |
Value |
1 |
SAPLogonControl |
Name |
SAPLogonControl1 |
|
|
Caption |
&R/3 Logon |
|
|
Others |
Default |
5.Add OnClik event at SAPLogonControl1 component with code bellow :
Private Sub SAPLogonControl1_Click()
Dim l_Conn As SAPLogonCtrl.Connection
Set l_Conn = SAPLogonControl1.NewConnection
If l_Conn.Logon(0, False) Then
MsgBox "Connect to SAP."
End If
End Sub
6.Press “ Run/Start “ button for testing your code.
____________________________________________________________________________
Create SAP Logon with input dialog
No |
Description |
|
1 |
Difficulty |
Easy ( For beginner ) |
2 |
Microsoft VB 6.0 Component |
Standard EXE |
|
|
TextBox |
Label |
Procedure:
1.Run Microsoft Visual Basic 6.0
2.Create new Project > "Standard EXE"
4.Add one “ SAPLogonControl ” Component to a Form.
5.Add and place it the others component like a picture bellow :

No |
Commponent |
Properties |
Value |
1 |
SAPLogonControl |
Name |
SAPLogonControl1 |
|
|
Caption |
&R/3 Logon |
|
|
Others |
Default |
2 |
TextBox |
Name |
eApplicationServer |
|
|
Text |
Null (Empty) |
3 |
TextBox |
Name |
eSystemNumber |
|
|
Text |
Null (Empty) |
4 |
TextBox |
Name |
eClient |
|
|
Text |
Null (Empty) |
5 |
TextBox |
Name |
eSystem |
|
|
Text |
Null (Empty) |
6 |
TextBox |
Name |
eUsername |
|
|
Text |
Null (Empty) |
7 |
TextBox |
Name |
ePassword |
|
|
Text |
Null (Empty) |
8 |
TextBox |
Name |
eLanguage |
|
|
Text |
Null (Empty) |
6.Add OnClick event at SAPLogonControl1 component with code bellow :
Private Sub SAPLogonControl1_Click()
Dim l_Conn As SAPLogonCtrl.Connection
Set l_Conn = SAPLogonControl1.NewConnection
l_Conn.Client = eClient.Text
l_Conn.ApplicationServer = eApplicationServer.Text
l_Conn.SystemNumber = eSystemNumber.Text
l_Conn.System = eSystem.Text
l_Conn.User = eUsername.Text
l_Conn.Password = ePassword.Text
l_Conn.Language = eLanguage.Text
If l_Conn.Logon(0, True) Then
MsgBox "Connect to SAP."
End If
End Sub
7.Press “ Run/Start “ button for testing your code.
____________________________________________________________________________
Calling and Using RFC/BAPIs from SAP R/3
BAPIs (Business Application Program Interfaces) is SAP business objects held in the Business Object Repository (BOR) encapsulate their data and processes. External access to the data and processes is only possible using specific methods.
RFC (Remote Function Call) is interfaces provided for communication between SAP Systems and with external partners.
The BAPIs and RFC in the R/3 System are currently implemented as function modules which are created and managed in the Function Builder (SE37). Not all SAP user can used a Function Builder. Only user who have an access key from SAP can used all the feature in Function Builder. You can get Access key from http://service.sap.com.
In RFC or BAPI desain there are 5 variable type, which is Import, Export, Changing, Tables and Exceptions. The variable which used generally is Import, Export and Tables.

Import Variable in SAPFunctions is declare as a function “ exports “, while the Export variable is declare as a function “ imports “.
SAPFunctions Concept and Format:
… SAPFunction Connection …
… Calling SAPFunctions …
… Fill (upload) Import/Tables variable in SAP …
… Call (download) Export/Tables variable in SAP …
… Close Connection …
The following Example show how to call RFC :
No |
Description |
|
1 |
Difficulty |
Middle |
2 |
Microsoft VB 6.0 Component |
Standard EXE |
|
|
TextBox |
|
|
Label |
|
|
Frame |
3 |
RFC names |
/CRYSTAL/GET_USER_LIST |
Procedure :
1.Run Microsoft Visual Basic 6.0
2.Create new Project > "Standard EXE"
4.Add one “ SAPLogonControl ” Component to a Form
5.Add and place it the others component like a picture bellow :

No |
Commponent |
Properties |
Value |
1 |
SAPLogonControl |
Name |
SAPLogonControl1 |
|
|
Caption |
&R/3 Logon |
|
|
Others |
Default |
2 |
TextBox |
Name |
eApplicationServer |
|
|
Text |
Null (Empty) |
3 |
TextBox |
Name |
eSystemNumber |
|
|
Text |
Null (Empty) |
4 |
TextBox |
Name |
eClient |
|
|
Text |
Null (Empty) |
5 |
TextBox |
Name |
eSystem |
|
|
Text |
Null (Empty) |
6 |
TextBox |
Name |
eUsername |
|
|
Text |
Null (Empty) |
7 |
TextBox |
Name |
ePssword |
|
|
Text |
Null (Empty) |
8 |
TextBox |
Name |
eLanguage |
|
|
Text |
Null (Empty) |
10 |
Frame |
Name |
Frame1 |
|
|
Caption |
SAP Logon |
10 |
TextBox |
Name |
DisplayTableData |
|
|
Text |
Null (Empty) |
|
|
MultiLine |
True |
|
|
ScrollBars |
3 - Both |
6.Add OnClick event at SAPLogonControl1 component with this code bellow :
Private Sub SAPLogonControl1_Click()
Dim l_Conn As SAPLogonCtrl.Connection
Dim l_SAPFunction As Object 'SAPFunctionsOCX.SAPFunctions
Dim l_Function As SAPFunctionsOCX.Function
Dim l_Table As SAPTableFactoryCtrl.Table
Dim i As Integer
Dim l_tmp As String
Set l_Conn = SAPLogonControl1.NewConnection
l_Conn.Client = eClient.Text
l_Conn.ApplicationServer = eApplicationServer.Text
l_Conn.SystemNumber = eSystemNumber.Text
l_Conn.System = eSystem.Text
l_Conn.User = eUsername.Text
l_Conn.Password = ePassword.Text
l_Conn.Language = eLanguage.Text
If l_Conn.Logon(0, True) Then
'Declare RFC Conncetion
Set l_SAPFunction = CreateObject("SAP.Functions")
Set l_SAPFunction.Connection = l_Conn
'Call RFC or BAPI
Set l_Function = l_SAPFunction.Add("/CRYSTAL/GET_USER_LIST")
'If RFC or BAPI doesn't need any export variable (in SAP is Imports)
'l_Function.exports(< variable name for Import in SAP >).Value = < value >
'Example:
'l_Function.exports("PERNR").Value = Edit1.Text
If Not l_Function.Call Then
' IF RFC or BAPI failed to call
MsgBox l_Function.Exception
Else
'Called (Download) table variable from RFC or BAPI
Set l_Table = l_Function.Tables.Item("USERACTGRP")
' If RFC or BAPI doesn't need any import variable (in SAP is Export)
'< value > = l_Function.imports(<variable name for Export in SAP >).value
'Example:
'Edit2.Text = l_Function.imports('PERNR').value
For i = 1 To l_Table.rowCount - 1
'Get value from table
'l_Table.Value(< data to >, < Field Name > )
l_tmp = ""
l_tmp = l_tmp & " | " & l_Table.Value(i, "MANDT")
l_tmp = l_tmp & " | " & l_Table.Value(i, "BNAME")
l_tmp = l_tmp & " | " & l_Table.Value(i, "SUBSYSTEM")
l_tmp = l_tmp & " | " & l_Table.Value(i, "AGR_NAME")
l_tmp = l_tmp & " | " & l_Table.Value(i, "FROM_DAT")
l_tmp = l_tmp & " | " & l_Table.Value(i, "TO_DAT")
l_tmp = l_tmp & " | " & l_Table.Value(i, "ORG_FLAG")
DisplayTableData.Text = DisplayTableData.Text & vbCrLf & l_tmp
Next i
End If
'Close SAP Conncetion
l_Conn.Logoff
End If
End Sub
7.Press “ Run/Start “ button for testing your code.