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.
Open a new Excel Workbook and add the Visual Basic and Control Box
Add a command button to the workbook and update it properties as shown below
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.
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”)
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.