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 # 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 à SAP Query à User Groups à Translation à Query Used For Maintaining Queries Maintaining Infosets Maintaining User Groups Language Comparison Transaction Code SQ01 SQ02 SQ03 SQ07

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  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.
2. 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. Users are not allowed to modify queries from other user groups, although they may, under certain circumstances, copy and execute

3.

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 Description TCODE

. Create Query Groups • Go to Transaction SQ03.1 2 3 Create a infoset or functional area Assignment of user group to infoset Creation of query based on infoset SQ02 SQ03 SQ01 Tools for Queries The following are the tools to manage.  Infoset Query  Queries  Quick viewer 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. create and change queries.

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

• 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.• Enter the description of the User Group in the next popup that appears. .

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

Now we need to assign fields to the field groups. The right side displays the field groups. . As seen on the screen. These field groups will display in the SAP Query tool during reporting. the left side of the screen shows the tables and the fields.• Change InfoSet screen appears. • • Expand the tree on the left hand side to view the fields in each table. 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.

When all the required fields are added. click on SAVE. . • Attach each InfoSet to a Query Group • • Go to transaction SQ02 Enter the InfoSet name created above and click on “User Group Assignment” button. • Now generate the InfoSet by clicking on GENERATE.• Select the field group on the right side and then drag and drop the fields from the left side to this field group.

Transaction with parameter. .sort text for your transaction 3) Choose radio button 5. Create transaction for SAP-Query 1) Open transaction SE93 2) Put object name .• Select the query group “ZSAPTECH_GRP” from the above list and click on SAVE.

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.

Ad-Hoc query provides three different kinds of reports: • • Basic List .Simple reports • Statistics . A special feature is the Human Resources (HR) component. InfoSet Query is suitable for reporting in all areas of the SAP R/3 system.Creating Ad Hoc query (HCM related infoset query) The InfoSet Query is a useful tool for maintaining queries within the SAP Query and is suitable for developing queries and for ad-hoc reporting. Function area provides special views of logical databases. the name Ad-Hoc Query is used instead of InfoSet Query. When InfoSet Query is used in HR for ad-hoc reporting.for analytical reports The first step in the process of creating an Ad-Hoc query is to create a Functional Area. percentages etc Ranked List . They determine which fields of a logical database can be evaluated in queries.reports with statistical functions such as Averages. Go to Tcode SQ03. .

Select Query areas Menu->Environment->Query areas Select the radio button ‘Global area’. .

Specify the sap logins of the users whom you want to authorize for using the functional area and click on the Create button. .Go to the menu path Environment => User Group or SQ03 à Give a user group name in the screen.Click on ‘Choose’ Create user group Here you specify the users who should be authorized to run the query. Select User group as ‘zdemo_user’ (Create Z user group) Click on ‘CREATE’ button. A user group is always associated with a Functional Area. .

Pass short description click SAVE Go to Environment menu select INFOSET or go for tcode (SQ02) Create Infoset with Z like ‘zdemo_infoset’ .

Click on create button Name as ‘Shortdesc’.. (demo) Select radio button Logical database ‘PNP or PNPC’ .

Click on Continue button Open ‘Basic personal data’ Select infotype which u need (like above screen short) Click on continue button .

Click on save and Click on generate button (red button) Go back to main screen Click on ‘Role/User group assignment’ tab .

.(zdem_user) Save it and back...... . Go to tcode for SQ01. Query ‘zdemo_01’ (Create zname) Click on ‘create’ button Select ‘infoset’ click on continue.Select assigned table check box with User group which u already created.

...(demo for pa infotype) Save... Back...Pass title as Shortdesc.(the fields you required as Selection screen fields and the fields you need as Output fields) .... Click on ‘Infoset Query’ button Select selection screen field and Output fields..

Select fields from which u already given info types .Select output check box with right click –select output-only value..

....Finally click on save button Click on continue.. Click on continue ready for you REPORT .. Back. Click on Execute button (F8).

Scope: All task lists pertaining to Production and Planning. complete the details with right information . Master Recipe (2). Rate Routing (R) Procedure: Follow the procedure step by step: Transaction Code Menu path Create new Quick view Write the appropriate name of query SQVI Tools>Utilities>SQVI .QuickViewer After you click on create button. Routing (N).Developing SAP Query for Task List Data Extraction Purpose: To create an SAP query to extract task list data from system. system will populate the following window.

