Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

SAP Query

Ad Hoc Reporting
Date: 30 May 2022
Version: 1.0
Approval for use

delaware Name Signature Date


Setup by:
Khairiena Humaira 30th May 2022
Approved by:
Karthik Krishnasamy 30th May 2022

Data classification

Choose a classification of confidentiality


An information asset is classified as public if the information is purposely aimed to be disclosed to the
☐ Public public and has no business impact for delaware if that information is disclosed.

An information asset is classified as internal use if the disclosure of the information to unauthorized
☒ Internal Use individuals could only cause limited or no business impact to delaware.

An information asset is classified confidential if the disclosure of the information to unauthorized


☐ Confidential individuals could cause a moderate business impact to delaware.

Strictly An information asset is classified strictly confidential if the disclosure of the information to unauthorized

Confidential individuals could cause a severe business impact to delaware.

Change history

Version Date Description


0.1 20th May 2022 Initial Draft
1.0 30th May 2022 Final Version upon review

2 / 31 delaware.pro
Table of Contents

1 Introduction of SAP Query 4


1.1 What is SAP Query 4
1.2 SAP Query Tools 4
1.3 Work Areas and Transporting Query Objects 4
Work Areas 4
Transporting Query Objects 6

2 Creation and Execution of a Query 8


2.1 User Group (Prerequisite 1) 8
Steps in creating User Groups 8
2.2 Info Set (Prerequisite 2) 10
Steps in creating Info Sets 10
Assigning the InfoSet to the User Group 16
2.3 Creating the Query 18
Steps in creating Queries 19
Further Coding Needs in the Query 27
Attaching the Report to a transaction code 28
2.4 QuickView (SQVI) 30
Steps in creating QuickView 30

3 / 31 delaware.pro
1 Introduction of SAP Query

1.1 What is SAP Query

Query application allows user to create reports that are not available in SAP without any
need of committing to the customization of reporting
Query allows the user to evaluate the data from multiple tables which can be extracted in
the system by allowing the users to create broad range in defining the reporting parameters
and create different types of reports such as:
• Basic List
• Statistics
• Ranked List

1.2 SAP Query Tools

There are various subareas in the SAP Query. Queries, InfoSet Queries, InfoSets and User
Groups. The QuickViewer is also available to you. This is a tool for simple but also very
restricted dataset display.
To call the individual components, choose the following transaction codes:

Transaction Target User Purpose


SQ01 End Users Editing and executing Queries and
InfoSet Queries
SQVI End Users Editing and executing QuickViews.
SQ02 System administrators Editing InfoSets
SQ03 System administrators Editing User Groups

1.3 Work Areas and Transporting Query Objects

Work Areas
The system administrator also sets up work areas, in which a number of queries, InfoSets, and
user groups can be administered together.
1. Global area: The query objects of the global area are cross-client objects
• Available in all clients and systems.
• Connected to Transport Organizer.
• Created and transported using the normal correction and transport
procedures

4 / 31 delaware.pro
2. Standard area: In the standard query area, all query objects (queries, InfoSets, user
groups) are created and managed specifically for each client.
• Not linked to the Transport Organizer, that is they cannot be created and
transported according to normal correction and transport procedures.
• The use of the standard area has its advantages when users want to develop
queries in their clients (ad-hoc reports) that are not meant to be used in the
system as a whole.

Figure 1: Navigation to change work area

Figure 2: Options to choose Work Area

5 / 31 delaware.pro
Transporting Query Objects
Query objects, such as queries themselves, InfoSets, or user groups can be transported,
subject to certain prerequisites. In this way, you can transfer a query object created in a
test system to a productive system

Figure 3: Global Work Area Transport Path

Figure 4: Standard Work Area Transport Path

The query objects to be transported must be exported to the transport table AQTDB in the
first step. In a second step, they are transported using the standard resources of the transport
system. The third step takes place in the target system. The transported query objects are
imported from the transport table into the relevant client-specific table AQLDB.
In addition to these two cross-system transport options, the query transport tool offers two
internal system copy processes:
a) Copying query objects between two clients of a system
Query objects that have been created in a client-specific area (standard area), can be
copied to another standard area using the transport table AQTDB

6 / 31 delaware.pro
Figure 5: Copying query between two different clients

b) Copying query objects from the standard area to the global area of a system
Query objects that have been created in a client-specific area (standard area), can be
copied to the global area of a system. Likewise, objects can be copied from the global
area to one or more standard areas

Figure 6: Copying query from standard to global work area

Figure 7: Navigation to transporting the queries

7 / 31 delaware.pro
2 Creation and Execution of a Query

2.1 User Group (Prerequisite 1)

