1. What is SAP query and why do we need queries?
Many times a need arises for SAP Users and Functional Consultants to generate quick reports
without getting any ABAP coding done – time taken to complete the coding in development,
transport and test it in QA system and then transport to production – is sometimes too long. In
such cases, SAP query is a tool provided by SAP for generating these kinds of reports.
Purpose
The SAP Query application is used to create reports not already contained in the default.
It has been designed for users with little or no knowledge of the SAP programming
language ABAP.
SAP Query offers users a broad range of ways to define reports and create different
types of reports such as basic lists, statistics, and ranked lists.
These outputs can include lists on screens in table format, ALV grids, downloadable
spreadsheets, and downloadable flat files. The internal report generator creates an
ABAP program corresponding to the definition of the list.
The SAP Query comprises five components:
Queries - SQ01
InfoSet Query -
InfoSets - SQ02
User Groups - SQ03
Translation/Query - SQ07
Query Areas
A query area contains a set of query objects (queries, Infoset, and user groups) that are discrete
and consistent.
There are the following query areas:
Standard area
Global area
Standard Area
1. Client specific
2. Query objects are not attached to the Workbench Organizer
Advantage:-End users can develop queries (ad-hoc reports) in their own client that are
not meant for use in the rest of the system.
Global Area
2. 1. Cross client
2. Query objects are attached to workbench organizer
Advantage:-The global query area is well suited for centrally developing queries meant
for use and distribution throughout the system.
Steps to create a Query
Transaction – SQ02 (Infoset creation)
STEP 1:
Open Transaction SQ02. Create Infoset
STEP-2
Assign Data sources
1. Name
2. Authorization group: This means that only users authorized to execute programs
from this authorization group are able to execute these queries.
Use Tcode: AUTH_DISPLAY_OBJECTS to see Authorization Groups
3. Choose Data Source:
Table join using a table: Is used when Query is prepared for retrieving data
from more than one database tables having relationships.
Reading tables directly: Is used when Query is prepared for retrieving data
from one table.
Logical databases: Is used when Query is prepared for retrieving data based
on a Logical database (LDB)
Using programs to retrieve data: Here a program can be written with own
logic. Declaration in data section of the program will help the query to select
Create a infoset
or functionalarea
SQ02
Assignment of
user group to
infoset
SQ03
Creation of query
based on infoset
SQ01
3. the elements of data to be retrieved from database. As per the logic, data is
validated, processed. The selection screen can be prepared in Query and
data is retrieved for output.
4. Options
No Automatic Text Recognition
Fixed Point Arithmetic
In example here, we have selected Table join using basis table : SPFLI
The following screen will appear.
4. STEP-3
To join a table with this SPFLI table , Click on the button as shown in image below:
Add table SFLIGHT here.
The tables will automatically get joined to each other. Click on Infoset.
5. STEP-4
We will create empty field groups and Add fields as we want.
The two filedgroupswill be createdcorrespondingtotwotableswe selectedbefore.i.e SPFLI
and SFLIGHT.
STEP-5
1. Select a field group.
2. Select a field, right click and ad field to field group.
Repeat this step for as many field s you want in a field group. Also do same for second
field group.
6. STEP-6
Click Generate Button.
The Infoset ZMJ_INFOSET2 is generated.
Transaction – SQ03 (User group Creation)
STEP-1: Execute transaction SQ03 and create a USERGROUP
7. The USER GROUP will be saved.
STEP-2:Now on same transaction SQ03 , Mention the InfoSet as shown on screen.
Click assign users and InfoSets to a user group created.
STEP-3:On the next screen assign the users for the user group to whom you want to
give authorizations. Click Change authorizations to change the authorization.
8. Assign Infoset to users selected
STEP-4:
Select InfoSets to be assigns to user selected on previous screen.
Save user group.
9. The user group will be saved.
Transaction – SQ01 (Query Creation)
STEP 1: Execute transaction SQ01 to create a query.
Write a query name and create.
Select the InfoSet into which the query is to be created.
10. STEP 2:
Fill details and click Basic List.
Select the keys. You will see the data creating in Yellow circle.
11. Click test.
This is the output of SAP query made by us.
Creating transactionusing ABAP Query
STEP 1:
Transaction SE93.