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: 

RFC-Call with VBA

Former Member
0 Kudos

I am trying to use a FM from SAP BW with two tables (Options and Fields) in VBA and fill these tables with some paramters.

The first one (with only one column named TEXT) works fine, but the second one with more than one column brings up an exception.

This is the VBA-Coding I am using:

Dim BW, MyFunc, App As Object

Set BW = CreateObject("SAP.Functions")

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

Exit Sub

End If

Set MyFunc = BW.Add("ZDU_READ_BWTDATA_RFC")

        • This works:

Set oParam1 = MyFunc.exports("TABLE")

oParam1.Value = "/BI0/TMATERIAL"

        • This works:

'OPTIONS

'Where-CLAUSE

Dim tOPTIONS As Object

Dim Options_Text As Object

Set tOPTIONS = MyFunc.Tables.Item("OPTIONS")

Set Options_Text = tOPTIONS.Rows.Add

Options_Text.Value("TEXT") = "LANGU eq 'E'"

        • This does not work:

'FIELDS

Dim tFIELDS As Object

Dim FIELDS_FIELDNAME As Object

Set tFIELDS = MyFunc.Tables.Item("FIELDS")

Set FIELDS_FIELDNAME = tFIELDS.Rows.Add

FIELDS_FIELDNAME.Value("FIELDNAME") = "MATERIAL"

Set FIELDS_FIELDNAME = tFIELDS.Rows.Add

FIELDS_FIELDNAME.Value("FIELDNAME") = "LANGU"

Set FIELDS_FIELDNAME = tFIELDS.Rows.Add

FIELDS_FIELDNAME.Value("FIELDNAME") = "TXTMD"

I found these links but they are using the same coding...

Any hints are welcome!

Message was edited by: Markus Fischer

6 REPLIES 6

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Check this.May be this can help you.If so,reward points by clicking the star button next to reply.

http://www.sap-img.com/abap/vb-codes-or-vba-macro-code-for-access-sap-and-run-one-rfc.htm

0 Kudos

Hello,

thanks for the link - nice coding, but it does not provide the informations I am searching.

The coding uses disconnected recordsets to hand over values and I do not know how to hand over theses recordsets to the RFC-Mdoule. the way the author used in the coding does not work.

Main Question is also why the first fill-up of the table options works and the secodn does not.

Thanks for the link anyway!

0 Kudos

Hi,

Check this.May be this can help you.

http://www.sapassist.com/code/d.asp?d=2397&a=s

Former Member
0 Kudos

Hi Markus,

here comes some "any hint" (hope it helps):

http://www.sap-img.com/abap/vb-codes-or-vba-macro-code-for-access-sap-and-run-one-rfc.htm

regards

Andreas

krzysztof_konitz4
Contributor
0 Kudos

Hi,

Try to use such coding:

Set MyFunc = Funct.Add("ZDU_READ_BWTDATA_RFC")

Set Options = MyFunc.Tables("OPTIONS")

Set Row = Options.Rows.Add

Row("FIELDNAME") = "MATERIAL"

Set Row = Options.Rows.Add

Row("FIELDNAME") = "LANGU"

Result = MyFunc.Call

Maybe first you should add row, then make assignment...

Krzys

Former Member
0 Kudos

You were almost there, try this:

Set tFIELDS = MyFunc.Tables.Item("FIELDS")

Set FIELDS_FIELDNAME = tFIELDS.Rows.Add

FIELDS_FIELDNAME.Value(1,"FIELDNAME") = "MATERIAL"

Set FIELDS_FIELDNAME = tFIELDS.Rows.Add

FIELDS_FIELDNAME.Value(2,"FIELDNAME") = "LANGU"

Set FIELDS_FIELDNAME = tFIELDS.Rows.Add

FIELDS_FIELDNAME.Value(3,"FIELDNAME") = "TXTMD"

Please note the unique index number before the text FIELDNAME to uniquley identify your parameters to the FM. Hope this helps.

Regards

Ashley Day