SAP ABAP Query Creation Tutorial

  • View

  • Download

Embed Size (px)


SAP ABAP Query Creation Tutorial


ABAP Query Creation

04/30/2006Development TeamPage 1

ABAP QueryCreation


04/30/2006Development TeamPage 2ABAP QueryThe application SAP Query is used to create lists not already contained in standard SAP. It has been designed for users with little or no knowledge of the SAP programming language ABAP.

ABAP Queries should be created for enterprise reports. Single user or simple business unit reports should be created by the end users using SAP Quick Viewer.

04/30/2006Development TeamPage 3ABAP Query ComponentsAn ABAP Query is comprised of 3 components:

InfoSets -InfoSets determine to which tables, or field within a table, a query can refer. InfoSets are usually based on table joins or logical databases.These should be created with sharability in mind. User Groups -The user group allows you to to specify the users who are authorized to run and/or create/change queries under that user group. Queries -Formatting the data identified in the InfoSet to create the desired report.

04/30/2006Development TeamPage 4ABAP query components can be created in either the standard area or global area:Standard Area - Allows for creation of client-dependent objects that have to be exported to a transport and then imported into each required client.Global Area - Allows for creation of client-independent objects that get transported via the normal transport process. A transport is required on save of an object.

NOTE: Global Area will be the Client standard since query objects need to be client-independent and should be created as permanent efficient objects. Standard vs. Global Areas

04/30/2006Development TeamPage 5

To ensure you are in the Global Area, each of the query transaction codes will show the following at the top of the screen:

Query areaGlobal Area (Cross-client)

If it does not, you are in the Standard Area. To switch to the Global Area, select from any of the query transactions:

Environment > Query areas

A pop-up box will be displayed. Choose Global Area (Cross-client).Standard vs. Global Areas

04/30/2006Development TeamPage 6

Menu Path: Tools > ABAP Workbench > Utilities > SAP Query > InfoSetsTransaction: SQ02InfoSet - CreationEnter your InfoSet name and hit the button.

04/30/2006Development TeamPage 7

Logical databases have already been set up and should be used if they contain the appropriate data. The table joins have already been done.Enter your description and your data source.InfoSet - Data Source - Logical Database

04/30/2006Development TeamPage 8

To find the available databases, select the possible entries on the Logical database field and enter a required table name.Possible entries will be displayed and select one.InfoSet - Data Source - Logical Database

Select the nodes (tables of the logical database) you require.

04/30/2006Development TeamPage 9

To display the structure of the logical database, select the magnifying glass next to Logical database field on the InfoSet: Title and Database screen.InfoSet - Data Source - Logical Database

04/30/2006Development TeamPage 10

A table join data source should be used if no logical database is available.Enter your description and your data source.InfoSet - Data Source - Table Join

04/30/2006Development TeamPage 11

InfoSet - Data Source - Table JoinSelect to insert another table. A pop-up will appear, enter the table nameThe system will automatically propose joins.

Press the Green arrow to back out. The pop-up on the right will appear, select include key fields.

04/30/2006Development TeamPage 12

It is possible to create an InfoSet using data retrieval by either an internal or external program. A data structure is required that may need to be created custom if an existing structure does not suffice.

An internal program allows you to create the code within the InfoSet to populate the specified structure.

Both of these methods have not been used by Client and would require further investigation and standardization.InfoSet - Data Source Data Retrieval Program

04/30/2006Development TeamPage 13

Additional tables, structures, and fields allow you to enhance the selected data source. They have two common features:

The point (event) at which SAP Query reads an additional table or performs a calculation on an additional field depends on the logical database table, since the associated ABAP code becomes part of the GET event processing that table.

Any query for the InfoSet can address both additional fields and additional table fields, provided they are assigned to a field group of that InfoSet.InfoSet Additional Tables, Structures, and Fields

04/30/2006Development TeamPage 14

InfoSet functionality to generate further code makes additional tables, structures, fields, parameters and selection criteria more flexible. These options generate ABAP code for all queries of an InfoSet, but this is transparent to the end-user. The coding areas are as follows:

DATA for global data declarations.INITIALIZATION for initializing data fields.AT-SELECTION for selection screen processing.START-OF-SELECTION which precedes the first database access.GET/GET Late for these events for a logical database table.Record Processing for processing individual records for non-logical databases.Free Coding for forms routines at end of the program.END-OF-SELECTION either before or after output of the list.TOP-OF-PAGE for just before the instructions for output of the page header.InfoSet - Further Code

04/30/2006Development TeamPage 15

When using a logical database, the additional tables feature can be used to join tables not in the logical database, but only at an existing table level. Selects can also be done in the coding section and data moved to additional fields or additional structures.

When using table joins, a limitation is that only one left outer join can be used per InfoSet. Again the coding section can be used to select other tables, but this method can only be used to add additional fields and not additional records to the relational structure of the join statement.

InfoSet - Further Data Information

04/30/2006Development TeamPage 16

InfoSet - Selecting Fields for Field GroupsThe left part of the screen shows all fields available in the database tables. The right side shows what fields have been selected for this InfoSet. Move all fields required for the query into the proper field group.

Press to generate and save the InfoSet.

04/30/2006Development TeamPage 17

Menu Path: Tools > ABAP Workbench > Utilities > SAP Query > User GroupsTransaction: SQ03User Group - Creation

Enter your UserGroup name and hit the button.

Enter a descriptionand hit save.

You will be promptedfor a transport.

04/30/2006Development TeamPage 18

Press the to assign users to your User Group. Select the checkbox next to the user name if you want them to create or change queries. Press save and green arrow back.

User Group Assign Users

04/30/2006Development TeamPage 19

Press the next to the InfoSet field on the main screen. Be sure your InfoSet name is in the field.User Group Assign InfoSets

Select your User Group name and press save. Your User Group is now assigned to your InfoSet.

04/30/2006Development TeamPage 20

Menu Path: Tools > ABAP Workbench > Utilities > SAP Query > QueriesTransaction: SQ01Query - CreationSelect your user group.

Enter your Query name and hit the button.

Select an InfoSet.

Enter a descriptionand hit save.

You will be promptedfor a transport.

04/30/2006Development TeamPage 21

Query - CreationUse Notes to document the Remedy ticket number, date of creation, and brief description.

Enter CUS&STANDARD as the standard variant to be used by this query. The naming convention of CUS& allows this to be transported.

Enter your Query description, list and output format. Hit to continue.

04/30/2006Development TeamPage 22

Query Selecting FieldsSelect the field groups you want to use in this Query. Select the fields and selection criteria.

04/30/2006Development TeamPage 23

Query Graphical Query PainterSelect a report type and the Graphical Query Painter:Basic List Simple ReportsStatistics Reports with statistical functions such Avg, %.Ranked List Analytical Reports

04/30/2006Development TeamPage 24

Query Graphical Query Painter

04/30/2006Development TeamPage 25

Query Graphical Query PainterSelect or double-click the fields from the left to move toyour report.Press save and test to execute your report.

04/30/2006Development TeamPage 26

Query Report AssignmentReport Assignment allows you to drill into another report or transaction.

Navigate to Query > Change > Goto > Report Assignment. Click on Insert Row.

To select an ABAP Query, check Global area, enter User Group, Query, and Variant.

04/30/2006Development TeamPage 27

Query Report AssignmentTo drill into another transaction:

Click on Other report type > Select TR.

Enter a transaction code.To transport a report assignment, click on the transport buttonand include in your query transport.

04/30/2006Development TeamPage 28

Query Transaction Code CreationTo create a transaction code for your query use transact