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

By Suraj Kumar Pabbathi 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 # 1 Topic What is Query? Purpose of Query. 2 3 4 Advantages of Query Infosets/UserGroups/Query in Detail Practical session covering important working models - I 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
  
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 à SAP Query à Queries à SAP Query à InfoSets Used For Maintaining Queries Maintaining InfoSets Transaction Code SQ01 SQ02 SQ03 SQ07

à SAP Query à User Groups Maintaining User Groups à Translation à Query Query Components The Queries component is used by end users to maintain queries. You can carry out the following tasks:  Execute Queries and Generate Lists  Define Queries  Change Queries Infosets Components Language Comparision

 InfoSets are special views of data sources.  An InfoSet describes which fields of a data source can be reported on in queries.  InfoSets are assigned to user groups.  End-users are able to work only with those InfoSets that are relevant to their particular area, as designated by the role or user group that they are assigned to.  Eg: Vendor master data can be important in purchasing as well as in accountancy. The relevant InfoSet is assigned to both roles/user groups. This means that queries based on this InfoSet can be copied and executed by both groups. User Groups Components
1. The User Groups component is used to maintain user groups. The system administrator uses it to set
up the work environment for end-users. Every user assigned to the user group is able to execute the query. 3. Users are not allowed to modify queries from other user groups, although they may, under certain circumstances, copy and execute 2.

Translation/Query Component  A great deal of text is generated when defining queries, InfoSets, and user groups.  The SAP Query displays these texts in the language that you chose when you logged on to the SAP system.  You can compare the text languages using the component Translation/Query.  A related text in one or more additional languages is made available for each of the texts created when defining the query. Query Areas A query area contains a set of query objects (queries, InfoSets, 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 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. Authorizations End-users, system administrators, and translators must all be assigned the appropriate authorizations allowing them to work with the SAP Query. In order to give individual users targeted, specific rights, the following options are available:  Roles/user groups  Authorizations Steps to create a Query Step 1 2 3 Description Create a infoset or functional area Assignment of user group to infoset Creation of query based on infoset TCODE SQ02 SQ03 SQ01

Tools for Queries The following are the tools to manage, create and change queries.  Infoset Query  Queries

 Quick viewer

Working with Infosets, User Groups, Query in detail
By Suraj Kumar Pabbathi, YASH Technologies In this document we shall cover Topic#2. For topic#1, click here. INCLUDEPICTURE "http://www.saptechnical.com/Tutorials/SAPQuery/Part2/Page1.15.gif" \* MERGEFORMATINET

INCLUDEPICTURE "http://www.saptechnical.com/Tutorials/SAPQuery/Part2/Page1.16.gif" \*

Creating and changing Infosets Creating Infosets – Prerequisites Assign Data sources Infoset Display/Change Definition of field groups .  Eg: Vendor master data can be important in purchasing as well as in accountancy.  An InfoSet describes which fields of a data source can be reported on in queries. This means that queries based on this InfoSet can be copied and executed by both groups. The relevant InfoSet is assigned to both roles/user groups. as designated by the role or user group that they are assigned to.MERGEFORMATINET Infosets Components  InfoSets are special views of data sources.  End-users are able to work only with those InfoSets that are relevant to their particular area.  InfoSets are assigned to user groups.

 Do you need to include any particular measures such as access protection?  Do you need to be able to change the long texts and headers for the selected fields? Assign Data sources 1.  Which data source corresponds to the requirements? For example: Material reports in Materials Management Document reports in Financial Accounting  Which fields do you need to include in the InfoSet?  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.  4. Use Tcode: AUTH_DISPLAY_OBJECTS 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. . 2. Declaration in data section of the program will help the query to select the elements of data to be retrieved from database. Name Authorization group: This means that only users authorized to execute programs from this authorization group are able to execute these queries.  Reading tables directly: Is used when Query is prepared for retrieving data from one table.Obtaining additional information Creating Selections Further Codes Application Specific Enhancements Creating Infosets – Prerequisites The following questions help in meeting the prerequisites of creating an infoset.)  Do you need parameters and selection criteria? (Parameters and selection criteria appear on the selection screens of queries that are created using the InfoSet). 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. 3.

 Fields must be assigned to a field group before they can be used in queries.As per the logic.  Assigning additional tables  Creating additional fields  Creating additional Structures  Extras  Selections  Further Code  Application Specific Enhancements Definition of field groups  A field group combines related fields together into a meaningful unit.  Include all table fields  Include key fields  Create empty field groups Note: Logical Database having more than 4 structures has different way of creating field groups.Eg: PNP . data is validated. Options  No Automatic Text Recognition  Fixed Point Arithmetic Display/Change Infoset  The InfoSet display allows you to examine or change the structure of the InfoSet. processed. The selection screen can be prepared in Query and data is retrieved for output.  Sequential datasets 4.

