Ab 4 Query
Ab 4 Query
BAP/4 Query is powerful tool to generate simple reports without the need for any coding. This is a very handy tool for the consultants functional who dont have any prior programming experience. This document is not meant to teach ABAP/4 Query completely but is meant to give a lead to learn it. Summary : In order to create an ABAP/4 Query, one has to do the following: 1. Create an User GroupCreate and Functional 2. Area. the functional Area, one has to mention how the data in the query In coming from (i.e. through a logical database or from an individual is table a program or joins etc.). Within the functional area you also have using the functional groups categorizing fields from the tables into different 3. groups. the User Group to the Functional Assign AreaCreate the Query based on the functional area 4. created The above four steps have to be done to create an ABAP/4 Query. Creation of Query is a simple process. ABAP/4 Query provides for three different kinds of reports: BASIC LIST - Simple reports STATISTICS - Reports with statistical functions such Percentages Averages, RANKED LIST - for analytical reports Within a query, you can define one basic list, up to 9 statistics and up to 9anked lists. These different list types may be combined in any permutation r you You can also extend existing queries by adding more sub-lists. Unless like. you specified otherwise, you see the basic list first, followed by the have statistics and finally the ranked lists when you execute a query. One has to be clear as to what kind of report he / she wants and select fields in the functional area accordingly and also the kind of report. One the can generate graphical reports in ABAP/4 also Query. There are different paths to create the functional area, user group and queries. You can create any of these by Tools ABAP/4 choosing Workbench Utilities ABAP/4 or executing the transaction codes for each of Query them: SQ01 for Query for Functional SQ02 Area SQ03 for User Group
ABAP/4 QUERY
The first step in the process of creating a ABAP/4 Query is to create an Functional Area. Functional Area provides special views of logical databases. They determine which fields of a logical database can be evaluated in Functional areas are assigned to user queries. groups. You can assign one functional area to many user groups. The functional area could be created with a logical database or without a logical database. You can opt any one of them for creating a query. In the functionalspecify how and where from the data in the query is going to area you retrieve from. For creating a functional area with a logical database you have to mention logical database name and then you can select the fields from the tables in the the logical database for your query. You can create a Functional Area without a logical database too. You create a functional area without a logical database with the following choices: a. You can create a functional area with a single table You create a functional area using a ABAP/4 b. program can create a functional area using Table c. You Joins You can also use Sequential d. Dataset.
Part I deals with the steps involved in the creation of Functional Area. Functional Area can be created with or without a Logical Database. First we will go through the procedure of creating the Function Area with a ogical L Database. CREATING AN FUNCTIONAL AREA ( with a Logical Database) The first step in creation of a ABAP/4 Query is to create an Functional Area. To create an Functional Area goto Tools ABAP/4 Workbench Utilities ABAP/4 Query Functional Areas Give a Functional Area and Click on Creat button. name e
A functional area is the definition of the fields in the query. In the next screen give description to the functional . A functional a can be created with a logical database or without a using a logical area area database. In the Functional Area With Logical database specify the database name . (e.g. Database : F1 Application : S. This is the box logical SAP defined flight database). Click on Functional Group button on the application toolbar to create functional group for the fields from the the tables in the logical database. Window : Change Functional Area <Functional Area name> In this screen in the Functional Groups mention the functional box Group number and ( e.g. 01 Flight, 02 Demo, 03 Bookings etc.). description Tables of logical database / Joins show the tables from the logical database. The fields from the tables are displayed in the Fields box. To change the double click on the table . list name In the Fields box against the specify the functional group in fields which you would like to include the number field. If the list of fields in the fields box is not completely displayed then to the entire display list of fields or to have broader display of place the cursor in the box area and click fields Settings Full from the menu on Screen bar. Do the above step for the fields from each table. To get the list of the fields other tables select the table in the Tables from logical database / from Joins double click. box and Save the Functional Area and Generate . Click on the SAVE icon and then it Generat icon on the toolbar to save and generate the functional on e area. DONT FORGET TO GENERATE THE FUNCTIONAL AREA . You can add additional fields (user defined fields), additional tables and them to any table in the logical database. These additional fields assign be . canseen from the fields list of the assigned table
To add additional fields from the menu bar GOTO choose Additional Fiel d In the next screen that you get, give the field name and the table name fromlogical database in which this field has to the include. Click on the enter icon. In the next screen specify the Sequence, Description, Heading, technical for the fields like field type, length etc. and then you can attributes also specify any formula for the field. Save the field details. You can to the same for any more fields, which you would like to include in the query. If you create two additional fields, and the second field uses the first field in code then the sequence of the second field should be higher than its sequence of the the first. You can also include tables. GOTO Additional Choose Tables You can also include your own selection criteria and parameters executing the query other than default selection screen and parameters If you include your own selection criteria and parameters then you have to write a code for them to take any effect. If you define Parameters as part of your selection screen you must also evaluate them in functional area code otherwise they will have no effect. Note : Please the online documentation for more information on this. You can also write Code for the that is to be executed at the time query of executing the query. GOTO Choose Code What code you want to write is up to you and the output of query you design. The point at which an ABAP/4 Query reads an additional table or performs on additional fields depends on logical database table since calculations associated ABAP/4 code becomes part of the GET event processing of the the table .
for
If you want to display something before the execution of the query / ccessing the logical database, you write the code for that a in SELECTION ( Goto Code START-OF). SELECTION If you want display something before or after the output of the query, you the code for that write END-OFin SELECTION. If you want to display something at beginning of the page then you write the for that code TOP-OF-PAGE . in Save and the functional generate Area. Click on Back icon to come out.
START-OF-
Next step is to create a User Group and assign it to the functional area. Now go to PART II if you are creating a Query with Logical Database
CREATING AN FUNCTIONAL AREA ( without a Logical Database) We will now see how to create a Functional Area without a Logical database. We can create a functional area without a logical database using a program or a sequential set or table (Direct Read) or using table joins. The following steps show you how create the FA using table joins. In order to create a FA using a table join, we have to keep in mind that the tables that used have at least one field in common (i.e. the field name should be of are the name, domain / data element). To create an functional area same withoutdatabase (using table join) do the following logical a : To create an Functional Area Tools ABAP/4 Workbench choose Utilities ABAP/4 Query Functional Areas Give an Functional Area name Click on Creat button. and e
A functional area is the definition of the fields in the query. In the next screen give description to the functional . A functional a can be created with a logical database or without a using a logical area area database. In the Functional Area Without a Logical database give the base name. area table Check the table join check and click on table join . box the button In the Joined Tables area give table which you want to include in the join condition and press names the Enter key . the After you press the enter key a check box will appear against the table names (left side), three radio buttons will appear against the tables (right side) specifying the join . type The base table name will be grayed out. Now select two tables by selecting the check boxes for defining the join condition. To define the join conditions EDIT Join Define . choose condition You will see a mapping between the tables on the right hand side under theoin J Conditions Click on the button (with + and down arrow area. symbol) specify the join between the tables. You will get a Proposals . Click on Yes. message Requested In the next screen that you get, if there is a foreign key relationship between the tables then you will see 00 = 00 (signifying the join) defined displayed common fields of the tables else you can specify the join against the yourself in 00 or 01 etc. In the boxes against the by typing fields. Click on Back arrow button to come back and continue defining conditions for the more tables if required.
to
Now proceed with PART II if you are creating a Query without a Logical Database
Click on Functional Group button on the application toolbar to create functional group for the fields from the the tables in the logical database. Window : Change Functional Area <Functional Area name> In this screen in the Functional Groups mention the functional number and ( eg. 01 Flight, 02 Demo, 03 Bookings etc.). box Group description Tables of logical database / Joins show the tables from the logical The fields from the tables are displayed in the Fields database. box. To change the list double click on the table name. In the Fields box against the fields specify the functional group numberyou would like to include the which field. If the list of fields in the fields box is not completely displayed then to display list of fields or to have broader display of place the cursor in the entire the box area and click fields Settings Full from the menu on Screen bar. Do the above step for the fields from each . To get the list of table from other tables select the table in the Tables from the fields logical Joins box database / and double click. Save the Functional Area and Generate . Click on the SAVE icon and it then on Generate icon on the toolbar to save and generate the functional area . ONT FORGET TO GENERATE THE FUNCTIONAL AREA D . You can add additional fields (user defined fields), additional tables and them to any table in the logical database. These additional fields assign canseen from the fields list of the assigned be table. To add additional fields from the menu bar GOTO choose Additional Fiel d In the next screen that you get, give the field name and the table name fromlogical database in which this field has to the include.
in
Click on the enter icon. In the next screen specify the Sequence, Description, Heading, technical for the fields like field type, length etc. and then you can attributes also specify any formula for the field. Save the field details. You can do the same for any more fields, which you would like to include in the query. If you create two additional fields, and the second field uses the first field its in code then the sequence of the second field should be higher than the sequence of the first. You can also include tables. GOTO Additional Choose Tables You can also include your own selection criteria and executing the query other than default selection screen and parameters parameters If you include your own selection criteria and parameters then you have to write a code for them to take any effect. If you define Parameters as part of your selection screen you must also evaluate them in functional area code otherwise they will have no effect. Note: Please the online documentation for more information on this. You can also write Code for the that is to be executed at the time query of executing the query. GOTO Choose Code What code you want to write is up to you and the output of query you design. The point at which an ABAP/4 Query reads an additional table or calculations performs on additional fields depends on logical database table since the associated ABAP/4 code becomes part of the GET event processing of the table . If you want to display something before the execution of the query / ccessing the logical database, you write the code for that a SELECTION ( Goto Code START-OF). in SELECTION
for
START-OF-
If you want display something before or after the output of the query, you the code for that write END-OF. in SELECTION If you want to display something at beginning of the page then you write the for that code TOP-OF-PAGE . in Save and generate the functional . Area Click on Back icon to come out. You can also fields allows functional area, without field. To define a choose screen Fiel d . When making needed: Short name define local for the functional area. The definition of fields you to generate newlocal information from the fields in a having to include an additional local field, Edit Create Local field on the Selec t
Field name you enter a text which describes the field contents. On Here, all subsequent screens, the local field is identified via this name. Heade r This is used when calculating column headers. Please note that headers correspond to the field output length and that they may should over two extend lines. Functional group The local field is included in the functional group. Attribute s When defining the technical attributes of the local field, you can use any the of following options: Refer to an existing field (i.e. use it as a reference field) The advantage of this option is that the local field can accept same the values as the reference field. If the reference field is a currency amount field or a quantity field, the local field inherits the currency or unit assignment of the reference field. In our example, the Distanc with the short DISTANC field e name E
is a
quantity field, since it contains a distance specification and a easurement unit. Therefore, the local m SPEED is also field a quantity field and has the same measurement unit as the DISTANC . field E Define the field as a text, calculation, date or time field. With text and calculation fields, you must specify the field size (number of characters/digits and number of decimal places). Define the field as a symbol or icon With these fields, the contents are interpreted as a symbol or and icon output is consequently in graphical format. You could do this wanted to emphasize particular values or lines in the if you list. Calculation formula You can determine the value of a field in either of the ways: following 1. By using a calculation formula. In the most simple case, a calculation formula consists of a single formula. All formulae conform to the usual mathematical rules and contain operands and operators. Valid operands include the short names of fields as well as numeric constants (e.g. 10 or 1.5) and character strings ABC). (e.g. Certain special fields are also available. These %NAME(the name of the user processing the are: query) %DATE(the current date when the query is being processed) current time when the query is being %TIME(the processed). If an operand is a text field, you can use the textfiel notation to access part of this field. d n: n is the position of m the first Here, character mis the position of the last and character. If you are accessing the 2nd character to the 5th character of field, the notation would the tex 2:5. be t If an operand is a date or time field, you can use the following to access the individual components of this notation date [YEAR] field: field year date [ MONT ] month field H date [DAY] day field time [ HOU ] hours field time [ R MINUT ] field time [ E SECON minutes ] field D seconds Created / Compiled By : P. M. V. Subba Rao 10
Valid operators include the basic arithmetic operations plus DIV MOD. DIV is the operator for whole number division and and MOD is the operator for the remainder in whole number division. You can use parentheses in the usual way. Next you create a user group. In the user group you specify the users who are authorised to use the queries under that user group. You associate a user group with Functional Areas
CREATING A QUERY
To create a Query Environment choose Queries Give a Query and Click on Creat Button. name e Select functional for the user group by double clicking on it or the by clicking on area enter the icon. Please note that a user group can be assigned to any number of functional areas, which could include functional with logical database and without logical database. In the next screen give description to the , specify output length a if required) and select query the processing from the further the Processing Options box. You can display the option a table, download it to a data as file, display in a word processor etc. Click on the Next Screen icon on the toolbar. ( ) SELECT FUNCTIONAL GROUP screen . The list of Functional Groups that were defined in the functional area is displayed. Select the ones required. The fields from this groups will only be displayed in the next screen. Click on the check boxes to select the functional groups. Click on the Next Screen icon on the toolbar. ( ) SELECT FIELD Screen . The fields from each functional groups is displayed. Select the fields that you want to include in your query report. Here in this screen, you can do the following if required : You can specify Short names for the Choose Edit Short Names Switch On/ fields. Off You can also change the selection text contents to the way you want it to appear in the selection screen.
You can also create local fields that you would like to include in this query only. You have to give a short name for the local fields that create you . hoose Edit C local field Create You can include fields such as user name, system date, time etc. You can also maintain column headers for the fields. Select the field then choose Edit Column Header and Maintain Click on the Next Screen icon on the toolbar. ( ) SELECTIONS SCREEN . In this screen click on check boxes against the fields . Now you have to select the Query Report ( Basic List, Statistics or Ranked List ) thattype you want to generate. Click on Basic . List BASIC LIST LINE STRUCTURE Screen. In this screen you need to do following : the Specify the lines on which the fields have to appear on the report layout Specify the order in which each field has to appear the sort order ( if Specify needed )numeric fields in the list, check the check box against For the thefields if you want to have the totals of the field in the Foroutput. looking output you can also check the Basic list with better box and Columns separated by | check boxes on the top of the screen Click on the Next Screen icon on the toolbar. ( ) CONTROL LEVELS Screen. In this screen, you can do the following ( if required ) : Specify the sort order as descending. Default is ascending. Click on Text check box if you want to have a Sub-heading for theselection for the fields Total for each field that is selected for sorting click on the Box check box then the output will be in box If you forthe fields against which the box check box is checked. If you click on the BlnkLn check box then there will be line after theoutput of fields against which the BlnkLn check box is checked
Click on New Page to get the output for the fields against which Newage check box is checked on a new New P Page Click on the Next Screen icon on the toolbar. ( ) LIST LINE OUTPUT OPTIONS Screen. In this screen you can specify the background color for the display of the output by selecting the color of the Header line in the output. Click on the Next Screen icon on the toolbar. ( ) FIELD OUTPUT OPTION Screen. Here you can do the following if required : change the output length of the field (s), specify new position of display for the fields, have any Quantity fields or currency fields then you can if you the specifyposition on display of the unit ( Left radio button Unit appearsthe figure, Middle Radio button Unit appears after the before figure and Last Radio button Unit does not appear). Under Format you can specify the color of the column for each field. want to have a label against the output of sort fields click If you on template check box and in the next screen that you get give the label name. Click on the Next ( ) Screen icon on the toolbar.
BASIC LIST HEADER . This screen gives you the layout display of selections that you have made for the query. Here you the can Give a Page Header and Pager Footer to Query the field Labels. Place the cursor on the field and Change choose Column Header .Change the label and click Enter Maintain the icon Page Header and Page Footer section, you can include or In the delete lines. Edit Line Insert / Choose Delete. You can include the user name and date by specifying &N and &D respectively . Save the Query now. Click on the Execut e button twic e to run the Query.
Edi t
NOTE : YOU CAN DO THE ABOVE PROCESS FOR CREATING QUERIES WITH RANKED LISTS AND STATISTICS LIST. THE PROCESS IS THE SAME EXCEPT THAT WHEN DEFINING THE QUERY YOU CHOOSE RANKED EITHER LIST OR STATISTICS LIST IN PLACE OF BASIC LIST.
RANKED LISTS
Ranked lists are special types of statistics. Here, numeric values are summed for key terms and displayed in a table. However, sorting is always by also a umeric value known as the ranked list criterion. Additionally, only a n certain of items are output. This makes ranked lists suitable for number analyzing such as: "What are the 10 flight connections with the highest questions sales?" First, you must assign a title to the ranked list. This is necessary, since query one can contain several ranked lists. You can then specify how many entries (i.e. output lines) you want the ranked list to have. The proposed value here is always 10. Subsequently, you must define which fields are to be output and in what order. this, enter sequence numbers in the first column. You select one of To do fields Fre seats these as the ranked list criterion. In our example, it is the field e . The ranked list criterion is the sort criterion of the ranked list. The default sort sequence for the sort criterion is descending order, but ascending order is sometimes necessary. This would apply, for example, to vendor sales figures are stored as negative amounts. In such cases, you can specify which ascending the ranked list criterion by selecting the order for As . column c You can also specify an output length and a rounding factor. As with statistics, fields and quantity fields require you to specify a reference currency currency a orreference unit which is used to convert all the amounts. Conversion errors have the same procedure as also statistics As with statistic, you can access the screens for maintaining the header and setting graphics parameters by following the normal sequence of query screens. The same rules apply for both these screens. If you want to define another ranked list, you choose Next ranked the list function.
SELECTOPTIONS:... DATA: ... DATA: BEGIN OF itab OCCURS xxx. If necessary, define an INCLUDE STRUCTURE tab. internal table itab with the DATA: END OF itab. structure tab to hold the records to be evaluated. * < Query_head> This comment must always appear after your data declarations. * Code to define the table itab, if such a table is used.
Beginning of a loop to retrieve each record and place it in the field string tab SELECT, DO, LOOP , ... * If necessary, code to format data * < Query_body> This comment must always be the last 'statement in the loop. *The data must now be in the field string tab. End of loop to retrieve each record
The two entries i.e the two comment lines *<QUERY_HEAD> and *<QUERY_BODY> in the above example, are fixed should be there in your report if you want to build a ABAP Query using and ABAP/4 ABAP program. They start immediately after the character "<", but the system does not distinguish between upper and lower case.
Depending on what the user values set in ACTVT field the user can manipulate / create the queries. The default values of authorizations for the authorization object are : S_QUERY_ALL : Change, Maintain and S_QUERY_UPD Translate : Change and Translate When you have chosen a user group, you see the names and titles of any queries already defined there in the lower part of the screen. You can display a list of queries for your current user group. To do this, proceed as follows: Choose Environmen Directorie Queries/user , or t s group Place the cursor on the input field for the query name and display a of possible entries by pressing F4 function key or by clicking the list arrow the on field. If differences occur between queries and functional areas, you should terminate the processing and perform a comparison between the query and the functional area. To perform a comparison, Quer Other functions select y Compare You then see a list of all the fields defined differently, together with about how the information field definition has changed and where in the query the field is used. If you wish, you can carry out an automatic comparison for individual fields . If you want to execute the query as a background job, choose backgroun . d To do this you would require variant.
S_QUERY
Exec. in