Skip to Content

Data Upload into SAP from Microsoft Excel – VBA Part

Data Upload into SAP from Microsoft Excel – VBA Part

In my previous weblog Data Upload into SAP from Microsoft Excel – ABAP part for the sample application to post material data in SAP was discussed.

The operation like
1. Establishing a Connection to SAP
2. Populating the import parameters of an RFC Function module
3. Executing the RFC function and processing the result

are to be handled in the Microsoft Excel. This can be achieved using the Visual Basic for Applications.

The Excel VBA reference is available for free download. For more information about this language please visit MSDN.

Open a new Excel Workbook and add the Visual Basic and Control Box

image

Add a command button to the workbook and update it properties as shown below

image

image

One main thing is to be noted at this point. The initial data row in the excel sheet is fixed to ROW5 in this example.

image

In case if you want to change, just put the required start row in the FOR loop.

For vRows = 5 To vLastRow [Replace 5 with your current data begin row]

Now double click the Command button, this will take you to the VBA editor, Place the below code in the Global Declarations

And the main logic goes as below

The example is created in such a way that the return messages will be populated in the same sheet. Thus we must know the last filled data row to that we can start writing the return messages after that row.

‘ Getting the last filled Row in Column A
vLastRow = Cells(Rows.Count, “A”).End(xlUp).Row

The above code will determine the last filled row in the Excel sheet.

Now populating the return messages will be done as below

‘ Get return parameters & display in excel
Set objReturn = objCreateMaterial.Imports(“RETURN”)
ActiveSheet.Cells((vLastRow + vRows), 1) = objReturn.value(“MESSAGE”)

image

Thus the return messages can be easily populated as shown above.

Hope this example was useful, and using the same logic much more complex data uploads can be done.

6 Comments
You must be Logged on to comment or reply to a post.
  • Hello Bala,
      Can we pass a structure instead of passing the individual variables.
    Like if the RFC has the importing parameter a structure instead of these variables.
    Like
    MATERIAL_DETAILS
           |
         MATERIAL
         MATL_DESC
         IND_SECTOR….

    and the RFC would have only 1 importing parameter called as MATERIAL_DETAILS.

    regards,

  • Hello Bala,
      Can we pass a structure instead of passing the individual variables.
    Like if the RFC has the importing parameter a structure instead of these variables.
    Like
    MATERIAL_DETAILS
           |
         MATERIAL
         MATL_DESC
         IND_SECTOR….

    and the RFC would have only 1 importing parameter called as MATERIAL_DETAILS.

    regards,

  • Hello Bala,
      Can we pass a structure instead of passing the individual variables.
    Like if the RFC has the importing parameter a structure instead of these variables.
    Like
    MATERIAL_DETAILS
           |
         MATERIAL
         MATL_DESC
         IND_SECTOR….

    and the RFC would have only 1 importing parameter called as MATERIAL_DETAILS.

    regards,

  • Hi,

    First of all, thanks for a useful article!

    I have a question similar to the one before, but rather than sending a structure I would like to collect all data into a table and pass that on to SAP. I have very little experience of VBA and Excel macros so any help is much appreciated!

    BR,
    Ulrika Enskog

  • Hi,

    First of all, thanks for a useful article!

    I have a question similar to the one before, but rather than sending a structure I would like to collect all data into a table and pass that on to SAP. I have very little experience of VBA and Excel macros so any help is much appreciated!

    BR,
    Ulrika Enskog

  • Hi,

    First of all, thanks for a useful article!

    I have a question similar to the one before, but rather than sending a structure I would like to collect all data into a table and pass that on to SAP. I have very little experience of VBA and Excel macros so any help is much appreciated!

    BR,
    Ulrika Enskog