Vous êtes sur la page 1sur 35

Chapter :2

Chapter :3

ABAP Query

Contents

In this chapter you will learn


how to:

Create a functional report


in ABAP Query

Build a basic functional


area using a logical
database

Running the Query.............................................................................................. 226

Maintain a user group

Understanding the Report List...........................................................................227

Create a report using a


functional area and a user
group

Learning the Basics of ABAP Query....................................................................22


Creating a Report with ABAP Query....................................................................27

Getting the Most from ABAP Query: Tips & Tricks...........................................227


Review.................................................................................................................. 233
Where to Learn More........................................................................................... 233

Report Development Tools

Chapter 2: ABAP Query


Creating a Report with ABAP Query

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

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

ABAP Query
Functional
Functional
Areas
Areas

Statistical
Statistical
List
List

Queries
Queries

Basic
Basic
List
List

User
User
Groups
Groups

Ranked
Ranked
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 tableswhich 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 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 fourcharacter names. SAP now delivers functional areas in various applications.

Report Development Tools

Chapter 2: ABAP Query


Creating a Report with ABAP Query

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

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

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

Report Development Tools

Chapter 2: ABAP Query


Creating a Report with ABAP Query

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.

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

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

Report Development Tools

Chapter 2: ABAP Query


Creating a Report with ABAP Query

The main steps in creating a query are shown in the graphic below.

Create
Create aa
functional
functional area
area

Assign
Assign required
required fields
fields to
to
functional
groups
functional groups

Generate
Generate the
the
functional
functional area
area

Create
Create aa
4Trained Employee
Available?
user
user group
group

Assign
Assign the
the functional
functional area
area
to
to the
the user
user group
group

Create
Create the
the query
query

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.

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

3. In Functional area, enter a


name for the functional area
(for example, ZZ_GL_DETAIL)
you want to create.
4. Choose Create.
3

Report Development Tools

Chapter 2: ABAP Query


Creating a Report with ABAP Query

5. In the Name field enter a


description for the functional
area.

5
6

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 9


name of the logical database
you want to use for the
functional area (for example,
SDF).
10
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.

10

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

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

12.Create the following two


functional groups, A1 and A2
in the Create Functional
Groups window:

12

A1 for Account Master Info

A2 for Account
Transactions
13.Choose Enter.

13

Report Development Tools

11

Chapter 2: ABAP Query


Creating a Report with ABAP Query

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.

2
3

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, doubleclick 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.

12

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

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
8
SKA1.

Report Development Tools

13

Chapter 2: ABAP Query


Creating a Report with ABAP Query

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.

10

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.

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

14

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

12.Select the line BSEG.


13.Choose the Extras button to
add an additional field.

13

12

14.Choose Create.

14

15.In the Name field, enter


Correct_Amount, the name of
the additional field to be
added to the functional area.

15
16

16.Select Additional field.


17.Choose Enter.

Report Development Tools

17

15

Chapter 2: ABAP Query


Creating a Report with ABAP Query

18.In Description, enter an


appropriate field description.
19.In Header, enter the column
header text.
20.Enter the format of the field
by either manually entering
20
the type, length, output
length, and decimals.
21
Alternatively, you may specify
the name of the field (for
example, BSEG-DMBTR) whose
formatting this additional field
should mirror.

18
19

21.To enter the ABAP code for the


additional field, choose Editor.
22.Enter the ABAP code that will
determine the value of the
additional field. In this
25
example, we are checking the
debit/credit indicator (BSEGSHKZG). If we find an 'S' for
debit, then the correct amount
is equal to the local currency
amount (BSEG-DMBTR). If it is
not a debit, then it is a credit
and the local currency amount
must be multiplied by -1.

23 24

22

Remember to enter the periods


at the end of each line!
23.Choose Save.
24.Choose Back.
25.Choose Enter twice to return
to the logical database view of
the functional area.

16

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

26.Double-click on the functional


group A2 to select it.
27.To add the additional field
(CORRECT_AMOUNT) to a
functional group so that it can
be used in queries, expand
the BSEG table to show all the
fields. Scroll down to the
bottom and select the
CORRECT_AMOUNT field.

26

27

Step 3: Generate the Functional Area


1. Choose Generate
to
generate the functional area.
This is the final step in
creating the functional area.

2
1

2. Choose Back after the


functional area has been
generated.

Report Development Tools

17

Chapter 2: ABAP Query


Creating a Report with ABAP Query

Step 4: Create User Group


Step 5 below describes how to create a user group.

Step 5: Assign the Functional Area to the User Group


The functional area must be
assigned to a user group before it
can be used in a query. From the
previous screen (in step 3),
choose Environment User
Groups.

1. In User group, enter X1, the


name of the user group.

2. If a user group does not exist,


choose Create.
The rest of this example
shows how to create a user
group. If an existing user
group will be used, choose
Assign users and functional
areas.

