cancel
Showing results for 
Search instead for 
Did you mean: 

RFC call thru Excel

ranjit_deshmukh
Active Participant
0 Kudos

Hi,

I am trying to call a RFC (ZTAB_FIELD_DET) by using VBA

as I am new to this feature I dont know much about the possible causes of some errors.

here is the code of RFC which will accept the table name, field name and language. And in turn it will return the Datatype of the field its length and description

**************************RFC Start*******************************:

FUNCTION ZTAB_FIELD_DET.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(I_TNAME) TYPE TABNAME

*" VALUE(I_FNAME) TYPE FIELDNAME

*" VALUE(I_LANG) TYPE LANG

*" EXPORTING

*" VALUE(E_DATATYPE) TYPE DATATYPE_D

*" VALUE(E_FIELDLENGTH) TYPE DDLENG

*" VALUE(E_DESC) TYPE STRING

*"----


*

*temporary FM created which can retrieve the field details of a table

*

DATA : BEGIN OF wa,

datatype LIKE dd03l-datatype,

leng LIKE dd03l-leng,

reptext LIKE dd03m-reptext,

END OF wa,

itab LIKE TABLE OF wa.

SELECT ldatatype lleng m~reptext

INTO CORRESPONDING FIELDS OF TABLE itab

FROM ( dd03l AS l JOIN dd03m AS m

ON lfieldname EQ mfieldname AND

ltabname EQ mtabname )

WHERE l~tabname EQ i_tname AND

l~fieldname EQ i_fname AND

m~ddlanguage EQ i_lang.

LOOP AT itab INTO wa.

e_datatype = wa-datatype.

e_fieldlength = wa-leng.

e_desc = wa-reptext.

ENDLOOP.

ENDFUNCTION.

*********************RFC End**********************************

and now here is the code that i use in VBA

'*****************VBA start******************************

Set functionCtrl = CreateObject("SAP.Functions")

Set sapConnection = functionCtrl.Connection

sapConnection.client = "xxx"

sapConnection.user = "xxx"

sapConnection.Language = "xxx"

sapConnection.hostname = "xxx"

sapConnection.Password = "xxx"

sapConnection.SystemNumber = "xxx"

sapConnection.Destination = "xxx"

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

MsgBox "No connection to R/3!"

Exit Sub 'End program

Else

MsgBox "Connection to R/3 successful"

' adding the RFC to functionCtrl Object

Set RfcCallTransaction = functionCtrl.Add("ZTAB_FIELD_DET")

RfcCallTransaction.imports("I_TNAME") = "MAKT"

RfcCallTransaction.imports("I_FNAME") = "MAKTG"

RfcCallTransaction.imports("I_LANG") = "EN"

If RfcCallTransaction.Call = True Then

MsgBox "Datatype" + RfcCallTransaction.imports("E_DATATYPE").Value

MsgBox "FieldLength" + RfcCallTransaction.imports("E_FIELDLENGTH").Value

MsgBox "Description" + RfcCallTransaction.imports("E_DESC").Value

Else

MsgBox " Call Failed! error: " + GetCustomers.Exception

functionCtrl.Connection.Logoff

End If

End sub

'************************VBA End*****************************************

When I run this code, connection to SAP is successful but the

>>Set RfcCallTransaction = functionCtrl.Add("ZTAB_FIELD_DET")

shows 'RfcCallTransaction' value as 'Nothing'

and the error message thrown is

"SAP Datatype not supported"

and in the debugger it throws

"Object variable or with block variable not set"

Need your valuable inputs on this

Thanks in advance!

Ranjit.

(P.S. This thread actually should have been posted in ABAP forum but as there was no response i had to post it here.)

Accepted Solutions (0)

Answers (2)

Answers (2)

ranjit_deshmukh
Active Participant
0 Kudos

Actually there was some problem with my export parameter types

after correction it got solved

ranjit_deshmukh
Active Participant
0 Kudos

repost