Once you have done with above steps you will get “Choose Data Source” screen. Here in the following step you need to connect different tables properly in order to get task list data.

We are starting with MAPL (Assignment of Task Lists to Materials) table. Similarly, we need to take following tables in order to get the appropriate information. PLKO (Task list – header) PLPO (Task list - operation/activity) PLAS (Task list - selection of operations/activities) CRHD (Work Center Header) CRTX (Text for the Work Center or Production Resource/Tool) MARA (General Material Data) MAKT (Material Descriptions)

Between PLPO and CRHD, the default link is with field OBJTY. You need to delete this link and create with PLPO-ARBID and CRHD-OBJID. For this click on ARBID in PLPO table and drag the cursor towards OBJID in CRHD table. Afterwards it should like

After you finish with above activities the screen will look like

Following tables explain the link details between different tables used above: Table 1 MAPL PLNTY PLNNR PLNAL MATNR PLKO PLNTY PLNNR PLNAL PLAS PLNTY PLNNR PLNKN PLPO ARBID CRHD OBJID Table2 PLKO PLNTY PLNNR PLNAL PLAS PLNTY PLNNR PLNAL PLPO PLNTY PLNNR PLNKN CRHD OBJID CRTX OBJID Table 3 MARA

MATNR

mainly you need to select which fields you want to see in selection screen and which one in output. .MARA MATNR MAKT MATNR In the following steps.

Similarly select all those fields from table enlisted which you want to see in Selection and Display screen. you want to see following fields in Selection Screen o o o Material Plant Task List Type And following fields in output o o Material Material Description . For example.

and Plant. . Group Counter. Material. you can select/deselect additional fields in Quick viewer: Initial screen It’s better to arrange Sort Sequence in order to get proper operation number in output for a combination of Group.o o o o o o o o o o o o o o o o o o o o o o o o Plant Group Group Counter Task List Description Usage Status From Lot Size UoM To Lot Size UoM Operation/Activity Work center Work center description Operation short Text Operation Base Quantity UoM Standard value1 UoM for Std value1 Standard value2 UoM for Std value2 Standard value3 UoM for Std value3 Setup Group Key Setup Group Category Note: As per your requirement.

Now it’s the time to see the result of efforts that you have put in to develop this query. So execute the transaction. .Check and Save the Query.

Deloitte Consulting India Pvt Ltd .and the Result of your efforts is Transport of SAP Query objects By Shiva Kumar Tirumalasetty.

2. The transport action is performed based on the radio button selected on the screen. . By using the standard program ‘RSAQR3TR’ By using the transport option available on the application bar in Transactions SQ02 or SQ03.ABAP Queries can be transported to different clients by the following two ways: 1. all the options come up for transporting the queries. From Transaction SQ02/SQ03->Environment->Transports: On the next screen.

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

Design Logic: 1.e. Design a custom function module which will collect the current SAP query name at run time (i. check the expiry date of that query from the custom table and generate an error message if the query is expired or work as per the code in the infoset if it’s not expired. the same can be used there for displaying the data fetched from the database. during query execution). 2. Setting the Expiry date in SAP Query Business Requirement: The client wants to maintain expiry dates to each and every SAP queries that are running in production. . Maintain a custom table with two fields – query name and query expiry date.Once the query is transported or uploaded in the destination system in the method specified above. The expired query will not be allowed to run in production.

infoset and query name. . Explanations: Step 1: Create a Z-table ZQUERY_EXPIRE along with a table maintenance generator.3. Put that custom function module in the infosets of all the queries. Step 2: Maintain query names along with their expiry dates in the Z-table ZQUERY_EXPIRE via SM30. refer to table AQLQCAT. For more details on user group. Keep all the executable codes of the infosets in the ‘ELSE’ part of the sy-subrc check.

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

WRITE: /5 'Hello1'. Test: Suppose today’s date is 20/03/2009. CALL FUNCTION 'ZQUERY_EXP_CHECK' EXCEPTIONS query_expired = 1 OTHERS = 2.03.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. The expiry date of the query QRY_TEST3 is today (20/03/2009). Scenario 2: Execute the query QRY_TEST3 (expiry date is equal to the current date) from SQ01. . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 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. ENDIF. The expiry date of the query BEJ_QRY_TEST1 was 18. ELSE.2009 (as maintained in the Z-table).

