cancel
Showing results for 
Search instead for 
Did you mean: 

How to use RFC_GET_TABLE_ENTRIES in Excel VBA ?

taketake
Explorer
0 Kudos

Hi Gurus!

Could you please help me?

Now I'm writing the excel vba for getting the data record entries number.

I used the RFC_GET_TABLE_ENTRIES and the source cord is as below.

This vba macro has been compiled and can run with no error.

And if the target table has small number of records, this vba PGM can get right data.

However if the target table has larger number of records than 32768, this vba PGM get wrong data.

For example if the table has 146448 records, this vba get 15376 number.

I think this is due to differences in type between abap and VBA.

Because 146448 divided by 32768 equals four, with a remainder of 15376.

The data type INT2 has range -32,768 to 32,767. So I afraid the object rfcFunc.imports("NUMBER_OF_ENTRIES") in source cord has been replace INT2 by system.

Could you please teach me how to modify properly in VBA PGM ?

Public Function FUNC_CALL(ApplicationServer, Client, User, System, SystemNumber, Password, Language, I_Sheet) As String
' --------------------------------------------------------------
' declare the variable
' --------------------------------------------------------------
' R/3 connection variable - - - - - - - - - - - - - - - - -
Dim R3          As Object 
Dim rfcFunc     As Variant 

Dim QUERY_TABLE As Object ' IMPORT1
Dim DELIMITER   As Object ' IMPORT2
Dim NO_DATA     As Object ' IMPORT3
Dim ROWSKIPS    As Object ' IMPORT4
Dim ROWCOUNT    As Object ' IMPORT5
Dim USERNAME2   As Object

Dim OPTIONS As Object     ' TABLES1
Dim FIELDS  As Object     ' TABLES2
Dim DATA    As Object     ' TABLES3

Dim Result  As Boolean  '

Dim iRow    As Integer  '
Dim iColumn As Integer  '

Dim iField  As Integer  '
Dim iStart  As Integer  '
Dim iLength As Integer  '
Dim vField  As Variant  '
Dim table

Dim ws As Worksheet

Dim Destination_System As Integer
Dim objBAPIControl As Object 'Function Control (Collective object)
Dim sapConnection As Object 'Connection object
Dim objUserList As Object
Dim objUserDetail As Object

Dim returnfunc As Boolean

Dim i As Integer
Dim j As Integer

Dim WK_CNT As Object

Dim RecordNo As Object
Dim RecondNo_I As Long
'---------------------------------------------------------------
'Connection R3
'---------------------------------------------------------------
Set R3 = CreateObject("SAP.Functions")        
R3.Connection.ApplicationServer = ApplicationServer  
R3.Connection.Client = Client              
R3.Connection.User = User                 
R3.Connection.System = System               
R3.Connection.SystemNumber = SystemNumber         
R3.Connection.Password = Password             
R3.Connection.Language = Language                 
FUNC_CALL = 0

' Login
If R3.Connection.Logon(0, True) <> True Then
    MsgBox "R/3 failed login"
    FUNC_CALL = 1
    Exit Function
End If
'---------------------------------------------------------------
'CALL RFC_GET_TABLE_ENTRIES
'---------------------------------------------------------------
Set rfcFunc = R3.Add("RFC_GET_TABLE_ENTRIES")

Set MAX_ROW = rfcFunc.exports("MAX_ENTRIES") 
Set TableName = rfcFunc.exports("TABLE_NAME")

Set RecordNo = rfcFunc.imports("NUMBER_OF_ENTRIES")

MAX_ROW.Value = "1"
TableName.Value = "TSP01"

Result = rfcFunc.Call

If Result = True Then

Else
    MsgBox rfcFunc.Exception
    R3.Connection.Logoff
    Exit Function
End If
'
 LastRow2 = Sheets("SPOOL").Cells(Rows.Count, 1).End(xlUp).Row
 wk_end2 = LastRow2
'
 WK_CNT2 = wk_end2 + 1
'
 Sheets("SPOOL").Cells(WK_CNT2, 1).Value = I_Sheet
 Sheets("SPOOL").Cells(WK_CNT2, 2).Value = RecordNo.Value

R3.Connection.Logoff

End Function


Accepted Solutions (1)

Accepted Solutions (1)

taketake
Explorer
0 Kudos

I have solved this problem by myself.

The status of "RFC_GET_TABLE_ENTRIES" is "not released".

Therefore this module cannot get SAP support.

So I copied "RFC_GET_TABLE_ENTRIES" and make new another function module. And I changed the type of NUMBER_OF_ENTRIES from INT4 to char 20, then I can get right figure.

Thanks.

Answers (0)