cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP QUERY

Former Member
0 Kudos

PLS SEND ME SOME LINKS AND MATTER BOUT ABAP QUERY I M NEW TO IT ...........

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member189629
Active Contributor
0 Kudos

Bala,

Here is answer for ur question

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, ABAP/4 query is a tool provided by SAP for generating these kind of reports.

Type of Report Desired

Before starting to write an ABAP query, its advisable to decide the type of report that the user wants. ABAP query provides the following type of reports:

Basic List Simple report

Statistics Report containing statistical functions like Average &Percentage

Ranked List Report written for analytical purpose

In a nutshell, an ABAP/4 query can be designed in four steps

Creation of a user group

Creation of functional area

Assignment of user group to functional area

Creation of the query based on functional area

The various objects that form an ABAP query can be created in the following 2 ways:

Tools => ABAP/4 Workbench => Utilities => ABAP/4 Query

OR

By executing the transaction codes mentioned below

SQ01 ABAP/4 Query

SQ02 Functional Area

SQ03 User group

Step I Create Functional Area

In the functional area section, the user indicates from which part of the SAP database the data is going to be retrieved and how the data is to be retrieved by the query. One functional area can be assigned to many user groups. A functional area can be created with or without a logical database.

To create a functional area with a logical database, one has to mention the name of the database and then select the fields from the tables that form the logical database.

To create the functional area with a logical database

Tools => ABAP/4 Workbench => Utilities => ABAP/4 query => Functional Areas.

Give the functional area name and click on Create button

In the next screen give a brief description of the functional area

Specify the name of the logical database, for e.g. Database FI, Application S. This will be the definition for the flight database

Click on the button Functional Group present on the application toolbar, in order to create the functional group for the required fields from the logical database tables

In the functional group box mention the number of the functional group and the description for the functional group

The tables from the logical database are shown in Tables Of Logical Database/Joins while the fields are displayed in the Fields Box

Double click on the table name in order to change the list

Every field that has to be selected in the query should be assigned a functional group number against it

Sometimes the list of fields in the Fields box will not be completely visible. To have a wider display of the list place the cursor in the fields box area and click on Settings => Full Screen from the SAP menu bar

To see the fields from different tables select the table and double click on it.

Once the required fields are selected, save the functional Area by clicking on the SAVE icon on the toolbar, and then Generate the Functional Area by clicking the Generate icon on the toolbar

To add user defined fields to the abap query use the menu bar option GOTO => Additional Field

Give the field name and the table name from the logical database to which the field needs to be included. Click the ENTER button.

On the next screen give the Sequence, description, title and the technical attributes for the field (field type, length). Here you can also specify the formula for the field. Click on the SAVE button to register the data to the database.

Remember that the sequence of the field matters – if the second field uses the first field in its code then the second field should have a higher sequence than the first. Tables can also be included – to do this use the menu option Goto => Additional Tables

You can include your own selection criteria and parameters to control the data to be selected from the database. For these additions to get activated, code needs to be written for taking care of the additional fields.

To display something before the execution of the actual query, go to the start of selection event via the menu path Goto => Code => Start-of-selection.

To display something just before or after the output of the query, go to the end of selection event via the menu path Goto => Code => End-of-selection.

To display something at the beginning of the page, go to the top of page event via the menu path Goto => Code => Top-of-page.

After finishing everything save and generate the functional area and click on the BACK icon to come out.

To create a functional area without a logical database

One of the following can be selected

Based on a single table

Using an ABAP/4 program

Using Table Joins

Using Sequential Dataset

The steps to be followed for creating the functional area are as follows

Tools => ABAP/4 Workbench => Utilities => ABAP/4 query => Functional Areas.

Give the functional area name and click on Create button

In the next screen give a brief description of the functional area

In the Without a logical database area give the base table on which to form the ABAP query

To form the query with two or three tables, we need to create a join. For this check the Table Join Check Box and click on the Table Join button.

NOTE: The tables to be used in the join should have at least one field in common i.e. it should have the same name, domain or data element.

Mention the tables that you want to include in the join condition in the Joined Tables area and press ENTER.

A checkbox will appear against the table names on the left side, and three radio buttons will appear against the tables on the right side specifying the join type.

Base table name remains grayed out. Select the two tables to be involved in the join by clicking the check boxes against them. Use menu path Edit => Join => Define condition to create the join. A mapping between the tables will be displayed on the right hand side. Click on the button provided (with + and down arrow symbol) to specify the join.

Click YES on the Proposal Requested message that gets displayed.

