Enterprise Resource Planning Blog Posts by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
peter_atkin
Active Contributor
36,652


This blog documents how you can use SAP Query (SQ01 and SQ02) to create infosets and queries using SAP standard program reports.

The following example shows how this can be done with standard report IW39  which uses program RIAUFK20 and structure RIHAUFK_LIST.

Enjoy..

PeteA

 


You can use standard SAP report programs in your SAP Queries. The following example shows how to can IW39 (RIAUFK20) with additional fields without the need for a developer key.

In the example below we will check if the equipment number on the order and notification are the same.




 

 

1. Create InfoSet via TCode SQ02:




This now gives the list of fields defined in structure RIHAUFK_LIST:



Click the  button to see the ABAP code which should look something like this:

 
report rsaqdvp_template.
*
*---------------------------------------------------------------------*
* declarations
* (insert your declarations in this section)
*---------------------------------------------------------------------*
data: rihaufk_list type rihaufk_list,
it_data type standard table of rihaufk_list.

field-symbols: <struc> type rihaufk_list.

tables: aufk.

data sel_tab type table of rihaufk_list with header line.

*-------------------------------------------------------------------*
* selection screen statements
*-------------------------------------------------------------------*
* (define your selection-screen here)
*select-options s_aufnr for aufk-aufnr.

* !! the following comment MUST NOT BE CHANGED !!
*<QUERY_HEAD>

*-------------------------------------------------------------------*
* read data into IT_DATA
*-------------------------------------------------------------------*
* (select your data here into internal table IT_DATA)
submit riaufk20 "with aufnr in s_aufnr
with dy_selm = 'D'
via selection-screen and return.

import sel_tab from memory id 'RIAUFK20'.

free memory id 'RIAUFK20'.
it_data[] = sel_tab[].

*------------------------------------------------------------*
* output of the data
* (this section can be left unchanged)
*------------------------------------------------------------*
loop at it_data assigning <struc>.
move-corresponding <struc> to rihaufk_list .
* !! the following comment MUST NOT BE CHANGED !!
*<QUERY_BODY>

 

In the above example we use the standard IW39 selection screen. However, you could define your own selection screen fields if required. This is done in the “selection screen statements” area. You would then need to pass these parameters to the RIAUFK20 program (and remove the “via selection-screen statement).

 

You can define additional fields, structures, etc for you report as follows:

 



 

Once the additional fields have been created you can see them in the Extras tab. You can then select the relevant field and click the  button to add ABAP code for the specific field:



Generate the infoset once you have finished.

 

2. Create SAP Query via TCode SQ01:


Assuming you want to enter your own selection–screen values, then create your Query as usual, but you do not need to specify any selection values as they are already defined in the InfoSet program code:



All other query functions are available e.g. local fields etc.

 

3. Test your SAP Query:


Execute the query and you should now see the results. The the example below we can see the two new fields we've added to the IW39 report (notification equipment and equipment mismatch flag):

5 Comments
Former Member
0 Kudos

Thanks Pete for reminding us all of this nice feature.

kaushal_sharma
Active Participant
0 Kudos
I can not see the attachment.
peter_atkin
Active Contributor
0 Kudos
Sorry guys, when the blog was trasferred to SAP's new site it looks like the attachments didnt come across.

I've now added the details in the body of the blog..

 
0 Kudos
Thank you peter.atkin
sallyxu-cn
Active Participant
0 Kudos
Hi Pete,

You said "remove the “via selection-screen statement"

Do you mean to remove the whole section? so there is no need to consider the scree selection?

 

I need it to combine an exisiting custom table to combine for more info in a query.

Pls advise if it is OK.

Sally

 
Labels in this area