通过 PyRFC 在 RFC_READ_TABLE 调用中打开 SQL 条件 [英] Open SQL condition in RFC_READ_TABLE call via PyRFC

查看:45
本文介绍了通过 PyRFC 在 RFC_READ_TABLE 调用中打开 SQL 条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 PyRFC 在 RFC_READ_TABLE 查询中指定 Open SQL WHERE 子句?

How do I specify the Open SQL WHERE clause in an RFC_READ_TABLE query using PyRFC?

我正在尝试开始使用 PyRFC,让 python 从 SAP 中提取表(在没有支持/合作基础团队的情况下).在这个例子中来自 http://scn.sap.com/community/scripting-languages/blog/2012/11/04/revisiting-python-and-sap-with-pyrfc,他们使用:

I'm trying to get started with PyRFC to have python do table extractions from SAP (in the absence of a supportive/cooperative basis team). In this example from http://scn.sap.com/community/scripting-languages/blog/2012/11/04/revisiting-python-and-sap-with-pyrfc, they use:

pyrfc.Connector.call("RFC_READ_TABLE", QUERY_TABLE=table, DELIMITER='|')

http://saplsmw​​.com/node/101 表示需要传递 WHERE 子句作为 RFC 调用的一个选项.我如何在 PyRFC 中做到这一点?(OPTIONS是SAP端RFC_READ_TABLE的功能模块声明中table类型的导出变量).

http://saplsmw.com/node/101 says that a WHERE clause needs to be passed as an OPTION to the RFC call. How do I do this in PyRFC? (OPTIONS is an exporting variable of type table in RFC_READ_TABLE's function module declaration on the SAP end).

好的 http://scn.sap.com/community/scripting-languages/blog/2014/05/05/python-for-basis 有一个在 OPTIONS 中发送 WHERE 子句的例子:

OK http://scn.sap.com/community/scripting-languages/blog/2014/05/05/python-for-basis has an example of sending the WHERE clause in OPTIONS:

OPTIONS = [{'TEXT':source_where}])

所以看起来语法是单元素字典的数组(映射 SAP 表类型),其中键是 SAP 数据类型,值是 WHERE 子句.

So it looks like the syntax is an array (maps the SAP table type) of single element dictionaries where the key is the SAP data type and the value is the WHERE clause.

那么下一个问题是:如何指定要发送到 RFC_READ_TABLE 的 PACKAGE SIZE 以便我可以在不达到内部表限制的情况下提取大表?

So next question is: How do I specify a PACKAGE SIZE to be sent to RFC_READ_TABLE so that I can extract large tables without hitting internal table limits?

推荐答案

RFC_READ_TABLE 有一个参数ROWCOUNT",它指定在一次调用中返回的最大行数.

RFC_READ_TABLE has a parameter 'ROWCOUNT' which specifies the maximum number of rows to return in a single call.

当然,如果您说将其限制为一次 1000 行,那么如果表包含的行超过 1000 行,那么您可能永远不会下载其他行.

Of course, if you say restrict it to 1000 rows at a time there may be other rows that you never download if the table contains more than 1000 rows.

为了解决这个问题,还有另一个参数ROWSKIPS",您可以通过它指定要返回的起始行.

To solve this there is another parameter, 'ROWSKIPS' through which you specify the starting row you want to return.

所以,第一次调用行数 = 1000ROWSKIPS = 0

So, with the first call ROWCOUNT = 1000 ROWSKIPS = 0

下一个电话行数 = 1000ROWSKIPS = 1000

The next call ROWCOUNT = 1000 ROWSKIPS = 1000

下一个电话行数 = 1000ROWSKIPS = 2000

The next call ROWCOUNT = 1000 ROWSKIPS = 2000

依此类推,每次按如下方式递增 ROWSKIPS:ROWSKIPS = ROWSKIPS + ROWCOUNT.

and so on, incrementing ROWSKIPS each time as follows: ROWSKIPS = ROWSKIPS + ROWCOUNT.

同时定义了 ROWCOUNT 和 ROWSKIPS 的 PyRFC 调用示例,它以 10 个批次从 TCURR 中读取(其中 FCURR 设置为USD"):

An example PyRFC call with both ROWCOUNT and ROWSKIPS defined, which reads from TCURR in batches of 10 (and where FCURR is set to 'USD'):

#!/usr/bin/env python
from pyrfc import Connection, ABAPApplicationError, ABAPRuntimeError, LogonError, CommunicationError
from ConfigParser import ConfigParser
from pprint import PrettyPrinter

def main():

    try:

        config = ConfigParser()
        config.read('sapnwrfc.cfg')
        params_connection = config._sections['connection']
        conn = Connection(**params_connection)

        options = [{ 'TEXT': "FCURR = 'USD'"}]
        pp = PrettyPrinter(indent=4)
        ROWS_AT_A_TIME = 10 
        rowskips = 0

        while True:
            print u"----Begin of Batch---"
            result = conn.call('RFC_READ_TABLE', \
                                QUERY_TABLE = 'TCURR', \
                                OPTIONS = options, \
                                ROWSKIPS = rowskips, ROWCOUNT = ROWS_AT_A_TIME)
            pp.pprint(result['DATA'])
            rowskips += ROWS_AT_A_TIME
            if len(result['DATA']) < ROWS_AT_A_TIME:
                break

    except CommunicationError:
        print u"Could not connect to server."
        raise
    except LogonError:
        print u"Could not log in. Wrong credentials?"
        raise
    except (ABAPApplicationError, ABAPRuntimeError):
        print u"An error occurred."
        raise

if __name__ == '__main__':
    main()

这篇关于通过 PyRFC 在 RFC_READ_TABLE 调用中打开 SQL 条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