使用JCo库限制从SAP接收的记录数量

huangapple go评论71阅读模式
英文:

Limit number of records to be received from SAP using JCo library

问题

假设在SAP表中有100条记录,我只想访问其中的5条。当我调用BAPI函数执行时,它会将所有100条记录加载到内存中,然后我才能对它们进行迭代。

在执行BAPI函数之前如何将记录限制为5条?

我不能要求客户限制表中的记录数量,因此我必须使用JCo库编写代码来实现这一点。

英文:

Suppose there are 100 records in one of the SAP tables and I want to access only 5 of them. When I call for BAPI function execution, it brings all 100 records in memory and then only I can iterate on them.

How to limit records to 5 before I execute BAPI function?

I cannot ask client to limit number of records in table itself, so I have code it using JCo library.

答案1

得分: 1

一个像这样的功能必须在BAPI本身中实现。实际上,一些BAPI具有允许限制BAPI返回结果集的WHERE子句。

但是从“外部”(即从JCo层)无法影响BAPI将返回的结果。至少不能在如此细粒度的级别上影响:有一个功能可以“关闭”整个表,如果您调用返回多个表的BAPI(并且从数据库为它们选择数据需要大量时间),但您只对其中的一些表感兴趣。然后您可以将其他表设置为“非活动”,后端的RFC层将仅返回活动表的数据。(如果BAPI以智能方式编程,它会预先确定哪些表是活动的,并跳过非活动表的SELECT语句。)

以下是一小段示例代码,用于禁用名为“TABLE_NAME”的BAPI表:

JCoFunction myBapi = ...;
JCoParameterList tables = myBapi.getTableParameterList();
tables.setActive("TABLE_NAME", false);
// 现在您可以执行myBapi,后端系统将不会返回名为TABLE_NAME的表的数据。
英文:

A functionality like this would have to be implemented in the BAPI itself. In fact, some BAPIs have a WHERE clause that allows to limit the result set that the BAPI will return.

But "from the outside" (i.e. from the JCo layer) you cannot influence the result that the BAPI will return. At least not on such a fine granular level: there is the feature to "turn off" an entire table, which can be used, if you call a BAPI that returns dozens of tables (and spends lots of time selecting the data for them from the database), but you are interested only in a few of these tables. Then you can set the other tables to "inactive", and the RFC layer of the backend will only return the data for the active tables. (And if the BAPI is programmed in an intelligent way, it determines beforehand, which tables are active and skips the SELECT statements for the inactive ones.)

Here is a bit of sample code, that deactivates a BAPI's table with name "TABLE_NAME":

JCoFunction myBapi = ...;
JCoParameterList tables = myBapi.getTableParameterList();
tables.setActive("TABLE_NAME", false);
// Now you can execute myBapi, and the backend system will not return 
// data for the table named TABLE_NAME.

huangapple
  • 本文由 发表于 2020年3月16日 20:24:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/60705985.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定