Within a team or department, the problems you solve using SAP Query reports are similar or
the same and involve the same InfoSets. For this reason, SAP Query has been designed to
allow you to combine users with similar concerns together in user groups. You can maintain
or manage your user group through the transaction of SQ03.
The characteristics of a user group include:

a) Grouping together users with similar tasks to perform


Each member of a user group can execute any queries within that group. However, only
those user group members possessing the required authorization can maintain the
queries.
Under certain circumstances, users can copy and execute queries from other user
groups.

b) Assigning InfoSets
All InfoSets covering one task area are assigned to one user group. The members of this
user group can define only those queries in the InfoSets assigned to their group.

As a rule, a user is part of one user group. But it is also possible that users with several work
areas are also members of several user groups.

Steps in creating User Groups


To create a user group, proceed as follows:
1. Go to transaction code of SQ03
2. Enter a name in the User Group field.
3. A user group name can contain up to 12 characters. This must be a user group name
which does not already exist.
4. Choose Create.

8 / 31 delaware.pro
5. A screen appears in which you enter a long text for the user group. Since the long
text of a user group is seen by all end users, it should reflect the nature of that user
group more precisely than the group's name.
6. Save your entries.

9 / 31 delaware.pro
2.2 Info Set (Prerequisite 2)

An InfoSet is a special view of a data source. The structure of an InfoSet is based on the
information requirements of the user.
A special authorization is usually required to create an InfoSet and to maintain its properties.
Therefore, contact your system administrator to identify the required InfoSet for your tasks,
or to have it created. InfoSets can be assigned to different user groups. A suitable InfoSet
may already exist for another user group, meaning that only the assignment of this InfoSet
needs to be adjusted.
As soon as a suitable InfoSet is available for your user group, you can generate an InfoSet
query for it.
Before you create an InfoSet, you must first discuss with the appropriate application
department the requirements that the InfoSet is going to have to meet.
Clarify the following points:
a) Which data source corresponds to the requirements?
b) Which fields do you need to include in the InfoSet?
c) Do you need additional information which is not available in the data source? (This
means you are going to have to connect additional tables and the definitions of
additional fields).
d) Do you need parameters and selection criteria? (Parameters and selection criteria
appear on the selection screens of queries that are created using the InfoSet).
e) Do you need to include any particular measures such as access protection?
f) Do you need to be able to change the long texts and headers for the selected fields?

Steps in creating Info Sets


1. Go to transaction code of SQ02
2. The InfoSet: Initial Screen dialog box appears.
3. Specify a name in the InfoSet field

10 / 31 delaware.pro
4. Choose Create. The InfoSet: Title and Database dialog box appears.

5. Choose a data source. To activate one of the following options, select the
corresponding radio button.

11 / 31 delaware.pro
Table join A table join includes several tables that are read by special forms
using a table of the SELECT statements.
Specify the name of the table that you want to use to start the
join definition. You can choose more tables later.
Choose Continue.

Reading The data is read directly from an SAP table. The table must be
tables included in the data dictionary.
directly
Enter the name of the table.

logical Specify the name of the logical database.


database
Use input help to get a list of all the logical databases.
Selection
Once you have specified the name of a logical database, you
Screen
Version can click on the Display Logical Database icon to display
more detailed information about the logical database.
You can assign a three-character ID to the version of a selection
screen and use it with the queries in this InfoSet. The selection
screen version must be supported by the logical database. You
can use the input help to find out the selection screen versions
that are available.
If you leave the Selection Screen Version field blank, the system
calls the standard selection screen when it executes the query.

Using You can use an ABAP report to evaluate any datasets, for which
programs to the automatic data retrieval process in the query is inadequate.
retrieve data

6. You are in the Join Definition screen. You can use the following functions for
defining the table joins.

12 / 31 delaware.pro
Inserting a Table Add table In the Add Table dialog box, specify the name of the
table that you want to add. Choose Continue.
The table is displayed in a window: The table fields are displayed
along with their corresponding long texts. Key fields are marked
with a symbol. You can move the position of the window however
you like.

Propose join The system proposes the standard default table joins. The proposals
conditions are determined from the foreign key dependencies stored in the
dictionary, or from the key fields in the tables that are used in the
join.
The join conditions between the individual tables in the join are
displayed as lines.

Create join Select the field where the join condition starts. Use the Drag Relate
condition function to join this field with its target field. If the join condition is
valid, the join is displayed as a line.

Define the type of You can choose from the following functions when you open the
join condition context menu for the join-line:

13 / 31 delaware.pro
Display Join Condition You get to the Join Condition dialog box.
This is where you define the type of join:
Internal
If according to the join conditions of a record in the first table,
there is a corresponding record in the second table, this second
record is included in the result set also.
Left-outer
All of the records in the first table are included in the result set.
If, in the second table, there is no record corresponding to a record
in the first table, a record containing fields with initial values (blank
fields) is used in the second table.
It is recommend that you do not add additional tables to tables
that have been joined using a left-outer join.

