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

VBA Calling RFC

Former Member
0 Likes
2,209

This question seems to come up again and again, but I did not find a solution that worked in previous threads. I am calling an SAP RFC from a VBA macro and receiving the error "Structure member not found" when I pass the RFC its only parameter. Below is the code:

<u><b>VBA Code</b></u>

Sub CreateRecallCancel()

Dim Functions As Object

Dim RemoteFunction As Object

Dim FunctionParameter1 As Object

'create components of the recall/cancel RFC

Dim sRecallCancel As String

Dim sMSGIND As String * 3

Dim sCLAIMNUM As String * 24

Dim sROC As String * 2

Dim sCHECKNO As String * 9

Dim sPOSNR As String * 12

'log in to SAP and send the user a message if logon was unsuccessful

Set Functions = CreateObject("SAP.Functions")

If Functions.Connection.Logon(0, False) <> True Then

MsgBox ("System could not log you on. Please check user name and password and try again.")

Exit Sub

End If

'set remote function equal to the recall function

Set RemoteFunction = Functions.Add("ZIS_CCS_RECALL")

Set FunctionParameter1 = RemoteFunction.exports("I_RECALL")

sMSGIND = "1"

sCLAIMNUM = "28X1445144"

sROC = "16"

sCHECKNO = ""

sPOSNR = "400000206500"

sRecallCancel = sMSGIND + sCLAIMNUM + sROC + sCHECKNO + sPOSNR

FunctionParameter1.Value = sMSGIND + sCLAIMNUM + sROC + sCHECKNO + sPOSNR

'log off SAP

Functions.Connection.Logoff

End Sub

<b><u>RFC Definition</u></b>

The only parameter taken in by ZIS_CCS_RECALL is I_RECALL, whose structure is as follows:

Field (Length)

MSGIND (3)

CLAIMNUM (24)

ROC (2)

CHECKNO (9)

POSNR (12)

The definition of I_RECALL is a LIKE to another structure, so the previous solution of TYPE vs. LIKE does not apply to this error. Please help. Thanks.

This question seems to come up again and again, but I did not find a solution that worked in previous threads. I am calling an SAP RFC from a VBA macro and receiving the error "Structure member not found" when I pass the RFC its only parameter. Below is the code:

<u><b>VBA Code</b></u>

Sub CreateRecallCancel()

Dim Functions As Object

Dim RemoteFunction As Object

Dim FunctionParameter1 As Object

'create components of the recall/cancel RFC

Dim sRecallCancel As String

Dim sMSGIND As String * 3

Dim sCLAIMNUM As String * 24

Dim sROC As String * 2

Dim sCHECKNO As String * 9

Dim sPOSNR As String * 12

'log in to SAP and send the user a message if logon was unsuccessful

Set Functions = CreateObject("SAP.Functions")

If Functions.Connection.Logon(0, False) <> True Then

MsgBox ("System could not log you on. Please check user name and password and try again.")

Exit Sub

End If

'set remote function equal to the recall function

Set RemoteFunction = Functions.Add("ZIS_CCS_RECALL")

Set FunctionParameter1 = RemoteFunction.exports("I_RECALL")

sMSGIND = "1"

sCLAIMNUM = "28X1445144"

sROC = "16"

sCHECKNO = ""

sPOSNR = "400000206500"

sRecallCancel = sMSGIND + sCLAIMNUM + sROC + sCHECKNO + sPOSNR

FunctionParameter1.Value = sMSGIND + sCLAIMNUM + sROC + sCHECKNO + sPOSNR

'log off SAP

Functions.Connection.Logoff

End Sub

<b><u>RFC Definition</u></b>

The only parameter taken in by ZIS_CCS_RECALL is I_RECALL, whose structure is as follows:

Field (Length)

MSGIND (3)

CLAIMNUM (24)

ROC (2)

CHECKNO (9)

POSNR (12)

The definition of I_RECALL is a LIKE to another structure, so the previous solution of TYPE vs. LIKE does not apply to this error. Please help. Thanks.

7 REPLIES 7
Read only

Former Member
0 Likes
1,314

Please reference this link for how to call BAPI in VB:

http://help.sap.com/saphelp_nw04/helpdata/en/a4/ba89c5462e11d2952500a0c94260a5/frameset.htm

BAPI is a kind of RFC, so I think the method is similiar.

Hope it will be helpful

Read only

0 Likes
1,314

I have gone through the whole process of navigating through DCOM setup to create component DLLs for my RFCs, but in the DCOM list of available RFCs for my SAP environment, it only shows SAP-standard BAPIs and other RFCs, but the custom RFCs that I have developed do not show up as available choices.

Read only

0 Likes
1,314

With regard to Zhenglin's link to DCOM information:

I tried to create a component DLL for the custom RFCs I want to call, but when I click on "Build Component DLL" in the DCOM Object Builder, I get errors. The most recent is <b>"CCP2Upload2.mak(6) : fatal error U1052: file 'mkenv.inc' not found Stop."</b>

I have Visual C++ 6.0 installed. Any ideas?

Read only

Former Member
0 Likes
1,314

Hi,

Custom Function module should be RFC enabled and

released so that external system can access your

custtom Fm.

Regards

Amole

Read only

0 Likes
1,314

The FMs are remote-enabled and are currently used by a .NET application, so I know they work. They are just not showing up as available choices in the DCOM list, even though they are truly available.

Message was edited by: Jon Gilman

Read only

0 Likes
1,314

Nevermind, I have found them, I will send update upon completion.

Read only

Former Member
0 Likes
1,314

Hi man, i trying call Z td code from VBA, any idea ?

Public Sub rfc_call_transaction()
    Dim Functions As Object
    Dim RfcCallTransaction As Object
    Dim Messages As Object
    Dim BdcTable As Object
    
    ' Create the Function control (that is, the high-level Functions collection):
    Set Functions = CreateObject("SAP.Functions")
    
    ' Set the rest of Connection object values:
    Functions.Connection.System = ""
    Functions.Connection.client = "100"
    Functions.Connection.user = ""
    Functions.Connection.password = ""
    Functions.Connection.language = "EN"
    
    If Functions.Connection.Logon(0, False) <> True Then
       Exit Sub
    End If
    
    ' Retrieve the Function object (the Connection object must be set up before Function objects can be created):

    Set RfcCallTransaction = Functions.Add("RFC_CALL_TRANSACTION")
    
    ' Set the export parameters (here, get all customers whose names start with J):
    RfcCallTransaction.exports("TRANCODE") = "ZDHWLOAD"
    RfcCallTransaction.exports("UPDMODE") = "S"

    
    If RfcCallTransaction.Call = True Then
        Set Messages = RfcCallTransaction.imports("MESSG")
        MsgBox Messages.Value("MSGTX")

    Else
        MsgBox " Call Failed! error: " + GetCustomers.Exception
        Functions.Connection.Logoff
    End If

Functions.Connection.Logoff

End Sub