|
Create SAP - VB.Net Connection using SAP ActiveX |
Home | ||||
|
Previous Next | |||||
| Page Contents | ||||||||||||
|
||||||||||||
Requirement All step is already tested using this requirement
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:
> A client in the r/3 system that you want to connect to
> The name of the host that you want to connect to
> Specify the system number (e.g. 00) of the SAP System that you want to connect to
> Specify the system ID (e.g. OSS) of the SAP System that you want to connect to
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
____________________________________________________________________________
SAPLogonControl Concept and Format: Declare a New Connection Fill Connection Variable login
Example:
Dim l_SAPLogonControl As New SAPLogonCtrl.SAPLogonControl Dim l_conn As SAPLogonCtrl.Connection l_conn = l_SAPLogonControl.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:
Procedure:
Private Sub BLogon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BLogon.Click Dim l_SAPLogonControl As New SAPLogonCtrl.SAPLogonControl Dim l_conn As SAPLogonCtrl.Connection l_conn = l_SAPLogonControl.NewConnection
If l_conn.Logon(0, False) Then MsgBox("Connect to SAP.") End If
End Sub
____________________________________________________________________________
Create SAP Logon with input dialog
Procedure:
Private Sub BLogon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BLogon.Click Dim l_SAPLogonControl As Object 'New SAPLogonCtrl.SAPLogonControl Dim l_conn As Object 'SAPLogonCtrl.Connection
l_SAPLogonControl = CreateObject("SAP.LogonControl.1") l_conn = l_SAPLogonControl.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
____________________________________________________________________________
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 :
Procedure :
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DataGridView1.Columns.Add("No", "No") DataGridView1.Columns.Add("MANDT", "MANDT") DataGridView1.Columns.Add("BNAME", "BNAME") DataGridView1.Columns.Add("SUBSYSTEM", "SUBSYSTEM") DataGridView1.Columns.Add("AGR_NAME", "AGR_NAME") DataGridView1.Columns.Add("FROM_DAT", "FROM_DAT") DataGridView1.Columns.Add("TO_DAT", "TO_DAT") DataGridView1.Columns.Add("ORG_FLAG", "ORG_FLAG")
End Sub
Private Sub BLogon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BLogon.Click Dim l_SAPLogonControl As Object 'New SAPLogonCtrl.SAPLogonControl Dim l_conn As Object 'SAPLogonCtrl.Connection Dim l_SAPFunction As New SAPFunctionsOCX.SAPFunctions
Dim l_Function As SAPFunctionsOCX.Function Dim l_Table As SAPTableFactoryCtrl.Table Dim i As Integer
l_SAPLogonControl = CreateObject("SAP.LogonControl.1") l_conn = l_SAPLogonControl.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 l_SAPFunction = CreateObject("SAP.Functions") l_SAPFunction.Connection = l_conn 'Call RFC or BAPI 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 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 = 0 To l_Table.RowCount - 1 'Get value from table 'l_Table.Value(< data to >, < Field Name > ) DataGridView1.Rows.Add() DataGridView1.Rows(i).Cells(0).Value = i + 1 DataGridView1.Rows(i).Cells(1).Value = l_Table.Value(i + 1, "MANDT") DataGridView1.Rows(i).Cells(2).Value = l_Table.Value(i + 1, "BNAME") DataGridView1.Rows(i).Cells(3).Value = l_Table.Value(i + 1, "SUBSYSTEM") DataGridView1.Rows(i).Cells(4).Value = l_Table.Value(i + 1, "AGR_NAME") DataGridView1.Rows(i).Cells(5).Value = l_Table.Value(i + 1, "FROM_DAT") DataGridView1.Rows(i).Cells(6).Value = l_Table.Value(i + 1, "TO_DAT") DataGridView1.Rows(i).Cells(7).Value = l_Table.Value(i + 1, "ORG_FLAG")
Next i End If 'Close SAP Conncetion l_conn.Logoff() End If
End Sub
|
| User Threads | New Thread ( Only for Donators ) |
|
|
|||
| Threads | Last Post | Replies | Views |
|
|
|||