although they may. copy and execute .User Groups Components  The User Groups component is used to maintain user groups.  Every user assigned to the user group is able to execute the query. The system administrator uses it to set up the work environment for end-users. under certain circumstances.  Users are not allowed to modify queries from other user groups.

1.Creating infosets or functional areas  Tcode-SQ02 .

.

.

To create user groups and assign to infosets  Tcode-SQ03 .2.

.

3. To create a query  Tcode-SQ01 .

.

Steps to create selection criteria to the query  Tcode-SQ01 .

.

.

Create Query Groups • Go to Transaction SQ03.SAP Query Step-by-step procedure in configuring SAP Query SAP R/3 Query tools (SAP Query) are based on the following four main components: • • • • Query Areas Query Groups InfoSets Administrative Decisions (Company-specific) Configuration of the Query tools is done in the following manner: • • • • Create Query Groups Assign Users to Query Groups Create InfoSets Assign each InfoSet to a Query Group. .

Now in the main screen.• Ensure that you are in the correct SAP Query area by navigating to Environment à Query Areas • • Select the “Standard Area (Client-specific). enter the name of the Query Group in the User Group field and click on CREATE .

• Enter the description of the User Group in the next popup that appears. • User Group ZSAPTECH_GRP is created. Assign Users to Query Groups • Click on the “Assign Users and InfoSets” button • Enter the SAP User-Ids of all the users you wish to include in the test group. .

Click on SAVE to save your entries. Create InfoSets • • Go to transaction SQ02 Ensure that you are in the correct SAP Query area by navigating to Environment à Query Areas • Enter the name of the InfoSet you wish to create and click on CREATE. .

• Enter the title and the logical database on the popup screen that appears. . We have used the LDB F1S (Flight bookings related) for our demo purpose.

• Expand the tree on the left hand side to view the fields in each table. The right side displays the field groups.• Change InfoSet screen appears. Please note that only the fields that are included here will be available for field selection in the SAP Query Tool that uses this infoSet as a data source. As seen on the screen. Select the field group on the right side and then drag and drop the fields from the left side to this field group. • • . the left side of the screen shows the tables and the fields. Now we need to assign fields to the field groups. These field groups will display in the SAP Query tool during reporting.

click on SAVE. . • Now generate the InfoSet by clicking on GENERATE.all the required fields are added. • When Attach each InfoSet to a Query Group • • Go to transaction SQ02 Enter the InfoSet name created above and click on “User Group Assignment” button.

3. The title bar shows you the query group you are currently in.• Select the query group “ZSAPTECH_GRP” from the above list and click on SAVE. Go to Transaction SQ01. SAP Query Step-by-step procedure in creating a simple list using SAP Query 1. Ensure that you are in the correct SAP Query area by navigating to Environment à Query Areas . 2.

6. The InfoSets of the user group ZSAPTECH_GRP is displayed. 5. . Select the InfoSet ZSAPTECH_IS and click ENTER. enter the name of the query you want to create and press CREATE. In the field “Query”.4.

on . Enter the title and any other notes that are required.7. Click “Next screen” button as shown in the above screenshot.

All the fields in the selected Field groups appear in this screen. 10. All the field groups available with the InfoSet are listed above. Click on Next screen. We can select any particular fields we would like to have in our report. .8. We can select the field groups that need to be listed in the report. 9.

Click on Next screen.11. .

Click on the “Basic List” button to create a SAP Basic list query. totals and counts (as . You can also use this screen to indicate sort order. In this screen. For each field. specify the line number and sequence number as you would like to appear on the report. 13. we can select the fields to appear on the selection screen during execution of the report. 14.12.

As shown above. here also the selection-screen appears. 15. 16. . Click on EXECUTE button to execute the report.necessary). the line structure would display the appearance of fields on the selectionscreen. As it is seen on normal reports. Click on SAVE.

.

3.g. Using table join Directly reading from tables Using logical databases (LDB) e. Capgemini There are 4 different ways to write SAP queries – depending on the approach of data retrieval strategy: 1.Building an SAP Query using ABAP Code By Jayanta Bej. 4. PNP Using some programs . 2.

Press ‘Create’ button. . we’ll demonstrate building SAP query using 2nd method (Direct read of table). 1.Here in this document. Create InfoSet by using t-code SQ02: 2.

3. Press enter. . Press ‘Code’.Press enter.

* Internal table and work area declaration DATA: wa_flight TYPE ty_flight.3. Write the following code in this section. carrname TYPE s_carrname. 4. wa_fldcat TYPE slis_fieldcat_alv. . i_flight TYPE STANDARD TABLE OF ty_flight INITIAL SIZE 0. fldate TYPE s_date. i_fldcat TYPE slis_t_fieldcat_alv. * Type for taking data from tables SFLIGHT and SCARR TYPES: BEGIN OF ty_flight. TYPE-POOLS: slis. currcode TYPE s_currcode. seatsmax TYPE s_seatsmax. connid TYPE s_conn_id. TABLES: scarr. Select the ‘DATA’ coding section. END OF ty_flight. carrid TYPE s_carr_id. seatsocc TYPE s_seatsocc.

