Download SAP Query Tutorial for Beginners PDF

TitleSAP Query Tutorial for Beginners
File Size4.0 MB
Total Pages83
Table of Contents
                            SAP Query
	What is SAP Query? Purpose and Advantages of SAP Query?
SAP Query
	Create transaction for SAP-Query
	Creating Ad Hoc query (HCM related infoset query)
	Developing SAP Query for Task List Data Extraction
	Transport of SAP Query objects
	Setting the Expiry date in SAP Query
	SAP Query for getting hourly background job status
	Building an SAP Query using ABAP Code
SAP Query
	Working with Infosets, User Groups, Query in detail
                        
Document Text Contents
Page 1

SAP Query

Step-by-Step Tutorials

• What is SAP Query? Purpose and Advantages of SAP Query?
• Configuration for SAP Query
• Create transaction for SAP-Query
• Creating Ad Hoc query (HCM related infoset query)
• Developing SAP Query for Task List Data Extraction
• Transport of SAP Query objects
• Setting the Expiry date in SAP Query
• SAP Query for getting hourly background job status
• Building an SAP Query using ABAP Code
• Development of Basic List Query using SAP Query
• Working with infosets/User Groups/Query in detail

What is SAP Query? Purpose and Advantages of SAP Query?

SAP Query is SAP’s tool to define and execute once own reports without knowing ABAP
programming language.

Let us see the key topics to explore SAP Query.

Topic # Topic
1 What is Query?

Purpose of Query.

Advantages of Query
2 Infosets/UserGroups/Query in Detail
3 Practical session covering important working models - I
4 Practical session covering important models-II

Various Lists and Background Scheduling

In this document we shall cover Topic#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

Page 2

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

Features:

The SAP Query comprises five components:

 Queries

 InfoSet Query

 Infosets

 User Groups

 Translation/Query

Classic reporting- the creation of lists, statistics and ranked lists- are covered by the InfoSet Query
and Queries components. Other components’ range of functions cover the maintenance of Infosets,
the administration of user groups and also the translation of texts created in the SAP Query. All
data required by a user for a report can be read from various tables.

To define a report, you first have to enter individual texts, such as titles, and select the fields and
options, which determine the report layout. In the WYSIWYG (What You See Is What You Get)
mode, you can edit the lists using Drag & Drop and various toolbars.

Overview:

The following sections describes the individual SAP Query components and provides general
information about query areas, transport and authorizations

Menu Path Used For Transaction
Code

à SAP Query à Queries Maintaining Queries SQ01

à SAP Query à Infosets Maintaining Infosets SQ02

à SAP Query à User Groups Maintaining User Groups SQ03

à Translation à Query Language Comparison SQ07

Page 41

Step 3: Design a custom function module ZQUERY_EXP_CHECK with an exception QUERY_EXPIRED
(Query has expired).

FUNCTION zquery_exp_check.
*"---------------------------------------------------------------
*"*"Local Interface:
*" EXCEPTIONS
*" QUERY_EXPIRED
*"---------------------------------------------------------------
TABLES: zquery_expire.
CONSTANTS: c_fill TYPE c VALUE '='.
DATA: v_sycprog LIKE sy-cprog,
v_user_grp1(30) TYPE c,
v_user_grp2(14) TYPE c,
v_query_name1(14) TYPE c,
v_rest(14) TYPE c,
v_query_name TYPE aqs_quname.
TYPES: BEGIN OF ty_query,
qnum TYPE aqs_quname,
exp_date TYPE datum,
END OF ty_query.
DATA: wa_query TYPE ty_query,
i_query TYPE STANDARD TABLE OF ty_query INITIAL SIZE 0.
v_sycprog = sy-cprog.
v_user_grp1 = v_sycprog+4(26).
v_user_grp2 = v_user_grp1+12(14).
SPLIT v_user_grp2 AT c_fill INTO v_query_name1 v_rest.
v_query_name = v_query_name1.
SELECT qnum
exp_date
FROM zquery_expire
INTO TABLE i_query
WHERE qnum EQ v_query_name.
LOOP AT i_query INTO wa_query.
* If the query expires, generate the error message
IF wa_query-exp_date LT sy-datum.
MESSAGE e000(zbasis_msg) RAISING query_expired.
* If the expiary date is today or yet to come, don't do anything
ELSE.
MESSAGE i002(zbasis_msg).
ENDIF.
ENDLOOP.
ENDFUNCTION.

Page 42

Step 4: Call this custom function module from the START-OF-SELECTION code sections of all the infosets of
the queries that are maintained in the custom table ZQUERY_EXPIRE.

Here we’ve added the following code in all the infosets of the 3 queries maintained in the custom table.

CALL FUNCTION 'ZQUERY_EXP_CHECK'
EXCEPTIONS
query_expired = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
WRITE: /5 'Hello1'.
ENDIF.

Test: Suppose today’s date is 20/03/2009. The expiry date of the query BEJ_QRY_TEST1 was 18.03.2009 (as
maintained in the Z-table).

The expiry date of the query QRY_TEST3 is today (20/03/2009).

Scenario 1: Execute the query BEJ_QRY_TEST1 (expiry date is less than the current date) from SQ01.



Execute; the following error message will be generated.



Scenario 2: Execute the query QRY_TEST3 (expiry date is equal to the current date) from SQ01.

Similer Documents