on 06-11-2014 10:57 PM
I'm trying to use PyRFC to extract large tables via RFC_READ_TABLE (due to an uncooperative/unsupportive basis team).
I know that RFC_READ_TABLE supports calling it with PACKAGE SIZE since ERPConnect does it by default.
In , I learned how to specify an Open SQL where clause using the OPTIONS:
result = connector.call('RFC_READ_TABLE',
QUERY_TABLE=tablename,
DELIMITER=delimiter,
OPTIONS = [{'TEXT':where_clause}])
Is there a way, and how to specify PACKAGE SIZE in this case?
Thanks
Hi,
the package size works, but you need to call the function module multiple times in a loop. Here's an excerpt of the attached script:
recordcounter = 1 #needs to be >0 to get the while loop going
iteration = 0 #the number of times the function module got called
while recordcounter > 0: #as long as the function module calll returns rows...
tempresult = self.call('RFC_READ_TABLE',
ROWSKIPS=iteration*fetchsize, #defines the number of rows to skip
**parameters)
iteration=iteration+1 #increase the iteration
data = tempresult['DATA'] #assign the returned rows to a variable
if len(data) > 0: #have there been any rows?
for row in data: #Do something with them
...
else:
recordcounter=0 #set recordcounter to 0 to end the while loop.
The script is far away from being perfect. It doesn't deal with RAW fields and the data types it returns are all strings. It does what I needed it to do but it may not be sufficient for what you may be trying to achieve.
Best regards
Lars
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
in your example code, you do:
if 'tabfields' in kwargs.keys():
tabfields=kwargs['tabfields']
# parameters['FIELDS']=tabfields
for field in kwargs['tabfields']:
parameters['FIELDS'].append([field])
else:
tabfields=''
This results in a keyerror because parameters['FIELDS'] has not been initialized before calling append([field]).
If I do intialize it, then pyrfc will fail when specifying a list of fields: tabfields = ['MANDT']:
AttributeError: 'str' object has no attribute 'iteritems'.
For example:
parameters['QUERY_TABLE'] = 'T001'
parameters['FIELDS'] = ['MANDT','BUKRS']
connection.call('RFC_READ_TABLE', NO_DATA='X', **parameters)
will fail with
AttributeError: 'str' object has no attribute 'iteritems'
(same thing with:
foo = conn.call('RFC_READ_TABLE',NO_DATA='X',QUERY_TABLE='T001',FIELDS=['MANDT','BUKRS'])
User | Count |
---|---|
81 | |
25 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.