You can use a program that reads data to generate dataset reports that use the automatic data retrieval process in the SAP Query.
You can convert an InfoSet that uses an external data-reading program into an InfoSet with an integrated data-reading program.
Procedure
You are on the InfoSet: Title and Database screen and select the Use a Program to Retrieve Data field.
Specify a data structure. This structure must describe the structure of the records in the dataset that you want to report on.
The Integrated Program option is set by default. This is the most suitable option in most cases.
If you do want to use an external program, specify the name of the program in the External Program input field.
Choose Continue.
Create a data-reading program before you generate the InfoSet for the first time.
You use the editor in the InfoSet maintenance if you are working with an
integrated data-reading program.
External data-reading program ABAP Editor
The data-reading program must meet the following requirements:
Its structure must conform to certain conventions.
It must not contain any syntax errors.
It must use the same fixed point arithmetic as the InfoSet (if it is an external data-reading program).
The data-reading program is not intended to be executed itself.
The basic structure and operating sequence of a data-reading program is as follows:
Report xxxxxxxx.
Tables tab.
Definition of the dictionary structure used to set up the InfoSet. This structure must contain the records that you want to report on.
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 providing the records that you want to report on.
* <Query_head>
Comment to finish off a data statement.
* Code to define the itab table, if such a table is used.
* Start of a loop to retrieve, one at a time, each of the records that you want to report on, and place them in the tab structure (SELECT, DO, LOOP)
* Code for formatting data
* <Query_body>
Comment to finish the statement in the loop. The data must be available in the tab structure.
* End of data retrieval loop for individual records (ENDSELECT, ENDDO, ENDLOOP)
In a model report, there are no restrictions on how you should organize the retrieval of your data. This means that you are able to use very complex algorithms to retrieve data, if you so wish. You can also use SELECT statements that read on a cross-client basis (CLIENT SPECIFIED extra).
Internal and external data-reading programs may also contain selections. These are displayed as standard selections on the InfoSet: Change or Display screen in the overview of selections (). The system checks the program for selections regularly:
Internal data-reading programs for every change made to the data-reading program.
External data-reading programs for calls of transaction SQ02 for the InfoSet.
Results
In the maintenance screens for an InfoSet that uses an integrated program to retrieve data, you have the same options available to you as you do when you are working with InfoSets that use other data sources.
The following text shows a model report that uses the SELECT statement:
*-------------------------------------------------------*
* data retrieval program for functional area FLDP *
*-------------------------------------------------------*
report aq00flcp.
tables saplane.
select-options type for saplane-planetype.
*<Query_head>
select * from saplane where planetype in type.
*<Query_body>
endselect.
The following text shows a model report that 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 that is filled by a data import from the INDX. In the LOOP structure, each line must be read from PLANEDATA into SAPLANE. This is because the InfoSet has been created using the SAPLANE structure, and the query is expecting the data in a field string with the name SAPLANE.