Skip to Content
Author's profile photo Former Member

Insert Data Via BAPI Using Excel-VBs

     Ref: Sales Inquiry Using BAPI-Excel-VBs & Hands-on VBs Tutor.


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.

  • 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]
  1. 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

  1. Writing a VB-Script Detail Explanation.

               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”)


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

  • 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

Sub Button1_Click()

***Above Code***

End Sub

You can also upload data to standard table just apply your logic and things will be done.


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member


      nice explanation. everythig seems soothing.

      but hardly know anything of vb. just want to know where to write vb code.

      do we need to install some another software .

      please guide me where to code this vb code.

      i mean platform...just like we write abap code in abap editor.

      here abap is the language and abap editor is the platform.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      As you can see in last excel sheet preview(MS Office 2010).

      From developer menu, you have various option available i.e. insert(button,input text),view code,design mode...

      For more detail you need to use google ...


      Author's profile photo Pragnesh Patel
      Pragnesh Patel

      Nice blog.

      Author's profile photo Former Member
      Former Member

      Great example, by knowing abap and (or c) you can do a great job and bypass abap limitations in GUI and interfacing...