cancel
Showing results for 
Search instead for 
Did you mean: 

how to specify PACKAGE SIZE for to RFC_READ_TABLE from PyRFC?

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

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'])

Former Member
0 Kudos

Ok I think I figured it out.

FIELDS must use the returned FIELDS structure (an array of dicts), so something like parameters['FIELDS']=[{'FIELDNAME':'MANDT''}, {'FIELDNAME':'BUKRS'}] works.

Answers (0)