Ref: Sales Inquiry Using BAPI-Excel-VBs & Hands-on VBs Tutor.
Hi,
Many of us know how to access RFC / BAPI and read data from SAP server;
today I am going to show you how to save data into Z table Via RFC/BAPI.
Here I assume that you know how to create BAPI from RFC Function module, here we go.
Steps Involve.
2. Create BAPI Structure for Data Type
This will be used to declare import parameter in RFC function module
3.Create RFC function module
4. Create BAPI from function module
A.Declare Variable
Dim Destination_System As Integer
Dim objBAPIControl As Object 'Function Control (Collective object)
Dim sapConnection As Object 'Connection object
Set objBAPIControl = CreateObject("SAP.Functions")
Set sapConnection = objBAPIControl.Connection
Dim valu As String
B. Connection Parameters
sapConnection.client = "client number"
sapConnection.user = "User name"
sapConnection.Language = "E"
sapConnection.hostname = "ip address server"
sapConnection.Password = "passwird"
sapConnection.SystemNumber = "System number"
sapConnection.System = "system id"
you can get above parameters from SAP Logon properties.
C. Determine Connection is establish or not.
If sapConnection.logon(1, True) <> True Then
MsgBox "No connection to R/3!"
Exit Sub 'End program
End If
D. If connection is successful then perform the save operation.
Set objUserList = objBAPIControl.Add("ZBAPI_TESTSAVE")
Worksheets(1).Select
For i = 1 To 5
valu = ActiveSheet.Cells(i, 2)
objUserList.exports("NAME1") = valu
returnFunc = objUserList.Call
ActiveSheet.Cells(i, 2) = ""
Next i
MsgBox "Record(s) saved", vbInformation
every time i increment and row changes columns remains static as we have fixed it to 2.
Excel Sheet Preview.
*All the operation is done under
Sub Button1_Click()
***Above Code***
End Sub
You can also upload data to standard table just apply your logic and things will be done.
-Avirat.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |