使用外部程序为Query提供数据

Query 很强大,通过下面的Help说明,可以实现使用ABAP程序来为InfoSet提供数据源,然后再作进一步的处理。

Retrieving Data with Programs

If you want to make evaluations for datasets, but SAP Query automatic data retrieval is not sufficient for the task, create an InfoSet by selecting the field Data Retrieval with Program in the Title and Database screen, then specify a program name and the name of a structure. This structure must reflect the record structure of the dataset you want to evaluate.

 

If you use the component Maintain Queries to create a query for this InfoSet, SAP Query uses the report as a model when generating the query report; the model report itself thus remains unchanged.

 

Before generating the InfoSet for the first time, you must create the model report yourself in the ABAP editor. The model report has to be syntactically correct and have the same definition for fixed point arithmetic as the InfoSet. It is not, however, intended that the model report itself be executed.

 

The structure of this model report and the sequence of its parts are regular. The main structure of a model report is given below.

Report xxxxxxxx .

 

Tables tab .

Definition of Dictionary structure used to set up the InfoSet. This structure must contain the records you want to evaluate.

Parameters .

Definition of parameters, selection criteria, and fields.

Select-Options:…

 

DATA :…

 

DATA: BEGIN OF itab OCCURS xxx.

INCLUDE STRUCTURE tab.

DATA: END of itab.

Definition of an internal table <itab> with structure <tab> which provides the records you want to evaluate.

* <Query_head>

This comment must always appear after your data declarations.

* Code to define the table itab, if such a table is used.

* Beginning of a loop to retrieve each record and place it in the structure tab (SELECT, DO, LOOP, …)

* Code for formatting data (if necessary)

 

* <Query_body>

This comment must always be the last ’statement’ in the loop. The data must be available in structure tab.

* End of data retrieval loop for individual records (ENDSELECT, ENDDO, ENDLOOP;…)

 

 

 

Note : If the model report components are in the wrong sequence, SAP Query may generate meaningless reports. The character strings of the two comment lines *<QUERY_HEAD> and *<QUERY_BODY> are fixed to start immediately after the character “<”, but the system does not distinguish between upper and lower case.

 

Continue:

Generating the InfoSet is possible only if the model report exists, conforms to the above conventions, is free of syntax errors and has the correct fixed point arithmetic setting.

 

When you generate query reports which use a model report, the generated reports inherit the attributes of the model report. In the end, this allows you to retrieve data by using a logical database. However, you should only make use of this option in special cases, since if you are using a logical database, it is better to set up the InfoSet this way also.

 

Below is a model report which uses the SELECT statement:

*————————————————————————–

* data retrieval program for functional area FLDP

*————————————————————————–

REPORT AQ00FLDP.

 

TABLES SAPLANE.

 

SELECT-OPTIONS TYPE FOR SAPLANE-PLANETYPE.

 

*<Query_head>

select * from saplane where planetype in type.

*<Query_body>

endselect.

 

Below is a model report which uses the LOOP statement:

*————————————————————————–

* data retrieval program for functional area FLDX

*————————————————————————–

REPORT AQ00FLDX.

 

TABLES: SAPLANE, INDX.

 

DATA: PLANEDATA LIKE SAPLANE OCCURS 100 WITH HEADER LINE.

 

SELECT-OPTIONS TYPE FOR PLANEDATA-PLANETYPE.

 

*<Query_head>

IMPORT PLANEDATA FROM DATABASE INDX(PL) ID ‘PLANEDAT’.

LOOP AT PLANEDATA WHERE PLANETYPE IN TYPE.

MOVE-CORRESPONDING PLANEDATA TO SAPLANE.

*<Query_body>

ENDLOOP.

 

The data is retrieved and placed in an internal table which is filled by an import from the INDX. In the LOOP structure, each line must be read from PLANEDATA into SAPLANE because the InfoSet was created via the structure SAPLANE and the query expects the data in a field string called SAPLANE.

 

You can see all the options available for you to use with InfoSets using logical databases in the screen for InfoSet maintenance, for example connecting additional tables and the definition of additional fields, and so on. Make a special note of the special features called Sequential Datasets at the end of the section.

 

InfoSets which retrieve data using a program, offer you a wide range of options. In a model report, there are no restrictions on how you should organize the retrieval of your data. Therefore you can use very complex algorithms. SELECT statements that read on a cross-client basis can also be used (option CLIENT SPECIFIED).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值