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.
- Create Z table for data save [Quick View]
- Create BAPI Structure for Data type [Quick View]
- Create RFC function module [Quick View]
- Create BAPI from function module [Quick View]
- Write VB script into MS-Excel [Detail View]
- Create Z table for data save
2. Create BAPI Structure for Data Type
This will be used to declare import parameter in RFC function module
3.Create RFC function module
- Writing a VB-Script Detail Explanation.
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
D. If connection is successful then perform the save operation.
Set objUserList = objBAPIControl.Add(“ZBAPI_TESTSAVE”)
For i = 1 To 5
valu = ActiveSheet.Cells(i, 2)
objUserList.exports(“NAME1”) = valu
returnFunc = objUserList.Call
ActiveSheet.Cells(i, 2) = “”
MsgBox “Record(s) saved”, vbInformation
- First line is to assign function module name as object.
- second line is to select Excel sheet number
- Third line to begin loop up to 5 times ( i am going to save 5 names at once)
- Forth line it so select cells dynamically ActiveSheet.Cells(Row,Column) –
every time i increment and row changes columns remains static as we have fixed it to 2.
- Fifth line is to export cell value to RFC function parameter (it will transfer data excel to rfc function parameter)
- Sixth line is to call / Execute function (Actual execution done and data transferred physically)
- Seventh line is to clear cell by Row and column
- eight line is to Return the loop and starts from the beginning until condition fails (that is 5 times)
Excel Sheet Preview.
*All the operation is done under
You can also upload data to standard table just apply your logic and things will be done.