Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to execute an SAP report from Excel sheet

former_member687052
Participant
0 Kudos

Hi All,

I have developed a report which retrieves the data from SAP and downloads to an Excel sheet on the local machine. But, the requirement from the client is... the client doesn't want to execute the report from SAP. There is a VB based EXCEL sheet on the local machine. In that, I have a PUSH BUTTON with name 'Get data from SAP'. So, When the user clicks the button in the excel sheet, it should execute the report in SAP and download the data into the same Excel worksheet.

Is it possible to execute an SAP report from the Excel sheet..?

If YES, what are the pre-requisites required and how can it be done.

If there is any useful information, please share. If someone help me in this regard with your valuable inputs that would be greatful.

Thanks in advance.

Best regards,

Paddu.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

I have not done it with a report. I have done it calling to a function in SAP. This it is the code of the macro.

I hope that it you works.

The function Processing Type is 'Remote-Enabled Module'

Sub Botón2_AlHacerClic()

'Create function component.

Dim fns As Object

Dim func As Object

Dim Correct As Integer

Dim errors As Integer

Cells(1, 2) = 0

Cells(2, 2) = 0

Correct = 0

errors = 0

Set fns = CreateObject("SAP.Functions")

fns.logfilename = "c: mp able+viewlog.txt"

fns.loglevel = 9

Dim conn As Object

Set conn = fns.Connection

If conn.logon(0, False) <> True Then

MsgBox "Error de conexion"

Exit Sub

End If

i = 9

While (Cells(i, 2) <> "")

Set func = fns.Add("ZZUPLOAD_FROM_EXCEL")

func.Exports("P_MATKL") = Cells(i, 2)

func.Exports("P_WERKS") = Cells(i, 3)

Result = func.call

If Result <> True Then

'MsgBox ("Call error: " + Exception)

'Exit Sub

Cells(i, 1) = func.Imports("MENSAJE")

Else

Cells(i, 1) = func.Imports("MENSAJE")

If (Cells(i, 1) = "OK") Then

Correct = Correct + 1

Else

errors = errors + 1

End If

End If

Set func = Nothing

i = i + 1

Wend

'clean the vars

Set fns = Nothing

Set conn = Nothing

Cells(1, 2) = Correct

Cells(2, 2) = errors

MsgBox "Finished load"

End Sub

4 REPLIES 4

former_member404244
Active Contributor
0 Kudos

Hi,

I may not be 100 percent right..But i can say we can have a try ..

Create a BAPI and inside BAPI u right ur data retrieval code ...U can also use ALV functionality the function module....

Now we need to communicate this bapi with the VB.. The VB people needs to call this bapi...

But i donno how the VB code for this..

Regards,

Nagaraj

Former Member
0 Kudos

Make a short cut of the tcode u want to exe in SAP by clicking CREATE SHORTCUT BUTTON next to CREATE SESSION BUTTON

Place that Shortcut on desktop.

Program ur excel button to point to SAP shortcut.

Then do programming accordingly.

Former Member
0 Kudos

I have not done it with a report. I have done it calling to a function in SAP. This it is the code of the macro.

I hope that it you works.

The function Processing Type is 'Remote-Enabled Module'

Sub Botón2_AlHacerClic()

'Create function component.

Dim fns As Object

Dim func As Object

Dim Correct As Integer

Dim errors As Integer

Cells(1, 2) = 0

Cells(2, 2) = 0

Correct = 0

errors = 0

Set fns = CreateObject("SAP.Functions")

fns.logfilename = "c: mp able+viewlog.txt"

fns.loglevel = 9

Dim conn As Object

Set conn = fns.Connection

If conn.logon(0, False) <> True Then

MsgBox "Error de conexion"

Exit Sub

End If

i = 9

While (Cells(i, 2) <> "")

Set func = fns.Add("ZZUPLOAD_FROM_EXCEL")

func.Exports("P_MATKL") = Cells(i, 2)

func.Exports("P_WERKS") = Cells(i, 3)

Result = func.call

If Result <> True Then

'MsgBox ("Call error: " + Exception)

'Exit Sub

Cells(i, 1) = func.Imports("MENSAJE")

Else

Cells(i, 1) = func.Imports("MENSAJE")

If (Cells(i, 1) = "OK") Then

Correct = Correct + 1

Else

errors = errors + 1

End If

End If

Set func = Nothing

i = i + 1

Wend

'clean the vars

Set fns = Nothing

Set conn = Nothing

Cells(1, 2) = Correct

Cells(2, 2) = errors

MsgBox "Finished load"

End Sub

Former Member
0 Kudos

Hi Former Member

can u please provide a detail on this scenario.

I want to execute a function module or report from excel.