10-08-2012 2:51 PM
Hi guys.
I'm using RFC_READ_TABLE transaction to parse some data from a table in SAP.
The problem is that I want to get the data for more than one order therefore I use the IN in the query as bellow:
tbloptions.AppendRow
tbloptions(1, "TEXT") = Chr(34) & "WERKS EQ '0012' AND AUFNR IN" & "(" & ordCollector & ")" & Chr(34)
ordCollector is a string variable where I add the order numbers respecting the syntax.
Dim Rand As Long
Dim LRand As Long
LRand = ws.Cells(Rows.Count, 1).End(xlUp).Row
Rand = 2
If LRand = 2 Then
ordCollector = "'" & ws.Cells(Rand, 1).Value & "'"
Else
Do While ws.Cells(Rand, 1).Value <> "" And Rand < LRand
ordCollector = ordCollector + "'" & ws.Cells(Rand, 1).Value & "', "
Rand = Rand + 1
Loop
ordCollector = ordCollector + "'" & ws.Cells(Rand, 1).Value & "'"
End If
with these two pieces of code I wanted to have something like:
tbloptions(1, "TEXT") = "WERKS EQ '0012' AND AUFNR IN ('1234567', '8910111', '2131415')"
I don't know if it' something wrong with the syntax I'm using (if I use chr(24) the workbook stops responding and if I'm not the RFC_READ_TABLE gives me an error.
Any ideas? If you want more details please ask.
Thank you!
10-08-2012 2:52 PM
And if there are some better ways to do this stuff in VBA I'm open to your sugestions!
Thanks!
10-08-2012 5:53 PM
Hi Andrei,
nice code, but use for loop already count no of rows.
LRand = ws.Cells(Rows.Count, 1).End(xlUp).Row
ordCollector = ""
for Rand = 2 to LRand
if trim(ws.Cells(Rand, 1).Value)<>"" then
ordCollector = ordCollector & "'" & ws.Cells(Rand, 1).Value & "', "
end if
next
ordCollector = left(ordCollector , len(ordCollector ) -1 )
Try this
All the best.
Regards,
Viswanathan S
10-08-2012 6:42 PM
Thanks for the tip. The problem is that this piece of code doesn't work. I would appreciate a method to use rfc_read_table for multiple values... (ie. multiple orders in this case). I have the orders in a range and I want to check the material movements on all of them. Any ideas? Thanks guys!
10-09-2012 9:29 AM
Hi Andrei,
can you tell which part code not work. i can explain. multi order or single order its store in ordCollector .
starting row is 2 upto rand to range update in ordCollector.
pls check it and reply.
Regards
Viswanathan S
10-09-2012 10:39 AM
Hi,
This is the part that I believe it doesn't work
tbloptions(1, "TEXT") = Chr(34) & "WERKS EQ '0012' AND AUFNR IN" & "(" & ordCollector & ")" & Chr(34)
I wanted the result of the above code to be something like:
tbloptions(1, "TEXT") = "WERKS EQ '0012' AND AUFNR IN ('1234567', '8910111', '2131415')"
The above piece of code works but when I'm trying it with ordCollector instead of actual order numbers it doesn't work.
In ordCollector I could have even 20 orders... could it be because of it? Are there any limitations to RFC_READ_TABLE? I'm askind this because I know that when I wanted to add multiple coditions I have to do it on more than one row.
10-09-2012 5:49 PM
hi Andrei,
Try this code.
Dim Rand As Long
Dim LRand As Long
LRand = ws.Cells(Rows.Count, 1).End(xlUp).Row
ordCollector = ""
for Rand = 2 to LRand
if trim(ws.Cells(Rand, 1).Value)<>"" then
ordCollector = ordCollector & "'" & ws.Cells(Rand, 1).Value & "', "
end if
next
ordCollector = left(ordCollector , len(ordCollector ) -1 )
tbloptions.AppendRow
tbloptions(1, "TEXT") = "WERKS EQ '0012' AND AUFNR IN (" & ordCollector & ")"
Regards
Viswanathan S
10-09-2012 8:28 AM
10-09-2012 12:13 PM
Problem solved. Instead of IN I'll use OR for tbloptions. It works great!
05-17-2013 2:04 PM
Hi Andrei,
Actually Im facing the same trouble!
You understand me man, was a long searching on the web to finally found this,
Unfortunately for me the same error keeps poping up, "System Failure",
Could you please share your solution=?, Im using table MARD, with several material numbers,
I tried:
tbloptions(1, "TEXT") = "WERKS EQ '7034' AND MATNR OR (" & ordCollector & ")"
Is this how you did it?
Please help!!
01-30-2015 2:58 PM
Hello,
I've got the same problem, please explain your solution in more details.
Thank you,
Csaba
01-30-2015 5:54 PM
I think instead of:
WERKS EQ '0012' AND AUFNR IN ('1234567', '8910111', '2131415')
he used:
WERKS EQ '0012' AND (
AUFNR EQ '1234567' OR
AUFNR EQ '8910111' OR
AUFNR EQ '2131415'
)
02-03-2015 10:41 AM
02-27-2015 1:03 PM
You have to take a close look at the length of each options statement - when these data is transfered to the SAP functionmodule it happens i text lines of 72 characters each! This meens that you have to think in "line mode" when you build up your options, and one more thing - it is a good idea to start each line with a blank character (try to imagine how the final SQL-statement will look like, when all ljnes are put together in the end).
Regards Dan