If the join tables have a foreign key relationship then the common fields in the tables will be marked with 00 to indicate that the join has been created. User can create the join by specifying 00, 01 etc. against the fields that qualify for the join.

Complete the join condition by adding more tables if necessary.

Remaining concepts for creating the functional area without a logical database are same as the concepts for creating the functional area with a logical database.

After finishing everything save and generate the functional area and click on the BACK icon to come out.

STEP II Creating User Group

Here you specify the users who should be authorized to run the query. A user group is always associated with a Functional Area.

· Go to the menu path Environment => User Group.</u> Give a user group name in the screen that comes next.

· Specify the sap logins of the users whom you want to authorize for using the functional area and click on the Create button.

· Use the menu path Assign Functional Area to assign the functional area to the user group.· Save the user group and back out of the screen by clicking the Back button.

Note: One user group can be assigned to any number of functional areas with logical database or without logical database.

The final step is to create the actual query.

STEP III Creating The Query

· In order to create the query use the menu path Environment => Queries

· Give a name to the query and click on the Create button

· Give the description of the query in the next screen. Specify the output length and select the processing option from the Further Processing Options box. The data can be displayed in various formats such as table, download to a file, and display in Word etc.

· Click on the Next screen icon. Select the functional group screen. All the functional groups created in the functional area are displayed. Select the groups that you desire – fields from only these groups will be displayed in the output. Click on the respective check boxes and click on the Next Screen icon.

· The Select Field screen gets displayed. Select all the fields from the user group that you need to display on the output of the query. If required, specify the short names for the fields using the menu path Edit => Short Names => Switch On/Off or you can also change the selection text contains in the order you want to appear on the selection screen. You can also maintain column headers for the fields by using the menu path Edit => Column Header => Maintain.

· Click on the Next Screen icon to get the Selections Screen. Here you can check against the fields that you require to be shown on the selection screen.

· Now we need to specify the output type for the query as Basic List, Statistics or Ranked List. Choose the option Basic List.

· On the Basic List line structure screen the following things can be done

o Specify the report layout in detail – lines on which the fields will appear.

o Order in which the fields will appear in the output

o Sort order for the fields – this is optional.

o For the numeric fields you can check against the fields for which you require totals in the output.

o Beautify the output according to the options provided.

· Click on the next screen icon, to specify the control levels as mentioned below

o Specify the sort order. The default sort order is ascending and can be changed to descending if required.

o Totals for each field selected for sorting can be displayed

o To display the output of a field in a box click on the check box against box. To display a line after the output of a field, click on the check box against BlnkLn

o To display the output of a field on a new page click on the check box against New Page

· Click on the next screen icon to get the List Line options Screen. Here you can specify the background color for displaying the output.

· Click on the next screen icon to get the Field Output Option screen. In this you can specify the following:

o Change the output length or the display positions of the fields

o Specify the display position of the unit for quantity or currency fields. Click left radio button to display it before the figure, middle radio button to display it after the figure while last radio button to hide the unit altogether.

o Specify color for the column of every field under the Format option.

o Specify the label against the output of sort fields.

· Click on the Next screen option to go to the Basic List Header screen. Here you can specify

o Give page header and page footer for the output

o Include user name and date by specifying &N and &D respectively.

After providing all the above options you can save the query and execute it by clicking the Execute button twice.

ABAP/4 Query Hints and Tips

The purpose of the SAP Query are for users with no programming knowledge. It is also used by abapers to create simple reports for the users.

You can easily create three types of query reports :

1. Basic lists (details list)

2. Statistics (counting etc.)

3. Ranked lists

When you start using version 4.6x, you can see a Quick Viewer button in the Query Main screen. It is suppose to be much simplier that the original Query but it is up to you to decide whether is it true.

To create a report with the QuickViewer, all you need to to do is enter texts such as titles, and select the fields and options that define the structure of the report. You can assign a specific sequence to the fields by numbering them.

If necessary, you can edit the lists either through drag and drop in WYSIWYG mode, or by using the functions in the available toolbars. Data can also be send to external programs such as MS Excel or MS Word for further processing.

The only problem with QuickViewer is that it cannot read cluster table.

Check this links

http://goldenink.com/abap/sap_query.html

http://www.sap-img.com/basis/transport-of-abap-query.htm

Check thwese links. Very helpful,

http://www.thespot4sap.com/Articles/SAP_ABAP_Queries_Create_The_Query.asp

http://www.sap-basis-abap.com/sapquery.htm

My own blog:

http://allaboutsap.blogspot.com/2007/09/sap-query-step-by-step.html

Reward if helpful,

Karthik