You are on page 1of 11

SAP ERP Human Capital Management (SAP ERP HCM): SAP Adhoc Query SQ01 SQ02 SQ03

Posted by Shafiq Rehman Jun 16, 2008 This blog will focus on the capabilities of SAP Query (a.k.a. Adhoc Query) and Creating Custom fields in infosets, with emphasis on HR Module.

Most of the reporting needs of an organization can be addressed through Adhoc Queries. For some specific requirements we will need custom ABAP reports, and to create custom fields ABAP knowledge is required.

First let’s refresh some concepts, processes and transactions involved in the process.

Infoset (Tcode: SQ02)
Here we will include all of our tables or infotypes that will provide us data for our queries. If you are trying to create queries in HR Module then it is strongly recommended to use a Logical Database to create your queries, because if you are using HR Tables then joining them will be a problem because of date fields (BEGDA/ENDDA).

Logical database will always use inner join and will skip the rows that will not match in corresponding infotypes. For example: You are trying to create a query with Pernr and name from infotype 2 and Work Address from infotype 6. Then the report will not include the persons that do not have a work address. Only employees shown on the report will be those that have a work address subtype of infotype 6 populated. This constraint is usually overlooked and it results in wrong reports.

Generated by Jive on 2013-03-01+01:00 1

3. otherwise you will have to create a new query to choose a different infoset. User Groups (Tcode: SQ03) Once you have created the infoset you have to assign it to a user group.k. PNPCE then a screen will pop-up to select the infotypes.e. So go to transaction SQ01 and create a new query: 1. If you have used tables then only give one table name and you will be brought to the screen where you can add more tables and specify joins between tables. If you have used logical database e. Give Infoset a description. 1. you can also change the join type from inner join to outer join. You name of the query you want to create and hit create button. This is mandatory. 2. There      is an area ‘Field Group’ in infoset screen.SAP ERP Human Capital Management (SAP ERP HCM): SAP Adhoc Query SQ01 SQ02 SQ03 Steps to create a new infoset using logical database PNPCE: 1. If       you later want to add more infotypes then click on menu item ‘Edit’ ->       ‘Change Info-Type Selection’ and add or remove the infotypes. If you already have a user group then you do not need to go to SQ03. only the fields that appear      here will be available while creating queries. title etc. To create a new user group go to transaction SQ03 and create a new user group and assign users to that user group. SAP Queries) are used for reporting off the infoset created in previous steps. give source of data for infoset i. Save and generate your infoset. as when you generate the infoset. on the main screen of SQ02 you can click on button ‘Role/ User Group Assignment’ to specify the user groups tied to that infoset. 4. Select the infotypes and continue. so be sure which infoset you want to choose. Logical Database or Tables etc. under each node of infotype/table you will see some fields in blank or blue text color. Ad-hoc Queries (Tcode: SQ01) Ad-hoc queries (a. which are pretty self explanatory and we will not go into details of them. Generated by Jive on 2013-03-01+01:00 2 . NOTE: You cannot change the infoset later. so you will have to manually drag      and drop them in appropriate field groups. click on ‘Join Tables’ and click on ‘Insert Tables’. Go to Transaction SQ02. 2. 5. will be asked the name of the infoset that you want to use. Blue fields are those that are included in the infoset and hence available for reporting in SQ01. To       add more tables. Give 2. 2.g. There will be various options on next screen regarding output format. a program is generated with the code reflecting your changes in infoset. You can drag and drop the matching field from one table to another to specify joins. All fields from infotypes      may not be available in field groups.a. On the left hand side. 1. 1.

this will be the name of the field used inside the ABAP code. It can be changed visa dragging and dropping on appropriate location in right hand pane. Second box is to display the field on the selection screen to restrict the records based on some criteria. we will come back from refreshing memories of creating queries and jump into a little technical area. fields that are not provided by SAP. Generated by Jive on 2013-03-01+01:00 3 . We can then either transport the infoset from Development to next systems or we can download and upload it in production (which will again need production system to be opened for some time). 3. Format: Give the technical information about your field or simply give the LIKE reference e. 5. Save and Run your report. it will pick up the attributes from that field. Long Text: This text will appear in the infoset for that field. Go to your infoset in SQ02 in change mode. For that. Give      it a name. P0002-VORNA. Each      infotype will have ‘Additional Fields’ node which contains the texts for      codes like for Position. To create a custom field: 1. 2. 2. it will contain a field text:position which will      display the STEXT for that position. On next screen. First box is to display the field on the report. If you need custom development then best place is the Development environment. when the report will be in run mode. Creating Custom Fields: Now.SAP ERP Human Capital Management (SAP ERP HCM): SAP Adhoc Query SQ01 SQ02 SQ03 2. 2. you will need ABAP access to the system. Fields will by default have same order in which you select them. You will see two check boxes in front of each field. provide following information. 6. Select      ‘Additional Field’ and click continue. and inside the SQ01 query while developing. 1. Right      click on the ‘Additional fields’ node of the infotype in which you want to      create the new custom field and click create.g. so if you are working in Production or Quality system then most probably you will not have authorization for that. We can create fields that will fetch data according to out own logic. 3. Header text: This text will appear on top of the field as header. 1. Expand the infotype in which you are interested. 4. A      faster way will be to click on ‘Basic List’ button. 3.

Save and generate the infoset.      go to menu option ‘Query > More Functions -> Generate Program’. They are usually a calculation on another field. Right      click the newly created field and click ‘Field Code’. if you already have your infoset developed and want to include some simple logic then Local Fields can be useful. 4. 7. go to tcode SQ01. so that it can be accessed in reports. Assign this newly created field to the field group. 9. This code will be executed for each pernr.SAP ERP Human Capital Management (SAP ERP HCM): SAP Adhoc Query SQ01 SQ02 SQ03 4. or Age is another calculated local field). E. select the query. like for example if you want to add a field for membership status depending on field Age (Assuming you already have a field Age in your infoset. then return ‘Junior’.g.      then go out of SQ01 transaction and then come back to SQ01 and select your      query 2. This is the place where you will put all your code. it is easy. Click on      ‘Automatically Adjust’ check box next to each field and update the query. P0006 etc. Tips: 1.      it will automatically ask for updating the new changes. If you      are working on custom fields in infoset and have opened a query in another       session then the changes in custom fields will not be seen in that query. Once done with the logic. 8.) you can use same macros as you will use in your normal HR Programs. We want a field that will return values based on following logic: If Age is less than 21. Generated by Jive on 2013-03-01+01:00 4 .      Otherwise you can go to menu option ‘Query -> More Functions >      Adjust’. If you      have changed the data types of custom field in infoset then you need to      ‘Adjust’ the query. so that it appears in the query. 6. 10.g. Local Fields: Local Fields are used in queries. Sequence       of code: This number will be sequence of the code to be executed inside       that field group. 5.      You need to generate the query again. assign the value to the field name. P0002. If you have used Logical Database then appropriate structures will be filled in automatically (e. if you have created 5 custom fields and you want       one field’s code to be executed before some other field so that some       variables are set-up then give the appropriate sequence. again come out of SQ01 and then go back.

SAP ERP Human Capital Management (SAP ERP HCM): SAP Adhoc Query SQ01 SQ02 SQ03 If Age is between 21 and 65. and Field Heading will be visible at the top of the field when the query output is displayed i. If Age is more than 65. Generated by Jive on 2013-03-01+01:00 5 . then return ‘Adult’. it is for end user. Go to menu item ‘Edit -> Local Field -> Create’ Field Label will be visible inside SQ01 query creation so we can say it is for SAP HR Person who will be creating or modifying the query. then return ‘Senior’.e.

And. do not worry). click on ‘Complex Calculation’ (there is nothing complex here.SAP ERP Human Capital Management (SAP ERP HCM): SAP Adhoc Query SQ01 SQ02 SQ03 You will find rest of the items on the above screen pretty self explanatory. Here is a screenshot on how to use the Complex Calculation screen: If you want to add more conditions then play with + and – icons on the above screen. Generated by Jive on 2013-03-01+01:00 6 . you are done with creating local field.

SAP provides various options for that. Lets say we are developing a simple report in HR. for the sake of understanding we will go through the simplest of them. To use this feature. the data of that employee is passed to an ABAP Program and that triggers some interface or whatever is coded in that program. Goto menu item ‘Goto -> Report Assignment’. Generated by Jive on 2013-03-01+01:00 7 . that displays Personnal Number. It will take many pages to go through all of them. Report Assignment is in fact making the reports interactive. Isn’t that fascinating? Another example would be that when a user double click a query row.SAP ERP Human Capital Management (SAP ERP HCM): SAP Adhoc Query SQ01 SQ02 SQ03 Report Assignment: A very very interesting area that is mostly ignored and has a great potential for interactive reporting. First Name and Last Name. Your report lists a lot of record and you want the user to have power to double click on any employee row and then open up the details in PA20. go to menu item ‘Goto -> Report Assignment’.

SAP ERP Human Capital Management (SAP ERP HCM): SAP Adhoc Query SQ01 SQ02 SQ03 Click on ‘Other report type’ and you will see the available options. And. and run the report. on next screen you will be asked to enter the TCODE. Save the program. double click on any person’s record and you will be brought to transaction PA20 with that person’s data populated on Generated by Jive on 2013-03-01+01:00 8 . Here are the actions that can be done when user double clicks the row: Select ‘Transaction’.

different name. 2008 11:16 PM Muhammad Harie Muhammad Amir Chow Muhammad Harie Muhammad Amir Chow in response to Generated by Jive on 2013-03-01+01:00 9 .. Then assign P0105-USRID or P0105-USRID_LONG to the custom field name that you created. Jul 8. Thanks and regards Oct 19. none of my ABAPers. are used to SAP Query. I managed to get some codings. You need to create a custom field. However. 2008 6:36 AM Percy Carbella Hi Shafiq. We would then want to make it appear in the same fashion as SYHR_A_P0105_AF_CELL. i still have one question: Do you know how to create parameter with multiple selection? Nov 27. You can also choose to go to PA30 so that user can change the data quickly. We have defined custom subtype in infotype communiction.SAP ERP Human Capital Management (SAP ERP HCM): SAP Adhoc Query SQ01 SQ02 SQ03 the screen. hence. Jul 7. Could you help ? Thanks . why?. Please see above in the blog on how to create a custom field. and you will need to put some code to pick the data from the IT0105 for your custom subtype. Other option is to put Communication Subtype on Selection Screen and select only the subtype in which you are interested. The other day I was using someone else's PC. I have discussed above that it may not give you all data and your reports may be wrong. Coding was done in Free Coding code section.. 3964 Views Jul 7. 2008 7:26 AM Shafiq Rehman Percy Carbella in response to Hi Percey. I don't know who turn to until I came across your blog. 2008 8:02 AM Yossi Bencuya Hi Thanks for the great explanation. Upon generating. very much like what you provided above. not even the senior ones. I would get error No code exists for additional field ZSYHR_A_P0105_AF_XXXX. Here's what I'm trying to achieve. 2008 6:26 PM Muhammad Harie Muhammad Amir Chow Shafiq Rehman in response to Hi again Shafiq. but I do not recommend this approach. Apparently. I can give you starting code tips: re_provide_from_last P0105 'CUST' PN-BEGDA PN-ENDDA. Your ABAPer can help you in that.

without the warning. I have followed your instructions for 'Report Assignment' and selected PA20 for my transaction. thats how I get it. It is also on my output. and the browser shown a time out error. but I cannot find anywhere else that addresses the SQ01 Report Assignment feature as clearly as this one. Finally I got the code working. And how can optimizer the custom fields. I added some. good day. You have to give the infotype number on PA20. how i can add additional structure. 2010 8:45 AM Community User Laurie Crow in response to At a previous company I worked at. One of my selection fields is the Material Number. Good work in this blog. I couldn't select the additional as selection. Jan 14. I had a question. this reports are of e-Recruiting (web). but it will put the pernr on PA20 for you. My Report Assignment to Tcode MM02 seems to only work if I have populated the Material Number field on the selection screen. 2009 8:20 PM Jeanette Fireman Hi Shafiq. Have I missed a step somewhere? Thanks for your help. Jeanette Nov 25. and the report is very slow to generate the information on screen. then it will not do it. 2009 10:49 AM Daniel Gaytan Rodriguez Hi. because. thanks a lot. Does any one know how this is configured? Generated by Jive on 2013-03-01+01:00 10 . When I run my query and double click on a person's record PA20 is launched but it is not populated with any data. Nov 24. Well if you hoping that it will open up an infotype. however. 2009 8:58 AM Shafiq Rehman Jeanette Fireman in response to It should open up PA20 with that pernr selected. Regards. Thank you. Any ideas ? Apr 23. The problem is now. just tested it today. Is there a way to get it to work even if I am not using the Material Number field on the selection screen? Or can you point me to another blog or forum where I can learn more? Mar 25. 2010 9:07 AM Laurie Crow I realize that this blog has an emphasis on HR Module and my question is NOT HR related. This is a very helpful blog. My query is all about the material master. the Infoset that was set up in Ad Hoc query had the facility to report by the org structure using the "Reporting set" .SAP ERP Human Capital Management (SAP ERP HCM): SAP Adhoc Query SQ01 SQ02 SQ03 Hi.

But I am facing a problem. I have created the Infoset and added some additional custom fields to it. May 9. 2010 12:59 PM raveesh saurabh Hi. Raveesh Generated by Jive on 2013-03-01+01:00 11 . I liked the blog a lot.SAP ERP Human Capital Management (SAP ERP HCM): SAP Adhoc Query SQ01 SQ02 SQ03 I know that I can go to settings and select by "Start by selction screen" But I want to be able to use the Reporting set function. But these additional custom fields are not available as selection criteria while creating the query. Can you please tell me how to use the custom fields as selection criteria? Thanks. Thanks for it.