cancel
Showing results for 
Search instead for 
Did you mean: 

Call SAP function module through Excel VBA

Former Member
0 Kudos

Hi experts,

I try to call the remote-enabled function module SWNC_COLLECTOR_GET_SYSTEMLOAD from Excel VBA to save the workload data of the system and to create some graphs etc.

Logon to SAP works fine for now, but I have no idea how to hande the import parameter (which is an export parameter from the view of the function module).

Here is an coding excerpt:

' EXPORTS

Set oParam1 = objDisplay.exports("COMPONENT")

oParam1.Value = "TOTAL"

Set oParam2 = objDisplay.exports("PERIODTYPE")

oParam2.Value = "D"

Set oParam3 = objDisplay.exports("PERIODSTRT")

oParam3.Value = "01012012"

' IMPORTS

Set oParam4 = objDisplay.imports("T_SYSTEMLOAD")

' Call FM

objDisplay.Call

Debug.Print oParam4

The debug-print gives an error 0. I have no clue what the error means.

Could anybody help me to solve the issue?

Accepted Solutions (0)

Answers (5)

Answers (5)

0 Kudos

Set trace level on the connection and review trace file output on SAP/Sap gui/ folder in your documents folder. Look for communication or authority.

Former Member
0 Kudos

Hi Davor,

Did you get a solution for this?

The function is remote enabled, I get a error while calling the function donot know what the error is, I check the format for all variables and they are correct....

Regards

Amit Jain

Former Member
0 Kudos

Hi Amit,

sorry for the late reply. Unfortunately I have no solution yet.

Regards

Davor

Former Member
0 Kudos

Hi,

I think not. The parameters are ok and are working for other function modules without problems.

I have found out - as implied by Michael - that I cannot call this function module although it is clearly remote enabled.

If I call an other SWNC* function module it works for me.

michael_hobbins
Active Participant
0 Kudos

Davor, just rechecked my ERP and SWNC_COLLECTOR_GET_SYSTEMLOAD is defintely not remote enabled in ECC 6.0 (with no EHPs installed). What version do you have?

I checked some other SWNC* and as you mentioned they are remote enabled.

My advice is still the same

Michael

Former Member
0 Kudos

Hi Michael,

we are using ECC 6.0 EHP 4 with Basis 701 SP7.

I just rechecked and in our ERP it is clearly remote enabled with "Start immed." flaged.

The last change in our ERP for this FM was 20110508 by SAP so it seems one of the last EHPs made this FM remote enabled.

michael_hobbins
Active Participant
0 Kudos

Just remembered we have a EHP4 sandbox, checked it and I see it's remote enabled there. The start immediately option refers to the Update Module.

With this cleared, can you try the following? The date format you used if DDMMYYYY, can you change it to YYYYMMDD and retry?

This change will look like this

oParam3.Value = "20120101"

Michael

Former Member
0 Kudos

Thanks for the hint. I really have tried everything. After activating RFC-Trace I found out that there was an error calling the function module in the ECC system. After that I tried another SWNC* function module with the same date format and it worked without problems.

I think I will copy the standard function module to a Z* one and give it another try. Thanks for your help.

michael_hobbins
Active Participant
0 Kudos

Davor, just tested the funtion from an Excel macro connecting it to my EHP4 sandbox. I get the same RFC conection error. As the date parameter is optional, I just passed COMPONENT and PERIODTYPE and got the error too, so it's not a date format problem.

I then tried SWNC_GET_WORKLOAD_DIRECTORY (which is remote enabled too) and the connection was successful. So, there is obviously some problem with the function module.

Alternatives: build the Z function module, or post a message on OSS with the error.

Cheers,

Michael

Former Member
0 Kudos

Hello Davor.

To me this is looking abit odd:

Set oParam3 = objDisplay.exports("PERIODSTRT")

oParam3.Value = "01012012"

When executing this function module in SAP this value is incorrect, instead SAP prompts for a valid date value i.e 2012-03-08. Could this be your problem?

michael_hobbins
Active Participant
0 Kudos

Hello Davor,

on ECC 6.0, this FM is not remote access enabled, so this is your first problem. A workaround to this is to create a Z function module that will call the standard FM. Copy de importing and exporting parameters from the standard to your Z version, make it remote access enabled and call it from your Excel VBA code.

Hope it helps and I'n not late

Cheers,

Michael