on 02-02-2014 1:48 AM
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
Nicholas,
As Jim said better not to use RFC_READ_TABLE because it is not released for Customer usage.It could be due to large amount of data.If in D and Q itself if you are facing problems with this FM then just imagine what will be the case in Production where it is bound to process huge no.of data.
Better go through SAP Service Market Place search for RFC_READ_TABLE.You will be getting more info on the usage of this FM and its pros and cons.
K.Kiran.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all,
i have registered only to let you know that i have solution
Use BBP_RFC_READ_TABLE function instead of RFC_READ_TABLE.
it works for me and download data from MARD and MARC tables ( i have checked only it, but probably it will work for other also).
Additionally i have read that BBP* function is more stable and work with larger amount of data. You need to test it.
it would be nice if it will help someone too.
Hi,
Ideally it should work, its not a big problem with MARD!
I am not sure on below code! can you try with other material
objOptTab(objOptTab.RowCount, "TEXT") = "MATNR = 'DTR0000122361-A'"
As per the RFC FM it should be pass in SAP like this
( MATNR EQ 'DTR0000122361-A' )
Can you check the rfc connection also
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What if you pass few columns only for selection?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nabheet,
Thanks for your suggestion.
I gave it a try and modified the code to add additional selection.
It failed with MARD again... but adding extra selection fields also crashes on table MARC which worked before.
There may be an error in my code (modifications in blue below) ...
Regards
Nicolas
For info, with the selection on material number (matnr) only, I get 8 records from MARC & would expect 8 from MARD.
With selection on Material (matnr) & Plant (werks), I shall get 1 hit from MARC, and 2 from MARD.
Code
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 = "MARC" 'TABLE. Works with MARC, MBEW, MARA... not with MARD ?!?
objOptTab.FreeTable
objOptTab.Rows.Add
objOptTab(objOptTab.RowCount, "TEXT") = "MATNR = 'DTR0000122361-A'"
objOptTab.Rows.Add
objOptTab(objOptTab.RowCount, "TEXT") = "WERKS = '3810'" 'STRANGE, adding this selection criteria makes it crash "SYSTEM FAILURE", on MARD, but also on MARC (which worked before).
objFldTab.FreeTable
objFldTab.Rows.Add
objFldTab(objFldTab.RowCount, "FIELDNAME") = "MATNR"
objFldTab.Rows.Add
objFldTab(objFldTab.RowCount, "FIELDNAME") = "WERKS"
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
Hi,
RFC_READ_TABLE cannot handle large rows.
There was an old note 758278 which should be relevant, but unfortunately it's not visible.
You need to use a customer function module instead of RFC_READ_TABLE as it's not released to customer.
Thanks.
Jim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jim,
Firstly : thanks a lot for answering.
I'm not sure to understand what you say "RFC_READ_TABLE cannot handle large rows".
With the material number I used for selection, I get 8 record rows from MARC, 18 from MBEW, and shall get (but it fails) 8 from MARD (according to SE16 extract).
Moreover, MARD table has less fields that MARC or MBEW.
Therefore how could MARD data be "larger" than the previous extractions made successfully ?
Did I understand wrong ?
You suggest to use customer function module.
I must confess I'm no expert at all ; is this feasible by calling it from VBA/Excel as I'm trying to do ?
Thanks again
Nicolas
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.