Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Chapter :3
ABAP Query
Contents
Functional areas
Queries
User groups
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.
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.
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.
Menu Path
Maintain 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.
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
5
6
10
12
A2 for Account
Transactions
13.Choose Enter.
13
11
2
3
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.
6. Choose Create.
8. Choose Enter.
Note that the selected table is
8
SKA1.
13
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 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
13
12
14.Choose Create.
14
15
16
17
15
18
19
23 24
22
16
26
27
2
1
17
18
2
3
4
1
4. Choose Create.
19
8
6
20
10
9
13
11
12
21
16
14
15
22
17
19
20
21
18
Expand.
23
29
24 25 26
27
28
31
30
24
35
32
33
34
38
36 37
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.
25
41.Choose Enter.
41
43
44
43.Choose Save.
44.Congratulations! Your query is
now ready to run. Choose
Execute to run the query.
26
2. Choose Execute.
1
5
6
3
3
3
27
28
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.
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.
29
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.
30
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.
31
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
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.
Drilldown reports created using the Drilldown reporting tool (see chapter 4
and appendix F)
ABAP programs
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.
33
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.
34
35