Delete table You get to the Delete Table dialog box. Specify the name of the
table that you want to delete. Choose Continue.

Alias Tables The dialog window InfoSet: Alias Names for Tables appears. You
use this function if you want to include the same table twice in a
join. Choose Create. Specify an alias for the table. You can
include the table in your join under both its original name and its
alias.

Check The system checks the validity of the join conditions between the
tables you have selected and looks for any tables that have been
added but not joined.

Reference Field When you place your cursor on a quantity field or a currency field
and choose the Reference field function, the system displays the
reference table that contains the corresponding unit of measure
or currency for this field.

Field Select a field from a table. Click on the Field


Documentation documentation function to display information on the technical
definition of a field.
Two fields sharing the same domain can always be joined.

14 / 31 delaware.pro
Two fields sharing the same data type (including length attributes)
in the data dictionary, can also be joined.

7. Once you have done defining the table joins, you can check the conditions

whether they are joined in a correct fields/domain. Use the button for
checking.
8. Click the following button to continue finishing your infoset
9. This will invoke another screen where you will have to choose the following:

Note: It is recommended to include all table fields where multiple queries can be
done on a single InfoSet. User will have the option to create a field group to select
desired fields from the table join into user defined field group.

10. Once you have selected your choice of Field Group Defaults, it will invoke another
screen as follows. In the screen capture, you can see the table that you have joined
together. You can even expand the table to view the fields in the tables.

11. Generate your InfoSet by clicking the button before proceeding to save the
creation. Usually, after generation of the InfoSet, you would get a warning message
on the joining of the fields between the tables. You can ignore the warning and
proceed with saving your InfoSet.
12. Click and exit the screen.

15 / 31 delaware.pro
Assigning the InfoSet to the User Group

Via SQ02
1. Go to the transaction of SQ02
2. Enter your InfoSet name that you have created

3. Select
4. Choose the user group you have defined for the query execution
5. Click the following to proceed with the assignment.

Via SQ03
1. Go to the transaction of SQ03
2. Enter your InfoSet name that you have created

16 / 31 delaware.pro
3. Click beside the InfoSet field.
4. A screen will be invoked for user to choose the user group that is applicable to the
InfoSet.

5. Proceed to click ‘Save’ to proceed.

17 / 31 delaware.pro
2.3 Creating the Query

The following screenshot shows the initial screen for the Queries component. If you are not
authorized to change queries, the Change and Create functions do not appear on this
screen. You can, however, display a query at any time.
When you start the component, the system takes a user group to which you are assigned
and displays the names and titles of any queries already defined for this user group in the
lower part of the screen. By selecting Other User Group, you can display the user groups to
which you are assigned and choose one for further processing

Figure 8: Query Creation Transaction Code

18 / 31 delaware.pro
Steps in creating Queries
1. Define the query name. If you have a certain naming convention, please follow it
accordingly.
2. Once you have clicked the Create button, the following screen will be invoked.

Note: In the creation of queries, only InfoSets that are tied to the specific user group would
be listed here.
3. Select the InfoSet that you would like to conduct query.
4. Enter the ‘Title’ of the query as it is mandatory
5. Select the Output Format of your query. As shown in the screenshot, the output
format is the SAP List Viewer or ALV format.
6. Click first to ensure your query has been created.

7. Then, you can either select one of the types of Reporting which are: Basic List,

Statistics and Ranked List

19 / 31 delaware.pro
In the InfoSet Query, the output list is displayed either as a full screen or in the lower area of
the screen. If you have set an output field in the InfoSet, you will first see it in an output
preview that contains example data.
You can format the output preview. This enables you to determine how data is arranged in
the output (for example, the sequence of columns, output list sorting and column colour),
and whether data is also aggregated (for example, summation of numerical columns and
rounding numerical values).
The settings and formatting are visualized in the output preview and apply to the data
output in the InfoSet Query screen, as well as to the data output in the full screen.

20 / 31 delaware.pro
8. On the top left sidebar, you would be able to see the tables that have been joined
during the InfoSet creation. The Query Painter is made up of screen divided into four
windows whose size may vary according to wish. The individual windows contain
a. Those fields at your disposal, organized on the left in tree form
b. the list's layout (upper right)
c. information about the list element currently selected (lower left)
d. links to documentation, as well as any warnings or error messages that occur
(lower right)

9. Click the arrow on the left side of the table name to expand in order to view the fields
available in the table

