Chapter:2 ABAP Query: Report Development Tools 1
Chapter:2 ABAP Query: Report Development Tools 1
Review.................................................................................................................. 2–33
Where to Learn More........................................................................................... 2–33
In this chapter, you will learn about ABAP Query, a tool that lets you present data from
database tables in report lists. Before getting into how you can use ABAP Query to create
reports, it is important to understand its features and basic organization.
ABAP Query
Functional
Functional User
User
Queries
Queries
Areas
Areas Groups
Groups
Statistical
Statistical Basic
Basic Ranked
Ranked
List
List List
List List
List
Functional Areas
You need functional areas to offer a preselected set of data to the user, depending on the
task to be accomplished. A functional area defines the tables—and the fields within those
tables—which can be queried. Functional areas use a logical database, a direct read from a
table, or a series of table joins to determine the available tables.
User Groups
User groups link users to functional areas and queries and control the functional areas and
queries a user can access. Each functional area is assigned to one or more user groups. For
access to ABAP Query, a user must be a member of at least one user group. All members of
a user group can access the same data as well as the same programs (queries) to create lists.
Queries
When you create different lists using ABAP Query, you can save the layout for each list. The
element created is called a query. A query is specific to a user group and functional area.
When creating a query, you may only select one functional area. Within a query, you must
also specify functional groups in the selected functional area. This means the selected area
(and the groups) must contain all the fields you wish to include in the query.
Using queries
If appropriate authorizations are in place, you can execute, modify, copy, and delete
queries. Any modifications to queries affect all users of a user group. That is, if one user
deletes a query, it is lost for all other users as well. All changes or new creations are at
once visible to all users.
Starting with Release 4.0, queries can have 12-character names. Prior releases were limited
to two-character names.
Related Terminology
Logical database: A series of tables that are linked together via a logical database
program.
Functional groups: Part of a functional area. You create functional groups within a
functional area and then assign the fields you want to query to the functional group.
Logical database
To retrieve data, ABAP provides an extra read program called a logical database. This
program reads the required data and provides it to you in the correct order. You only
write the statements that process the data. To take advantage of this functionality for your
report program, you must declare the logical database in the report attributes.
SAP delivers several logical databases in the application areas and gives a user the
capability of creating their own. We strongly recommend that a basis/tools expert be
involved in the creation of a logical database. To view the delivered SAP logical databases,
follow the menu path: Tools ABAP Workbench Development Programming
Environment Logical Databases, or use transaction code SE36.
Functional groups
If a field is not assigned to a functional group, it cannot be included in a query. Functional
groups have two-character names and are functional-area dependent. There are no
naming restrictions for functional groups.
In this section a guided tour shows you how to create a report using ABAP Query. This
step-by-step approach is built around a sample report (see the graphic below). We suggest
you take a few minutes to familiarize yourself with the scenario and the desired report.
Example: Bungee Corporation wants to view the account history for several G/L
accounts at a time—in a specified format. While they like many of the standard reports
provided in R/3, they would prefer to change the order of the columns. Bungee
Corporation believes that in the future they will include fields from internal tables, and
thus would like to begin creating custom reports. Additionally, the company wants to be
able to print the General Ledger history.
Shown below is a preview of the General Ledger History report with all the desired
functionality. For this query, we will create a functional area using a logical database. This is
an easy and effective way to start creating queries.
Note: In the example we use Release 4.0B. While this release has a different look-and-
feel than prior releases, the underlying concepts and terminology remain the same.
The main steps in creating a query are shown in the graphic below.
1 Create
Create aa
functional
functional area
area
2 Assign
Assign required
required fields
fields to
to
functional groups
functional groups
3 Generate
Generate the
the
functional
functional area
area
Create
Create aa
4Trained Employee
userAvailable?
user group
group
5 Assign
Assign the
the functional
functional area
area
to
to the
the user
user group
group
6 Create
Create the
the query
query
Guided Tour
11
13
The next step is to add an additional table that does not exist in the logical database. In this example, the
G/L account description is not stored in any of the logical database tables; it is stored in table SKAT. We
need to add table SKAT to table SKA1 (shown below) because all the key fields of table SKAT are available
in table SKA1.
4. Click on the node for SKA1 to
select the table in the Change
Functional Area ZZ_GL_DETAIL
5
screen.
5. Choose Extras in the toolbar to
add an additional table.
6. Choose Create.
10
11
We will now look at the same logical database (SDF), but at a different table (BSEG). The next step is to add
an additional field—in this example, the dollar amount in table BSEG is stored as an absolute value. The
online system uses the posting key to determine if the additional field is positive or negative. We need to
add an additional field that would contain the amount with the proper sign so that the final totals are
correctly calculated.
12
14
27
11
12
30
Note: You must remember where the line breaks occur (for example between the G/L account long text
and the accounting document number). The long text is on line 1 and the document number starts line 2.
39
41
42. To enter a date, time, page, or
name, put your cursor in the white
line in the Page header section and
43
type &%DATE, &%TIME, &%page, or
the appropriate variable name. To 44
insert additional lines, double-
click on the white line.
42
43. Choose Save.
44. Congratulations! Your query is
now ready to run. Choose Execute
to run the query.
Creating variables
In the functional area, you can use available selection criteria to customize specific fields
(variables) for entry at execution time. These new variables work for all queries created
within the functional area. You can set up selection options and parameters that work just
like the ABAP code statements Select-Options and Parameters.
With these selection options you can make the variables:
Work with their matchcodes
Mandatory fields
Display only
Highlighted
Set defaults
The following example explains how to customize the variables from within the functional
area.
1. From the SAP main menu choose System Services ABAP Query, then Tools ABAP
Workbench Utilities ABAP Query Functional Areas.
2. In the Functional area field, enter the name of the functional area to be changed and click
the Change button (not shown).
3. In the Change Functional Area screen, choose Selections (not shown).
4. If the functional area was created using a logical database, the database selection criteria
will appear. Do not add these fields again or try to change them. If the functional area
was created using table joins or direct table reads, this table will be empty which means
there are no pre-defined selection criteria included in the functional area. You will need
to manually add all the desired fields as selection criteria.
7. Select Selection criterion. Since parameters only allow one value, this selection gives you
the most flexibility to enter multiple values and ranges.
8. Choose Enter.
10
11
12
9. Enter the description and selection text for the field. In this example, Cost Center is
added.
10. Enter the name of the field being added in the FOR statement.
11. In the Extras statement, enter any criteria for the field. In this example, the cost center
field is made a mandatory field with matchcode capabilities.
12. Choose Enter.
Table joins became available with Release 3.0C. If just a few tables are being used to create
a functional area, tables joins can be more efficient than logical databases. However,
logical databases are essential for hierarchical processing. Table joins should be considered
for performance reasons when creating the functional area.
Only inner table joins are available in the standard 4.0x releases. Left outer tables joins are
available in Release 4.5x. If left outer joins are needed in a 4.0x system, refer to OSS note
130837 on how to retrofit this functionality.
OSS note 48296 is also helpful when working with tables joins.
What follows is an example of starting a functional area with a table join. The example stops
at the point where you begin adding fields to the functional groups. For more information
on how to add fields to the functional groups and to finish the configuration of the
functional area, see page 11.
1. From the SAP main menu choose System Services ABAP Query, then Tools ABAP
Workbench Utilities ABAP Query Functional Areas.
2. In the Functional area field, enter the name of the functional area to be created and choose
Create.
4
5
7. Enter the names of the other tables that are needed in the functional area.
8. Choose Define condition to define the link between the two selected tables.
9. The tables appear in the Join conditions (right side of the screen).
10. Choose Specify conditions to define the join.
9 10
11. You are prompted for proposals for the table join. Choose Yes and the system will
propose the join conditions.
13
12
12. The proposed join between MARD and MARC is the material number and the plant.
These are the two key fields on MARC. If both key fields can be matched (as in this case),
then the system will always bring back one unique record—if a record is found.
If the proposal did not create the intended join conditions, you may want to define
additional join conditions. To do this, enter matching numeric values in the two-character
space next to each field. For example, if Ind.: Flag material on MARD should match the
Indicator: Flag material on MARC, enter a 02 in the two-character space next to each of these
fields. ABAP Query only allows join conditions between fields of a similar type.
Many customers like to drill down to display transaction codes for master records and
detail transactions from queries. To add the Report Call functionality to a query:
1. You must be in Create or Change mode within the query.
2. Choose Goto Report assignment.
3. Assign any of the report types mentioned above to the query.
While ABAP Query is an easy tool to work with, it is important to recognize that
experience with the tool is valuable toward producing an efficient query.
It is important to control the usage of the tool; not every user in a company should
be given permission to create, change, or access queries. Controlled access to ABAP
Query is recommended for optimal system performance and report organization. A
reporting team should be formed to create and change queries. This team should be
responsible for naming conventions, report creation, and testing. The team should
ensure that duplicate functional areas, queries, and user groups are not created and that
the standards are adhered to.
A report specification form is a valuable tool. A sample form is included in the
Fundamentals of Reporting guidebook and on the companion CD supplied with this
guidebook set. This form serves as the key channel of communication between the
reporting team and the end users that need reports.
Review
ABAP Query is an easy-to-use tool for extracting data from the R/3 System. It can be used
with most tables, both standard and user-defined. With ABAP Query you can list data, total,
and sort from almost any table or combination of tables. ABAP Query can create basic,
statistical, and ranked lists. It works with logical databases, tables joins, or individual tables.
Queries can be printed, downloaded, used with graphics, saved as extracts, or simply
viewed on the screen.
The following steps are needed to create a report with ABAP Query:
1. Create a functional area.
2. Assign required fields to functional groups.
3. Generate the functional area.
4. Create a user group.
5. Assign the functional area to the user group.
6. Create the query.
R/3 Library (Online help): In Release 4.0B, you will find more information on ABAP
Query. Go to R/3 Library BC Basis Components ABAP Workbench BC ABAP
Query | BC ABAP Reporting Tutorial.
ABAP/4 Query, a comprehensive book from the ABAP/4 Development Workbench
documentation published by SAP AG. To order printed copies use product number
50014371.
BC405: ABAP/4 Development Workbench—Reporting, a five-day training course offered
by SAP Education and Training.