Application Development and Automation 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: 
Read only

Calling RFC via VBA Code.

0 Likes
1,180

Hello All,

I have a requirement wherein i need to do some offline planning of Some FSS Data and after the planning  the data needs to be uploaded on single click.

Pre-requisites:

Connected to BEx System to same system to which  file is to be uploaded

The report is an excel File. So when we Click on 1 button , it should do following things.

1. Automatically connect to SAP .

2. Create a Copy of same file as CSV on desktop.

3. We have created a RFC by copying the Function Module " ARCHIVFILE_CLIENT_TO_SERVER ". Basically this Function Module takes CSV file from Desktop and uploads to a default path on Application Server.

( Note : We are able to debug the RFC , and we can see the parameters being passed Correctly, But execution is an issue. The Functionality of RFc of picking the file & uploading is not working)

4. Now we are invoking this RFC using VBA Code. Please find the code below at the bottom.

Issue is it is giving Error File on executing it .

Questions :

1. Are there any other parameters that need to be set via VBA Code.

2. Do we need any Settings to be done to use RFC.

3. Any Other suggestions to the Solution

VBA Code

Sub abc()

    Dim FModule

    Dim FM As Object

    Dim Data As Object

    Dim objCon As Object

    Dim strusername As String

    Dim strappserver As String

    Dim temptable

    Dim I As Integer

    Dim J As Integer

    Dim Res

      

    Set FM = CreateObject("SAP.FUNCTIONS")

  

    Set objCon = Application.Run("BExAnalyzer.xla!sapBEXgetConnection")

     If objCon.user = "" Then

        MsgBox "Connnection can not be established.", vbOKOnly + vbCritical

        Exit Sub

    End If

  

  

     strusername = objCon.user

     FM.Connection.user = objCon.user

     FM.Connection.Password = objCon.Password

     FM.Connection.client = "400" 'objCon.client

   

  

     strappserver = objCon.ApplicationServer

     FM.Connection.ApplicationServer = strappserver 'objCon.ApplicationServer

     FM.Connection.Language = "EN" 'objCon.Language

     FM.Connection.System = objCon.System

     FM.Connection.SystemNumber = objCon.SystemNumber

    'opening connection

    If FM.Connection.logon(1, True) <> True Then

        MsgBox "Can not logon. Please contact your administrator"

        Exit Sub

    Else

  

    'your function modulename

     Set FModule = FM.Add("ZAR_TO_PR_SRVR")

''        With FModule

''            .Exports("PATH") = "C:\Users\10603751\Desktop\Upload2.csv"

''            .Exports("TARGETPATH") = "Upload2.csv"

''        End With

   

    FModule.exports("PATH") = "C:\Users\10603751\Desktop\Upload2.csv"

'     Dim oParam2, oParam3 As Object

'

'    Set oParam2 = FModule.exports("C:\Users\10603751\Desktop\Upload1.csv")

    'oParam2.Value = "C:\Users\10603751\Desktop\Upload1.csv"

    FModule.exports("TARGETPATH") = "Upload2.csv"

'    Set oParam3 = FModule.exports("Upload1.csv")

    'oParam3.Value = "Upload1.csv"

   

    result = FModule.Call()

'    If result = False Then

'        MsgBox ("abc")

'        End If

      Res = FModule.exception

           

     'FM.Connection.logoff

    End If

End Sub

1 ACCEPTED SOLUTION
Read only

sascha_mink2
Explorer
0 Likes
734

a little bit off topic i know but why so complicated, you could reuse your Connection with the following stmt:

FM.Connection = objCon

1 REPLY 1
Read only

sascha_mink2
Explorer
0 Likes
735

a little bit off topic i know but why so complicated, you could reuse your Connection with the following stmt:

FM.Connection = objCon