Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8122

VBA using RFC_READ_TABLE works with all tables but with MARD...

$
0
0

Hi,

I'm struggling for several days on this topic.

Already found lots of info on scn.sap.com.

But I still can't understand why MARD seems to crash my vba macro ... which works perfectly on other tables.

 

I'm using the code below to extract SAP data onto Excel spreadsheets.

I tested with MARC, MBEW, MARA... it all works perfect.

But if I put "MARD" then I get "SYSTEM FAILURE".

Does anybody have any idea about what should I do ?

 

Thanks a lot in advance.

Nicolas

 

VBA code below :

 

Sub getSAPdata()

 

Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object

If sapConn.Connection.Logon(0, False) <> True Then 'Try Logon

   MsgBox "no SAP connection"

End If

 

Set objRfcFunc = sapConn.Add("RFC_READ_TABLE")

Set objQueryTab = objRfcFunc.Exports("QUERY_TABLE")

Set objRowCount = objRfcFunc.Exports("ROWCOUNT")

objRowCount.Value = "99999999"

Set objOptTab = objRfcFunc.Tables("OPTIONS")

Set objFldTab = objRfcFunc.Tables("FIELDS")

Set objDatTab = objRfcFunc.Tables("DATA")

 

 

objQueryTab.Value = "MARD" 'TABLE. Works with MARC, MBEW, MARA... not with MARD ?!?

 

objOptTab.FreeTable

objOptTab.Rows.Add

objOptTab(objOptTab.RowCount, "TEXT") = "MATNR = 'DTR0000122361-A'"

 

objFldTab.FreeTable

objFldTab.Rows.Add

objFldTab(objFldTab.RowCount, "FIELDNAME") = "MATNR"

 

If objRfcFunc.call = False Then

   MsgBox objRfcFunc.Exception 'I get "SYSTEM FAILURE" with MARD

End If

 

Dim objDatRec As Object

Dim objFldRec As Object

For Each objDatRec In objDatTab.Rows

   For Each objFldRec In objFldTab.Rows

      Cells(objDatRec.Index + 1, objFldRec.Index) = _

            Mid(objDatRec("WA"), objFldRec("OFFSET") + 1, objFldRec("LENGTH"))

   Next

Next

End Sub


Viewing all articles
Browse latest Browse all 8122

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>