Report Development Tools 2–1
Chapter 2: ABAP Query
Contents
Learning the Basics of ABAP Query ....................................................................2–2
Creating a Report with ABAP Query.....................................................................2–7
Running the Query ...............................................................................................2–26
Understanding the Report List............................................................................2–27
Getting the Most from ABAP Query: Tips & Tricks...........................................2–27
Review ...................................................................................................................2–33
Where to Learn More............................................................................................2–33
2
In this chapter you will learn
how to:
Create a functional report
in ABAP Query
Build a basic functional
area using a logical
database
Maintain a user group
Create a report using a
functional area and a user
group
Chapter 2: ABAP Query
Learning the Basics of ABAP Query
Reporting Made Easy
2–2
Learning the Basics of ABAP Query
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.
What Is ABAP Query?
ABAP Query is an easy-to-use reporting tool that lets you query data from one or more
database tables and funnel it into a list. With this tool, you can extract data from virtually
any application or database table in the R/3 System. ABAP Query enables you to create lists
by moving through menus.
The output of ABAP Query can be:
< Displayed on the screen in a table format
< Displayed on the screen using SAP graphics
< Downloaded to a spreadsheet (for example, Microsoft Excel)
< Downloaded to a flat file
< Saved as an extract that can be viewed later.
Who Uses ABAP Query?
ABAP Query is used by two different groups of people. Each group works with different
ABAP Query components.
< Departmental users: These are end users who create new queries and generate lists.
Non-technical users find ABAP Query particularly useful because it does not require
any programming knowledge.
< System administrators: System administrators set up the necessary environment for end
users and carry out transports.
ABAP Query can be used to access just about any data in the database, making it very
desirable for users in many areas of a business. Several R/3 application areas provide a
predefined logical database for easier information retrieval.
How Is ABAP Query Organized?
As shown in the graphic, ABAP Query has three main components:
< Functional areas
< Queries
< User groups
Chapter 2: ABAP Query
Learning the Basics of ABAP Query
Report Development Tools
2–3
Basic
List
Basic
List
Ranked
List
Ranked
List
Statistical
List
Statistical
List
Functional
Areas
Functional
Areas
ABAP Query
User
Groups
User
Groups
Queries
Queries
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.
Why create functional areas
ABAP Query allows you to evaluate data in the R/3 System. However, since the system
contains several hundred thousand fields in logical databases, in tables, and sequential
datasets, it is simply not practical to offer all these fields to a user for selection when
creating queries. Therefore, before starting to create queries (using the component
Maintain Queries), you create functional areas (using the component Maintain
Functional Areas). Functional areas provide the user with a framework for defining a
query quickly and easily.
Functional groups
When you create a functional area, you select a logical database from an application
system. However, since one logical database can contain a vast number of fields, you
combine fields together in logical units known as functional groups (see page 2–5). A
functional area not only allows you to restrict the number of fields and group them
together in meaningful units, but it also allows you to define auxiliary fields and process
them like database fields.
You can also read the long texts in additional tables (for example, the long text of an
airline carrier in the table SCARR) and perform any necessary preliminary work. This
means that you can evaluate sequential datasets just as easily as SAP databases. Starting
with Release 4.0, a functional area can have a name of up to 24-characters. Previous
releases were limited to four-character names. SAP now delivers functional areas in
various applications.
Chapter 2: ABAP Query
Learning the Basics of ABAP Query
Reporting Made Easy
2–4
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.
What is a user group?
A user group is a collection of users that work with comparable data and accomplish
similar tasks. Changes to functional areas and queries are immediately visible to all users.
The users assigned to a user group can only access the functional areas assigned to their
user group. When creating a query, the user group controls which functional areas can be
used. (However, user groups are irrelevant if a user has full authorization to all R/3 data.)
Starting with Release 4.0, user groups can have 12-character names. Prior releases were
limited to two-character names.
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.
Queries have three different types of reports or lists:
< Basic list: Sorts and totals selected fields as specified by the user in the query. This is the
most common kind of report.
< Statistical list: Totals, calculates averages, and allocates percentages based on the fields
in the query.
< Ranked list: Ranks fields based on numeric fields, including currency or quantity.
A single query may have multiple statistical and ranked lists but only one basic list.
Chapter 2: ABAP Query
Learning the Basics of ABAP Query
Report Development Tools
2–5
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.
How to Access ABAP Query Components?
From the SAP main menu, choose System → Services → ABAP Query to access ABAP Query.
To access the components of ABAP Query, use the menu paths shown in the following
table:
ABAP Query Component Menu Path
Maintain Queries
Tools → ABAP Workbench → Utilities → ABAP Query →
Queries
Maintain Functional Areas
Tools → ABAP Workbench → Utilities → ABAP Query →
Functional Areas
Maintain User Groups
Tools → ABAP Workbench → Utilities → ABAP Query →
User Groups
Chapter 2: ABAP Query
Learning the Basics of ABAP Query
Reporting Made Easy
2–6
How Does ABAP Query Differ from Other Reporting Tools?
There are several differences between ABAP Query and other reporting tools:
< ABAP Query can access data from any table within SAP. Most other reporting tools can
access only certain tables.
< ABAP Query is ideal for listing data from any application in the system. It can calculate
additional fields such as purchase price variance (PPV) in procurement or “aging
buckets” in accounts receivable (A/R), and total and sort on any field. These fields are
calculated on each line of a detail report and then totaled by the specified fields (for
example, material or customer).
< ABAP Query reports are typically simple listing and totaling reports, unlike a balance
sheet or an income statement that requires complex groupings (for example, a cash or
revenue line made up of several accounts on a financial statement). Such complex
groupings would require the query to read tables multiple times to appropriately total
and sort the accounts. Other tools (such as Report Painter/ Report Writer which uses
sets for these groupings) are better suited for reports with complex groupings.
What Are the Prerequisites?
< An understanding of the data dictionary and perhaps some basic programming: While
an ABAP programming background is not critical to use this tool, knowledge of the data
dictionary and some basic programming is helpful. If you are not familiar with the data
dictionary or do not possess basic programming skills, you may want to enlist the help
of a basis/tools expert at some point. These skills will come in handy when the
functional area you are building needs additional tables, additional fields, or table joins.
< Know required database tables and fields: Before starting a query, you should know
the required tables and fields. To execute a query, data must be present in the tables you
are accessing. A general understanding of the fields and how they are stored in the
database is also helpful. For example, the posted dollar amount in an FI document is
stored as an absolute number. The system uses the posting key to determine if the actual
value is positive or negative. To show the correct amount in your query you will need to
create an additional field in the functional area that checks the posting key to determine
the correct amount. The correct amount is then stored in the additional field for your
queries.
< System settings: An administrator must first make the required settings to allow a user
to work with ABAP Query.
< Authorizations: End users and system administrators must have the appropriate
authorizations to use ABAP Query.
Chapter 2: ABAP Query
Creating a Report with ABAP Query
Report Development Tools
2–7
Creating a Report with ABAP Query
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.
Chapter 2: ABAP Query
Creating a Report with ABAP Query
Reporting Made Easy
2–8
The main steps in creating a query are shown in the graphic below.
Create the query
Create the query
Trained Employee Available?
Assign the functional area
to the user group
Assign the functional area
to the user group
Create a
user group
Create a
user group
Generate the
functional area
Generate the
functional area
Assign required fields to
functional groups
Assign required fields to
functional groups
Create a
functional area
Create a
functional area
1
2
3
4
5
6
Guided Tour
Step 1: Create a Functional Area
1. To access the initial screen of ABAP Query, choose System
→
Services
→
ABAP Query.
2. Choose Environment
→
Functional
Areas.
2
Chapter 2: ABAP Query
Creating a Report with ABAP Query
Report Development Tools
2–9
3. In Functional area, enter a name for
the functional area (for example,
ZZ_GL_DETAIL) you want to
create.
4. Choose Create.
5. In the Name field enter a
description for the functional area.
6. Leave Fixed point arithmetic
selected to ensure that the decimal
places are correctly set for the
calculations.
7. In Logical data base, enter the name
of the logical database you want to
use for the functional area (for
example, SDF).
8. To display the tables and fields
available in the logical database,
choose Display.
9. Select Table join.
Note: If you prefer to directly read
a specific table or use a table join
for multiple tables, then enter the
name of the main table in the Table
field and select either Direct read or
Table join. Only one of two areas
(steps 6 and 7 for logical databases
or step 8 for specific tables) should
be selected.
10. Choose Enter.
4
3
5
6
7
8
10
9
Chapter 2: ABAP Query
Creating a Report with ABAP Query
Reporting Made Easy
2–10
11. Choose the Create button (next to
the Functional groups folder) to add
two functional groups to the
newly created functional area
ZZ_GL_DETAIL.
12. Create the following two
functional groups, A1 and A2 in
the Create Functional Groups
window:
< A1 for Account Master Info
< A2 for Account Transactions
13. Choose Enter.
11
12
13
Chapter 2: ABAP Query
Creating a Report with ABAP Query
Report Development Tools
2–11
Step 2: Assign Required Fields to Functional Groups
1. Choose Expand to assign
fields to the functional groups for
queries. Once the nested detail is
in view, the button turns from
green to red.
2. Click line A1, Account Master Info,
to highlight the group for field
assignment.
3. To assign the fields to the
functional group A1, click the
minus (-) sign, next to the field
names. The icon changes to a
green plus (+) sign. The functional
group A1 appears next to the
green icon, indicating that the
fields have been assigned to the
highlighted functional group.
Continue adding fields to the
functional group by repeating
steps 1 and 3 (above) for each table
that contains fields needed for
your queries.
To select a different functional
group to add fields to, double-
click on the new functional group
and perform steps 1 and 3 (above).
Selecting fields for functional groups
When selecting fields for your functional groups, select the field in the highest possible table.
For example, company code (BUKRS) is available in tables SKB1, SKC1A, SKC1C, BKPF, BSIS,
BSEG, and GSEG. The company code should be selected only from table SKB1 because it is
the highest table in the logical database hierarchy that contains the company code. If the
company code is selected from more than one table, it will appear multiple times to the users
when creating queries. Multiple appearances can be extremely confusing.
The next two steps involve ABAP programming statements. You may want to ask a
Basis/Tools expert to help you if you are not familiar with SELECT statements and basic
ABAP code.
1
3
2
Chapter 2: ABAP Query
Creating a Report with ABAP Query
Reporting Made Easy
2–12
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
screen.
5. Choose Extras in the toolbar to add
an additional table.
6. Choose Create.
7. In Name, enter SKAT, the table to
be added to the functional area.
Leave Additional table selected.
8. Choose Enter.
Note that the selected table is
SKA1.
7
8
5
4
6
Chapter 2: ABAP Query
Creating a Report with ABAP Query
Report Development Tools
2–13
9. The system defaults to the SELECT
statement values it can determine.
You must complete the missing
entries, if any.
10. Choose Enter twice to return to the
Change Functional Area
ZZ_GL_DETAIL screen.
11. Be sure to add the fields from the
additional table to a functional
group. The additional tables fields
will be listed under the table to
which it was attached. In this
example, table SKAT is attached to
table SKA1.
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.
9
10
11