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
< 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
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
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
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
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
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
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
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