21 / 31 delaware.pro
10. Right next to the column of ‘Data Fields’ are the ‘List Fields’ and ‘Selection Fields’
11. List Fields are the fields that would be displayed in the reporting output therefore tick
the fields that are applicable to your reporting needs.
12. Selection Fields are the fields that would be the input parameter at your Selection
Screen before the execution of the report therefore tick the fields that are applicable
to the selection screen of your report.
Note: The arrangement or sequencing in the report and selection screen would be based
on the order of the fields you have selected.
13. If you would like to add formatting to the certain field, select the field and the bottom
left sidebar would be as below shown in the screenshot. Based on your requirement
needs, choose as required and click ‘Apply’.

22 / 31 delaware.pro
14. Once you have selected the List Fields and Selection Fields, you can view the
number of fields you have selected at the top of the column. Shown in the
screenshot below are: 14 List Fields and 2 Selection Fields.

23 / 31 delaware.pro
15. You can also activate few other functions like having a Header and Footer and
even toolboxes such as follow:

16. Click the for consistency check

17. Click the to proceed on the testing of the report queries.

24 / 31 delaware.pro
18. It will invoke a screen where you can proceed with or without defining a variant.
Click the button as shown to proceed.

19. In the selection screen, you can see the fields that you have chosen to be as the
input parameters of the report. Should you have any default value to the parameter,
you can input it and save as a ‘Variant’ of the report.

Figure 9: Example of the Selection Screen of the Query

25 / 31 delaware.pro
Figure 10: Example of the Reporting Output of the Query

20. Click the following button twice.

21. In the Layout Design screen, click once you are satisfied with the reporting
needs and click . Make sure you have saved all the edits you have made.

26 / 31 delaware.pro
Further Coding Needs in the Query
This topic discusses additional options which make additional tables, additional structures,
additional fields, parameters and selection criteria more flexible and give you more room
to move but cannot be addressed in queries for the InfoSet. These options generate ABAP
code for all queries of an InfoSet, but this is invisible to the end-user.
DATA Code: This code declares data to be used in a report (for example, variables for
calculations).
START Code: This code appears under the event START-OF-SELECTION which precedes the
first database access.
GET Code: This code appears under the event GET for a logical database table but does
not depend on a particular additional field
GETLATE Code: This code appears under the event GET LATE for a logical database table.
END Code: This code appears under the event END-OF-SELECTION either before or after
output of the list.
TOP-OF-PAGE Code: This code is copied into every generated report and appears at TOP-
OF-PAGE just before the instructions for output of the page header.

Figure 11: In Maintain InfoSet (SQ02) screen

1. Go to transaction code of SQ02


2. Select the InfoSet that require change
3. Click the
4. Follow the directory as shown in the screenshot below. Gotto > Code
5. Select the code part you need based on the explanation given above or you can
put free code. Proceed to saving once you have completed the change.

27 / 31 delaware.pro
Attaching the Report to a transaction code
1. Go to transaction code of SQ01.
2. Click More > Query > More Function > Display Report Name

3. Copy the report name “AQGHPROCUREMENT=QUERY_02======”


4. Open a new transaction screen of SE93
5. Enter your transaction code name. Follow the naming convention if you have any.
6. Click the button ‘Create’

28 / 31 delaware.pro
7. Once you have chosen to create, it will invoke another screen which prompts you to
enter the descriptive text of the transaction code and choose the following option
as shown below.

8. Click to proceed.
9. Paste the program name that you have copied in the step 3 in the program name
field.

10. Click ‘Save’ to finish the transaction.

29 / 31 delaware.pro
2.4 QuickView (SQVI)

You can use a QuickView to display information from different data sources. An InfoSet is
not necessarily required to create a QuickView; the data can be directly read from a
selected table, a table join, or a logical database instead. QuickViews are therefore the
simplest way to quickly display data from a particular source.
Once you are familiar with the navigation of the SQ01 and SQ02, SQVI or Quick View would
be intuitive for you to execute.
Steps in creating QuickView
1. Create a new QuickView, enter a name for it and choose Create.
2. A new dialog box appears, in which you should enter additional information about
this QuickView. In the second step of this dialog, you select the type of data source.

Table Enter the name of the database table.

Table join After you have confirmed the dialog step, another screen will
appear, on which you can create the table join. Use the Insert
Table button to select at least two database tables, from which
you want to create the join. Then exit this dialog by choosing
the Back button.

Logical Select a logical database


database

SAP Query You can also execute the QuickView on an existing InfoSet. To do
InfoSet this, select the required InfoSet. Note that, to use an InfoSet, you
must be assigned to an authorized user group.

3. Finally, define the display mode in which you want to structure the query. The
contents of the displayed data will not change. Therefore, select the mode that is
better suited to your purposes. Confirm the create dialog.
4. On the subsequent screen, select:
a. Which fields of the data source are to be used for the selection of the values
(selection fields)?
b. Which fields of the selection result are to be displayed in the list (list fields)?

30 / 31 delaware.pro
END OF DOCUMENT

31 / 31 delaware.pro

You might also like