Show TOC

Using Programs to Retrieve DataLocate this document in the navigation structure

Prerequisites

You have created an InfoSet and specified a description and a Authorization Group on the InfoSet: Title and Database screen.

For more information, see Assigning Data Sources.

Context

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.

Note

From the InfoSet: Initial Screen, you follow the menu path Start of the navigation path InfoSet  Next navigation step More Functions Next navigation step Integrate External Reading Program End of the navigation path.

Procedure

  1. You are on the InfoSet: Title and Database screen and select the Use a Program to Retrieve Data field.
  2. Specify a data structure. This structure must describe the structure of the records in the dataset that you want to report on.
  3. 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.

    Caution

    If you transport an InfoSet that uses an external program to retrieve data, you must make sure that the InfoSet and the external program are transported together.

  4. Choose Continue.
  5. 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)

    Caution

    If you arrange the components of the model report in an inappropriate sequence, SAP Query may generate meaningless reports.

    The character strings for the two comment lines *<QUERY_HEAD> and *<QUERY_BODY> are set to begin immediately after the "<" character. The system does not make a distinction between capital letters and lower case letters.

    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.

For more information, see Special Features.

Note

When you create a query for an InfoSet that uses a program to retrieve its data, the model report is used as a template when the query report is generated. The attributes of the model report are passed on to the generated reports. The model report itself is not changed as a result of this process.

This means that you also have the option of using a logical database to organize the data retrieval process. We recommend that, as a rule, you create the InfoSet directly using the logical database.

Example

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.