Using t-code SQ03.Execute. a. which are running in production. create one user group ZPROD_BEJ (Jayanta Bej's User Group). . Assign user ids to this user group. b. the actual code of the infoset will be executed. SAP Query for getting hourly background job status This SAP query is designed to get the hourly background job status updates. Step 1: Create user group.

b. a. Add two selection criterion S_JOBNAM (Job Name) & S_STRTDT (Start Date) and one parameter P_ENDTIM (Time) in the Selections tab.Step 2: Create infoset. Using t-code SQ02. create one infoset BATCH_JOBLIST_REPORT with the direct read from the table TBTCO and including key field only. .

Details: P_ENDTIM. . Details: S_STRTDT.Details: S_JOBNAM.

c. SDLSTRTTM type TBTCO-SDLSTRTTM. JOBNAME type TBTCO-JOBNAME. SDLSTRTDT type TBTCO-SDLSTRTDT. stat(15). In the START-OF-SELECTION section. SDLSTRTTM type TBTCO-SDLSTRTTM. FLAG2(1). DATA: begin of gt_TBTCO2 occurs 0. JOBNAME type TBTCO-JOBNAME. DATA : gt_tbtco4 like gt_tbtco occurs 0 with header line. SDLSTRTTM type TBTCO-SDLSTRTTM. refresh gt_tbtco[]. DATA: end of gt_TBTCO. JOBNAME type TBTCO-JOBNAME. ENDTIME type TBTCO-ENDTIME. DATA: begin of gt_TBTCO occurs 0. DATA: begin of gt_TBTCO1 occurs 0. write the following code: DATA : FLAG(1). write the following code: select JOBNAME SDLSTRTDT SDLSTRTTM ENDTIME STATUS from TBTCO into corresponding fields of table gt_tbtco3 where jobname in s_jobnam and status = 'P'. stat(15). Go to Code tab. . SDLSTRTDT type TBTCO-SDLSTRTDT. DATA : gt_tbtco3 like gt_tbtco occurs 0 with header line. ENDTIME type TBTCO-ENDTIME. status(15). STATUS type TBTCO-STATUS. DATA: end of gt_TBTCO2. SDLSTRTDT type TBTCO-SDLSTRTDT. FLAG1(1). In the DATA section. DATA: end of gt_TBTCO1. d. ENDTIME type TBTCO-ENDTIME.

when 'S'. gt_tbtco1-stat = 'Released'. endif. gt_tbtco1-stat = 'Released'. gt_tbtco1-stat = 'Active'. gt_tbtco1-stat = 'Released'. when 'A'.clear gt_tbtco[]. when 'P'. sort gt_tbtco by JOBNAME SDLSTRTTM. endat. flag = 'X'. endif. if gt_tbtco-status = 'F' . gt_tbtco1-stat = 'Released'. sort gt_tbtco by JOBNAME SDLSTRTTM. clear gt_tbtco1. else. endcase. gt_tbtco1-stat = 'Cancelled'. append gt_tbtco1. gt_tbtco1-stat = 'Cancelled'. elseif gt_tbtco-status = 'F' and gt_tbtco-SDLSTRTTM ge P_ENDTIM. Loop at gt_tbtco. clear gt_tbtco1. . case status. when 'Y'. else. gt_tbtco4[] = gt_tbtco[]. append gt_tbtco1. select JOBNAME SDLSTRTDT SDLSTRTTM ENDTIME STATUS from TBTCO into corresponding fields of table gt_tbtco where jobname in s_jobnam and SDLSTRTDT in s_strtdt. MOVE-CORRESPONDING gt_tbtco to gt_tbtco1. if flag = 'X'. at new jobname. gt_tbtco1-stat = 'Scheduled'. append gt_tbtco1. if ( gt_tbtco-SDLSTRTTM le P_ENDTIM ) . delete gt_tbtco where ENDTIME < P_ENDTIM and ( status = 'F' or status = 'A' ). gt_tbtco1-stat = 'Suspended'. when 'Z'. clear gt_tbtco1. else. status = gt_tbtco-status. append gt_tbtco1. if ( gt_tbtco-SDLSTRTTM le P_ENDTIM ) . when 'R'. gt_tbtco1-stat = 'Active'. check sy-subrc = 0.

* Display List of Cases to be Cancelled CALL FUNCTION 'RS_COMPLEX_OBJECT_EDIT' EXPORTING object_name = 'RESULTS' changing object = GT_TBTCO2[] EXCEPTIONS OBJECT_NOT_SUPPORTED = 1 OTHERS = 2.flag2. move-corresponding gt_tbtco4 to gt_tbtco2. else. Loop at s_jobnam. sort gt_tbtco1 by jobname. if gt_tbtco4-status = 'F'. endif. if sy-subrc = 0. else. clear status. endloop. append gt_tbtco2. endif. endif. clear gt_tbtco2. append gt_tbtco2. clear gt_tbtco2. . gt_tbtco2-stat = 'Not Scheduled'. endif. gt_tbtco2-stat = 'Canceled'. sort gt_tbtco3 by jobname. gt_tbtco2-stat = 'Scheduled'. if sy-subrc = 0. CLEAR FLAG. gt_tbtco2-jobname = s_jobnam-low. append gt_tbtco2. flag2 = 'X'. endif.clear gt_tbtco1. if not gt_tbtco2[] is Initial. endif. move-corresponding gt_tbtco3 to gt_tbtco2. flag2 = 'X'. move-corresponding gt_tbtco1 to gt_tbtco2. if sy-subrc = 0. endif. read table gt_tbtco4 with key jobname = s_jobnam-low. read table gt_tbtco3 with key jobname = s_jobnam-low. append gt_tbtco2. endloop. clear : flag1. read table gt_tbtco1 with key jobname = s_jobnam-low. gt_tbtco2-stat = 'Finished'. if flag1 <> 'X' and flag2 <> 'X'. clear gt_tbtco2. endif. clear gt_tbtco2. flag1 = 'X'. else.

create one query BATCH_JOBLIST for the infoset BATCH_JOBLIST_REPORT. Select the variant. Step 4: Execute the query from SQ01 with proper variant for the list of background jobs whose hourly status needs to be found out. Step 3: Create the query. Suppose we want to find out the background status at 2 PM for the below list of jobs: PROC_CHGPNTRS_ENERGYCARE PROCESS_CP_ACTIVITY PROCESS_CP_CONTACT PROCESS_CP_CONTRACT PROCESS_CP_SALESORDER PROCESS_IDOC_IN_ACTIVITY PROCESS_IDOC_IN_ADDRSYNCH PROCESS_IDOC_IN_BPCAMERGE PROCESS_IDOC_IN_OAMUPDATE PROCESS_IDOC_IN_PARTNRUPD PROCESS_IDOC_IN_PREPAY PROCESS_IDOC_IN_SALESORDR PROCESS_IDOC_OUT_ACTIVITIES PROCESS_IDOC_OUT_AQSND0055 PROCESS_IDOC_OUT_CONTACTS PROCESS_IDOC_OUT_CONTRACT PROCESS_IDOC_OUT_OBJSD0064 PROCESS_IDOC_OUT_SOSTATUS PROCESS_CP_FILES PROCESS_IDOC_OUT_FILES SWWERRE SWEQSRV SWWDHEX ZUBC_DELETE_WORKITEMS ZZ_IDOC_DISPATCH Z_APP_LOG_DEL_DAILY ZUBC_DELETE_IDOCS EMMA_AUTOPROC_SB61 .EXIT. Using t-code SQ01. Generate the infoset and then attach it to the user group ZPROD_BEJ.

the date should be equal to current date and time should be current time and should be done as follows: Now selecting the variant JOBLIST (JOB LIST STATUS). In the variant. The following report will be displayed. execute the query.ZUUBI_REPLACEMENT_BILLING_01 ZUBC_DELETE_APP_LOGS SAP_ARCH_RETHIST SAP_ARCH_PAYLOTS SAP_ARCH_RETLOTS SAP_APURG_MDR1 Put all these job names in the select option for job name. . Now we execute the query.

This is the status update of all the listed background jobs for the hour 14 i. 2. Building an SAP Query using ABAP Code There are 4 different ways to write SAP queries – depending on the approach of data retrieval strategy: 1.e. 4. PNP Using some programs .g. 3. Using table join Directly reading from tables Using logical databases (LDB) e. 2 PM.

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

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

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

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. * 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.5.

APPEND wa_fldcat TO i_fldcat. CLEAR: wa_fldcat. APPEND wa_fldcat TO i_fldcat. wa_fldcat-col_pos = 7. ENDIF. wa_fldcat-seltext_l = 'Maximum capacity'. APPEND wa_fldcat TO i_fldcat. CLEAR: wa_fldcat. Generate the InfoSet. CLEAR: wa_fldcat. wa_fldcat-col_pos = 5. APPEND wa_fldcat TO i_fldcat. wa_fldcat-fieldname = 'FLDATE'. CLEAR: wa_fldcat. 6. . wa_fldcat-fieldname = 'CARRNAME'. wa_fldcat-fieldname = 'CONNID'. CLEAR: wa_fldcat. wa_fldcat-col_pos = 4. CLEAR: wa_fldcat. IF sy-subrc <> 0.wa_fldcat-fieldname = 'CARRID'. * 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. wa_fldcat-fieldname = 'SEATSOCC'. APPEND wa_fldcat TO i_fldcat. APPEND wa_fldcat TO i_fldcat. wa_fldcat-seltext_l = 'Flight connection Id'. wa_fldcat-seltext_l = 'Airline name'. EXIT. wa_fldcat-seltext_l = 'Airline carrier ID'. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. wa_fldcat-seltext_l = 'Flight date'. CLEAR: wa_fldcat. Now create a user group. wa_fldcat-seltext_l = 'Occupied seats'. wa_fldcat-fieldname = 'SEATSMAX'. wa_fldcat-fieldname = 'CURRCODE'. wa_fldcat-col_pos = 2. 7. wa_fldcat-seltext_l = 'Local currency of airline'. wa_fldcat-col_pos = 6. wa_fldcat-col_pos = 3. APPEND wa_fldcat TO i_fldcat.

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

9. . Now create the query.Save it.

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

SAP Query Step-by-step procedure in creating a simple list using SAP Query 1. . 2. Go to Transaction SQ01. The title bar shows you the query group you are currently in.2008 and execute the query.Enter the flight date as 11.06. we’ll get the following ALV grid display report.

The InfoSets of the user group ZSAPTECH_GRP is displayed. . Ensure that you are in the correct SAP Query area by navigating to Environment à Query Areas 4.3. enter the name of the query you want to create and press CREATE. 5. In the field “Query”.

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

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

.13. Click on the “Basic List” button to create a SAP Basic list query.

15. Click on EXECUTE button to execute the report. As shown above. here also the selection-screen appears. 16. As it is seen on normal reports. totals and counts (as necessary).14. You can also use this screen to indicate sort order. . the line structure would display the appearance of fields on the selection-screen. Click on SAVE. specify the line number and sequence number as you would like to appear on the report. For each field.

.

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

16.gif" MERGEFORMATINET \* Infosets Components  InfoSets are special views of data sources.com/Tutorials/SAPQuery/Part2/Page1. .saptechnical.INCLUDEPICTURE "http://www.

Creating and changing Infosets Creating Infosets – Prerequisites Assign Data sources Infoset Display/Change Definition of field groups 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). The relevant InfoSet is assigned to both roles/user groups. as designated by the role or user group that they are assigned to.  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.  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.  End-users are able to work only with those InfoSets that are relevant to their particular area. This means that queries based on this InfoSet can be copied and executed by both groups.  InfoSets are assigned to user groups.  Do you need to include any particular measures such as access protection? .

 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. Name Authorization group: This means that only users authorized to execute programs from this authorization group are able to execute these queries.  Assigning additional tables  Creating additional fields  Creating additional Structures  Extras  Selections  Further Code  Application Specific Enhancements . The selection screen can be prepared in Query and data is retrieved for output. 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. processed. Do you need to be able to change the long texts and headers for the selected fields? Assign Data sources 1. Declaration in data section of the program will help the query to select the elements of data to be retrieved from database.  Reading tables directly: Is used when Query is prepared for retrieving data from one table.  Sequential datasets 4. As per the logic. 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. data is validated. 3. 2.

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.Eg: PNP User Groups Components  The User Groups component is used to maintain user groups.  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. copy and execute .  Users are not allowed to modify queries from other user groups.Definition of field groups  A field group combines related fields together into a meaningful unit. although they may.  Fields must be assigned to a field group before they can be used in queries. under certain circumstances.

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

.

.

.

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

.

3. To create a query  Tcode-SQ01 .

.

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

Sign up to vote on this title
UsefulNot useful