3. In the Users section, enter the


user names of the users who
should have access to the
functional areas and queries
of this user group. In this
example, we added the user
Tbecker to the user group.

4. Choose Assign funct. areas to


assign the appropriate
functional areas to the user
group.

18

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

5. To assign the functional areas


to the user group, select the
appropriate checkboxes on
the left side of the screen. In
this example, we selected
functional areas ZZGL and
ZZ_GL_DETAIL.

6. Choose Save to save the


assignments.
7. Choose Back twice to return to
the main user group screen.
Now that the functional area and
user groups have been set up,
you are ready to build the query.
5

Step 6: Create the Query


To go to query maintenance from
the User Group screen, choose
Environment Queries
1. Make sure you are working in
the appropriate user group.
2. If not, choose the Other User
Group button and switch to
the correct user group.
3. In the Query field, enter a
name for the new query. In
this example, enter A1.

2
3
4
1

4. Choose Create.

Report Development Tools

19

Chapter 2: ABAP Query


Creating a Report with ABAP Query

5. You are now prompted to


select a functional area. The
list of functional areas
includes all areas assigned to
the user group you are
working with. Double-click on
the functional area you wish
to use. In this example,
double-click on ZZ_GL_DETAIL.

6. In Title, enter the title of the


query, and in Notes enter any
relevant notes. The notes are
for reference only and do not
appear in the query.
7. In Columns, enter the column
size (in characters). In Lines
enter the desired number of
lines. In this example, the
number of lines and columns
is 65 and 132 respectively.
This should match a print
format if the query is to be
printed.

8
6

8. Choose Next Screen to


continue.

20

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

9. Select the functional groups


from which you want to
choose fields. Remember that
you are working with
functional groups, not
functional areas, in this step.
10.Choose Next screen to
continue.

10
9

11.From each functional group,


select the fields to be used in
the query.
12.Use Page up or Page Down to
scroll through the fields. In
this example, the fields you
select would be based on the
desired report output (as
shown in the sample report on
page 7).
13.Choose Next Screen to
continue.

13

11

12

Report Development Tools

21

Chapter 2: ABAP Query


Creating a Report with ABAP Query

14.From this list, select the fields


that should be used as
variables when executing the
query. Some of these fields
may already be variables in
the logical database. If so,
they will appear twice when
executing the query. You may
return to this screen and
deselect them if they are
duplicated.
15.If selection fields straddle
multiple pages, use Page up
or Page Down to scroll
through the fields.

16
14

15

16.Choose Basic List to continue.

22

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

17.Enter the Line and Sequence


for each field in the query. In
the output for this sample
report, recall that the account
number and description
23
appear above the transaction
22
detail. This is because we
specified that they would be
on line 1. The transaction
detail is on line 2. The
sequence is the order in which
the fields appear across the
page.

17

19

20

21

18

18.Use Page up or Page Down to


scroll through the remaining
fields.
To view a full page of fields,
choose

Expand.

19.Select and order the sort


fields in the Sort column.
20.The Total button is available
on all numeric, currency, and
quantity fields. This gives you
the option to total the sort
fields.
21.The counter field is new in
Release 4.0 and allows you to
count the number of entries in
your query for the selected
field. This will also total on the
sort fields.
22.The Compressed display
checkbox allows detail
transactions to be suppressed
on the initial screen (and then
expanded if necessary). With
compression on, you will see
the account number and a
total for the account. When
expanded you will see all the
related transaction detail.
23.Choose Next Screen to
continue.

Report Development Tools

23

Chapter 2: ABAP Query


Creating a Report with ABAP Query

This screen helps you set up the


sort fields.
24.To get text above each sort
break, select Text.

29

25.To get totals for a sort level,


select Total. This option works
only if you have also selected
Total for a numeric field on the
previous screen.

24 25 26

27

28

26.To get counter totals for the


sort field, select Cnt.
(counter).
27.To get a blank line between
account numbers, select
BlnkLn.
28.To get a page break at each
new company code, select
NewPg.
29.Choose Next Screen to
continue.
30.Each sort field for which you
selected Text, Total, or Cnt.
above has a separate screen
(as shown here). You can
specify the text that should
appear next to each total and
above each sort break.

31

31.Choose Next Screen to


continue. Choose this button
through each of the controllevel text screens.

30

24

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

32.Each detail line of your query


will have a line on the List line
output screen. To get a
column header for the list line,
select Header line.

35
32

33.Selecting Ref. checks the


referenced line (for example,
line 02) which is the detail
transaction line for an activity.
If there is no activity for line
02, then line 01 is suppressed
as well.

33

34

34.If the detail lines for an


