Professional Documents
Culture Documents
Ab 4 Query
Ab 4 Query
ABAP/4 QUERY
- Simple reports
- Reports with statistical functions such Averages,
Percentages
- for analytical reports
Within a query, you can define one basic list, up to 9 statistics and up to 9
ranked lists. These different list types may be combined in any permutation you
like. You can also extend existing queries by adding more sub-lists. Unless you
have specified otherwise, you see the basic list first, followed by the statistics
and finally the ranked lists when you execute a query.
One has to be clear as to what kind of report he / she wants and select the
fields in the functional area accordingly and also the kind of report. One can
also generate graphical reports in ABAP/4 Query.
There are different paths to create the functional area, user group and queries.
You can create any of these by choosing Tools ABAP/4 Workbench
Utilities ABAP/4 Query or executing the transaction codes for each of them:
SQ01 for Query
SQ02 for Functional Area
SQ03 for User Group
Part I deals with the steps involved in the creation of Functional Area.
Functional Area can be created with or without a Logical Database.
First we will go through the procedure of creating the Function Area with a
Logical Database.
CREATING AN FUNCTIONAL AREA ( with a Logical Database)
The first step in creation of a ABAP/4 Query is to create an Functional Area.
To create an Functional Area goto
Tools ABAP/4 Workbench Utilities ABAP/4 Query Functional Areas
Give a Functional Area name and Click on Create button.
To add additional fields from the menu bar choose GOTO Additional
Field
In the next screen that you get, give the field name and the table name from
the logical database in which this field has to include.
Click on the enter icon.
In the next screen specify the Sequence, Description, Heading, technical
attributes for the fields like field type, length etc. and then you can also
specify any formula for the field.
Save the field details.
You can to the same for any more fields, which you would like to include in
the query.
If you create two additional fields, and the second field uses the first field in
its code then the sequence of the second field should be higher than the
sequence of the first.
You can also include tables. Choose GOTO Additional Tables
You can also include your own selection criteria and parameters for
executing the query other than default selection screen and parameters
If you include your own selection criteria and parameters then you have to
write a code for them to take any effect.
If you define Parameters as part of your selection screen you must also
evaluate them in functional area code otherwise they will have no effect.
Note : Please the online documentation for more information on this.
You can also write Code for the query that is to be executed at the time of
executing the query. Choose GOTO Code
What code you want to write is up to you and the output of query you
design.
The point at which an ABAP/4 Query reads an additional table or performs
calculations on additional fields depends on logical database table since the
associated ABAP/4 code becomes part of the GET event processing of the
table.
If you want display something before or after the output of the query, you
write the code for that in END-OF-SELECTION.
If you want to display something at beginning of the page then you write the
code for that in TOP-OF-PAGE.
Save and generate the functional Area.
Click on Back icon to come out.
You can also define local fields for the functional area. The definition of local
fields allows you to generate new information from the fields in a functional
area, without having to include an additional field.
To define a local field, choose Edit Local field Create on the Select
Field screen.
When making this definition, the following information is needed:
Short name
Field name
Here, you enter a text which describes the field contents. On all
subsequent screens, the local field is identified via this name.
Header
This is used when calculating column headers. Please note that headers
should correspond to the field output length and that they may extend
over two lines.
Functional group
The local field is included in the functional group.
Attributes
When defining the technical attributes of the local field, you can use any
of the following options:
Refer to an existing field (i.e. use it as a reference field)
The advantage of this option is that the local field can accept the
same values as the reference field. If the reference field is a
currency amount field or a quantity field, the local field inherits
the currency or unit assignment of the reference field. In our
example, the field Distance with the short name DISTANCE is a
- Calculation formula
You can determine the value of a field in either of the following
ways:
1. By using a calculation formula.
In the most simple case, a calculation formula consists
of a single formula. All formulae conform to the usual
mathematical rules and contain operands and operators.
Valid operands include the short names of fields as well as
numeric constants (e.g. 10 or 1.5) and character strings (e.g.
ABC).
Certain special fields are also available. These are:
%NAME(the name of the user processing the query)
%DATE(the current date when the query is being processed)
%TIME(the current time when the query is being processed).
If an operand is a text field, you can use the notation textfield
n:m to access part of this field. Here, n is the position of the
first character and m is the position of the last character.
If you are accessing the 2nd character to the 5th character of
the field, the notation would be text 2:5.
If an operand is a date or time field, you can use the following
notation to access the individual components of this field:
date field [YEAR] year
date field [ MONTH] month
date field [DAY] day
time field [ HOUR] hours
time field [ MINUTE] minutes
time field [ SECOND] seconds
Created / Compiled By : P. M. V. Subba Rao
10
11
CREATING A QUERY
To create a Query choose Environment Queries
Give a Query name and Click on Create Button.
Select the functional area for the user group by double clicking on it or by
clicking on the enter icon.
Please note that a user group can be assigned to any number of functional
areas, which could include functional with logical database and without
logical database.
In the next screen give a description to the query, specify the output length (
if required) and select the processing option from the further Processing
Options box. You can display the data as a table, download it to a file,
display in a word processor etc.
Click on the Next Screen icon ( ) on the toolbar.
SELECT FUNCTIONAL GROUP screen.
The list of Functional Groups that were defined in the functional area is
displayed. Select the ones required. The fields from this groups will only be
displayed in the next screen.
Click on the check boxes to select the functional groups.
Click on the Next Screen icon ( ) on the toolbar.
SELECT FIELD Screen.
The fields from each functional groups is displayed. Select the fields that
you want to include in your query report.
Here in this screen, you can do the following if required :
You can also change the selection text contents to the way you want it to
appear in the selection screen.
12
You can also create local fields that you would like to include in this
query only. You have to give a short name for the local fields that you
create.
Choose Edit local field Create
You can include fields such as user name, system date, time etc.
You can also maintain column headers for the fields. Select the field and
then choose Edit Column Header Maintain
Specify the lines on which the fields have to appear on the report
layout
Specify the order in which each field has to appear
Specify the sort order ( if needed )
For the numeric fields in the list, check the check box against the
fields if you want to have the totals of the field in the output.
For better looking output you can also check the Basic list with box
and Columns separated by | check boxes on the top of the screen
13
Click on New Page to get the output for the fields against which New
Page check box is checked on a new New Page
14
NOTE :
YOU CAN DO THE ABOVE PROCESS FOR CREATING QUERIES WITH
RANKED LISTS AND STATISTICS LIST. THE PROCESS IS THE SAME
EXCEPT THAT WHEN DEFINING THE QUERY YOU CHOOSE EITHER
RANKED LIST OR STATISTICS LIST IN PLACE OF BASIC LIST.
RANKED LISTS
Ranked lists are special types of statistics. Here, numeric values are also
summed for key terms and displayed in a table. However, sorting is always by a
numeric value known as the ranked list criterion. Additionally, only a certain
number of items are output. This makes ranked lists suitable for analyzing
questions such as: "What are the 10 flight connections with the highest sales?"
First, you must assign a title to the ranked list. This is necessary, since one
query can contain several ranked lists. You can then specify how many entries
(i.e. output lines) you want the ranked list to have. The proposed value here is
always 10.
Subsequently, you must define which fields are to be output and in what order.
To do this, enter sequence numbers in the first column. You select one of these
fields as the ranked list criterion. In our example, it is the field Free seats.
The ranked list criterion is the sort criterion of the ranked list. The default sort
sequence for the sort criterion is descending order, but ascending order is
sometimes necessary. This would apply, for example, to vendor sales figures
which are stored as negative amounts. In such cases, you can specify ascending
order for the ranked list criterion by selecting the column Asc.
You can also specify an output length and a rounding factor. As with statistics,
currency fields and quantity fields require you to specify a reference currency or
a reference unit which is used to convert all the amounts. Conversion errors
also have the same procedure as statistics
As with statistic, you can access the screens for maintaining the header and
setting graphics parameters by following the normal sequence of query screens.
The same rules apply for both these screens.
If you want to define another ranked list, you choose the Next ranked list
function.
15
SELECT-OPTIONS:...
DATA: ...
DATA: BEGIN OF itab OCCURS xxx. If necessary, define an INCLUDE STRUCTURE
tab. internal table itab with the
DATA: END OF itab. structure tab to hold the records to be evaluated.
* <Query_head> This comment must always appear after your data declarations.
* Code to define the table itab, if such a table is used.
16
Beginning of a loop to retrieve each record and place it in the field string tab
SELECT, DO, LOOP, ...
* If necessary, code to format data
* <Query_body> This comment must always be the last 'statement in the loop.
*The data must now be in the field string tab.
The two entries i.e the two comment lines *<QUERY_HEAD> and
*<QUERY_BODY> in the above example, are fixed should be there in your
ABAP report if you want to build a ABAP Query using and ABAP/4
program. They start immediately after the character "<", but the system
does not distinguish between upper and lower case.
17
Depending on what the user values set in ACTVT field the user can
manipulate / create the queries.
The default values of authorizations for the authorization object S_QUERY
are:
S_QUERY_ALL : Change, Maintain and Translate
S_QUERY_UPD : Change and Translate
When you have chosen a user group, you see the names and titles of any
queries already defined there in the lower part of the screen.
You can display a list of queries for your current user group. To do this,
proceed as follows:
Choose Environment Directories Queries/user group, or
Place the cursor on the input field for the query name and display a list
of possible entries by pressing F4 function key or by clicking the arrow
on the field.
If differences occur between queries and functional areas, you should
terminate the processing and perform a comparison between the query and
the functional area.
To perform a comparison, select Query Other functions Compare.
You then see a list of all the fields defined differently, together with information
about how the field definition has changed and where in the query the field is
used. If you wish, you can carry out an automatic comparison for individual
fields.
If you want to execute the query as a background job, choose Exec. in
background.
To do this you would require variant.
18
19