. * Populate the field catalogs wa_fldcat-col_pos = 1. * Retrieve data from tables SFLIGHT and SCARR SELECT m1~carrid m1~connid m1~fldate m1~seatsmax m1~seatsocc m2~carrname m2~currcode INTO TABLE i_flight FROM sflight AS m1 INNER JOIN scarr AS m2 ON m1~carrid = m2~carrid. Now go to START-OF-SELECTION section And write the following code in START-OF-SELECTION section to display a few field data in ALV grid display report format. CLEAR: wa_flight.5.

CLEAR: wa_fldcat. wa_fldcat-seltext_l = 'Occupied seats'. CLEAR: wa_fldcat. wa_fldcat-seltext_l = 'Flight connection Id'. wa_fldcat-col_pos = 5. wa_fldcat-col_pos = 7. 7. APPEND wa_fldcat TO i_fldcat. wa_fldcat-col_pos = 2. wa_fldcat-seltext_l = 'Flight date'. * ALV grid display report CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING it_fieldcat = i_fldcat TABLES t_outtab = i_flight EXCEPTIONS program_error = 1 OTHERS = 2. Now create a user group. wa_fldcat-fieldname = 'SEATSMAX'. wa_fldcat-seltext_l = 'Maximum capacity'. IF sy-subrc <> 0. Generate the InfoSet. APPEND wa_fldcat TO i_fldcat. wa_fldcat-col_pos = 3. wa_fldcat-seltext_l = 'Local currency of airline'. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. wa_fldcat-fieldname = 'CARRNAME'. wa_fldcat-fieldname = 'CURRCODE'.wa_fldcat-fieldname = 'CARRID'. APPEND wa_fldcat TO i_fldcat. ENDIF. wa_fldcat-seltext_l = 'Airline carrier ID'. CLEAR: wa_fldcat. wa_fldcat-col_pos = 6. APPEND wa_fldcat TO i_fldcat. wa_fldcat-fieldname = 'SEATSOCC'. CLEAR: wa_fldcat. wa_fldcat-fieldname = 'CONNID'. . EXIT. APPEND wa_fldcat TO i_fldcat. APPEND wa_fldcat TO i_fldcat. CLEAR: wa_fldcat. wa_fldcat-col_pos = 4. CLEAR: wa_fldcat. APPEND wa_fldcat TO i_fldcat. wa_fldcat-seltext_l = 'Airline name'. wa_fldcat-fieldname = 'FLDATE'. 6. CLEAR: wa_fldcat.

8. Now assign the user group ZUGRP_BEJ to the InfoSet ZINFOSET_BEJ. . I’ve assigned two users in my user group.

. Now create the query.Save it. 9.

. Now execute the query from SQ01.10. The following selection screen will appear where we need to put the flight date.

2.06. Transport of SAP Query objects By Shiva Kumar Tirumalasetty. From Transaction SQ02/SQ03->Environment->Transports: .Enter the flight date as 11. Deloitte Consulting India Pvt Ltd ABAP Queries can be transported to different clients by the following two ways: 1. we’ll get the following ALV grid display report.2008 and execute the query. By using the standard program ‘RSAQR3TR’ By using the transport option available on the application bar in Transactions SQ02 or SQ03.

all the options come up for transporting the queries. The transport action is performed based on the radio button selected on the screen.On the next screen. .

2. The User Group is to be transported first. The transport action is performed based on the radio button selected on the screen.The transports are to be made in the following order: 1. followed by the Infoset and then the Queries. User Group transport Infoset transport Infoset and Query transport Queries transport The transports are to be made in the specified order. By using the standard program ‘RSAQR3TR’: Execute the standard program RSAQR3TR On the next screen. 3. 4. . all the options come up for transporting the queries.

the same can be used there for displaying the data fetched from the database. Create transaction for SAP-Query By Aswani Bharath. Dell Services 1) Open transaction SE93 .Once the query is transported or uploaded in the destination system in the method specified above.

sort text for your transaction 3) Choose radio button 5. Transaction with parameter.2) Put object name . 4) Default value for transaction ‘START_REPORT’ 5) In bellow default value section insert default value .

.SREPOVARI-REPORTTYPE = AQ "Parameter indicating Abap Query D_SREPOVARI-REPORT = ZY_CS_ALLSLS "Query User group D_SREPOVARI-EXTDREPORT= ZY_SLS_MST_001 "Query name 6) Save the transaction.

8) Execute the transaction. .

Sign up to vote on this title
UsefulNot useful