account break across pages,
selecting Page Header repeats
the first line (with the account
number and description) at
the top of the next page.
35.Choose Next Screen to
continue.
36.The query gives the standard
length of the field. You now
have the option of shortening
it.
37.If the Pos fields are left blank,
the default is one space
between each field. Entries in
the Pos column determine
where in the line you want the
field to start. In our example,
we want the account number
to start in character position
02 and the text in character
position 12. This means there
will be 4 blank spaces
between the account number
and text (12 - 2 6 = 4).

38
36 37

38.Choose Next Screen to


continue.

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.

Report Development Tools

25

Chapter 2: ABAP Query


Creating a Report with ABAP Query

39.This is the column header


screen. To change a field
header, double-click on the
field header in the Page
header section. In this
example, we double-click on
the Amount field.
39

40.Change the description in the


popup box.
40

41.Choose Enter.
41

42.To enter a date, time, page, or


name, put your cursor in the
white line in the Page header
section and type &%DATE, &
%TIME, &%page, or the
appropriate variable name. To
insert additional lines, double42
click on the white line.

43
44

43.Choose Save.
44.Congratulations! Your query is
now ready to run. Choose
Execute to run the query.

26

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

Running the Query


To run a query, choose System
Services ABAP Query.
1. Select the query from the list.
In this example, user group
X1 has only one query (A1).
2

2. Choose Execute.
1

3. Enter the variables.


In this example, enter:
470000 in G/L Account
3000 in Company code
19.10.1998 in Open items at
key date

5
6
3

4. Notice that the G/L account


number and Company code
fields appear twice because
both the logical database and
the query use these fields as
selection criteria. Be sure to
remove this duplication from
the query.
5. Dynamic selections are also
available because of the
logical database. These
selections should also be used
instead of query selections.

3
3

6. Choose Execute to run the


query.

Report Development Tools

27

Chapter 2: ABAP Query


Creating a Report with ABAP Query

Understanding the Report List


The basic list shown here is a
simple listing of detailed
transactions for specific G/L
accounts. In this example, 15
transactions have been posted to
the G/L account based on the
selection criteria specified at the
time of executing the query.
From the report output, you may:
Expand or collapse the detail
with the Basic List button.
Drill down (sometimes
referred to as Report Call) to
call up a variety of reports or
transactions from this query.
Drilldown capability is specific
to the query.
Save the query to a file to be
called up and viewed later.
Note that expand/collapse and
the report call capability is not
available in a saved list.

Getting the Most from ABAP Query: Tips & Tricks


Adding Selection Criteria in a Functional Area
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 SelectOptions and Parameters.
With these selection options you can make the variables:
Work with their matchcodes
Mandatory fields
Display only
Highlighted
Set defaults

28

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

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.

5. Choose Create to add a new field.


6. In the Create Selection window, enter the name of the new selection criteria.
Use a name that starts with an alpha character.

6
7

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.

Report Development Tools

29

Chapter 2: ABAP Query


Creating a Report with ABAP Query

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

Using Table Joins in a Functional Area


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

30

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

3. In the Name field, enter a description for the functional area.


4. In the Table field, enter the name of the table (for example, MARD) with which
you want to begin the table join. For best results, a high percentage of fields
from the table you choose (for example, MARD) must also be present in the
other table (for example, MARC).
5. Select Table join.
6. Choose Enter.
3

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.

Report Development Tools

31

Chapter 2: ABAP Query


Creating a Report with ABAP Query

9. The tables appear in the Join conditions (right side of the screen).
10.Choose Specify conditions to define the join.

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
recordif a record is found.

32

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

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.
13.Choose Back to go back one screen.
14.Choose Functional group on the next screen to begin adding fields to the
functional groups from the adjoined tables.

Assigning Reports with Report Call Functionality in a Query


Each query has Report Call functionality for drilling down to other reports. These
reports can be any of the following:

Report groups created using Report Painter/Report Writer (see chapter 3)

Drilldown reports created using the Drilldown reporting tool (see chapter 4
and appendix F)

ABAP programs

Other ABAP queries

Transaction codes (for example, standard reports available in LIS. For more
information, see chapters 5 and 6)
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.

More Helpful Hints for Report Developers


Creating functional areas using table joins, instead of logical databases, is
more efficient for processing if you are using only a few tables. However,
logical databases are essential for creating hierarchical lists. You may want to
consider the pros and cons of using functional areas and logical databases if
performance issues are an important concern. Due to perceived performance
problems, many customers make limited use of ABAP Query.
Non-technical users may find it difficult to work with table joins, additional
tables, and additional fields. People may get discouraged and back away from
the tool. Have the more technical team members create the functional areas
and user groups. Delegation of tasks allows less technical team members to
concentrate on creating queries.

Report Development Tools

33

Chapter 2: ABAP Query


Creating a Report with ABAP 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.

Where to Learn More


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 WorkbenchReporting, a five-day training
course offered by SAP Education and Training.

34

Reporting Made Easy

Chapter 2: ABAP Query


Creating a Report with ABAP Query

Report Development Tools

35

Vous aimerez peut-être aussi