Transcript
Page 1: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 1

ABAP QueryCreation

Page 2: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 2

ABAP Query

• The 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.

Page 3: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 3

ABAP Query Components

An 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.

Page 4: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 4

ABAP 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

Page 5: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 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 area Global 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

Page 6: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 6

Menu Path: Tools > ABAP Workbench > Utilities > SAP Query > InfoSets

Transaction: SQ02

InfoSet - Creation

Enter your InfoSet name and hit the

button.

Page 7: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 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

Page 8: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 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.

Page 9: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 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

Page 10: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 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

Page 11: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 11

InfoSet - Data Source - Table Join

• Select to insert another table. • A pop-up will appear, enter the table name• The system will automatically propose joins.

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

Page 12: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 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

Page 13: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 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

Page 14: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 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

Page 15: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 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

Page 16: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 16

InfoSet - Selecting Fields for Field Groups

• The 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.

Page 17: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 17

Menu Path: Tools > ABAP Workbench > Utilities > SAP Query > User Groups

Transaction: SQ03

User Group - Creation

Enter your UserGroup name and hit the button.

Enter a descriptionand hit save.

You will be promptedfor a transport.

Page 18: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 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

Page 19: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 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.

Page 20: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 20

Menu Path: Tools > ABAP Workbench > Utilities > SAP Query > Queries

Transaction: SQ01

Query - Creation

Select 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.

Page 21: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 21

Query - Creation

Use 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.

Page 22: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 22

Query – Selecting Fields

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

Page 23: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 23

Query – Graphical Query PainterSelect a report type and the Graphical Query Painter:

• Basic List – Simple Reports• Statistics – Reports with statistical functions such Avg, %.• Ranked List – Analytical Reports

Page 24: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 24

Query – Graphical Query Painter

Page 25: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 25

Query – Graphical Query Painter

• Select or double-click the fields from the left to move toyour report.

• Press save and test to execute your report.

Page 26: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 26

Query – Report Assignment

Report 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.

Page 27: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 27

Query – Report Assignment

To 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.

Page 28: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 28

Query – Transaction Code Creation

To create a transaction code for your query use transaction SE93:

• Enter a transaction code. Typically it would be named with Z plus the domain name plus “_” plus a short name.

• Enter a short text which would typically be the Query Title with (AQ) behind it for clarification.

• Select Transaction with paramters (parameter transaction).

Page 29: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 29

Query – Transaction Code Creation

To create a transaction code for your query use transaction SE93:• Enter START_REPORT as the

Transaction and check the Skip initial screen and Inherit GUI attributes boxes.

• Enter the above screen fields and values where EXTDREPORT is the Query name, VARIANT is the starting variant name (optional), and REPORT is the user group (1st twelve characters) plus “G” for global area.

Page 30: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 30

ABAP Query

Standards

Page 31: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 31

Standards - General

• Any AD-HOC reporting by the end user or domain teams should be done via SQVI (Query Quick Viewer).

• All other queries are intended for wider distribution and/or frequency, therefore these should be developed as permanent efficient development objects.

• All query objects will be developed in the Global Area and will be transported via the standard transport process.

• All development should be done in DEV and access to SQ01, SQ02, and SQ03 should not be required in QR or PR.

• Transaction codes would be created for all of these objects as that would be the only means to execute these queries.

Page 32: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 32

Standards - Ownership• SQ01 – Query Maintenance – These objects may be created by the

Development Team, but would be ultimately owned by the Functional Domain, using existing InfoSets.

• SQ02 – InfoSet Maintenance – These objects would be owned by the Development Team and would be developed based on requirements from the Functional Domains. Key Functional Domain users may create these with Development Team review and approval.

• SQ03 – User Group Maintenance – These objects would be owned by the Functional Domains.

• SE93 – Transaction Codes for ABAP Queries – These may be created by the Development Team, but would be ultimately owned by the Functional Domain.

• Non-conforming objects will be owned by Client group that created them until they are converted to comply with current standards.

Page 33: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 33

Standards – Naming ConventionsAll objects will begin with “Z” plus the Functional Domain plus “-” where applicable (i.e. ZSD_”). See additional requirements below:

• Queries – These objects should have a specific name to match the title of the Query (i.e. ZSD_CUST_CL for Customer Credit Limit Rep).

• InfoSets – These objects should be created to cover generic table accesses and should be named as such (i.e. ZSD_CUST_MSTR).

• User Groups – There should be one main user group for each Functional Domain (i.e. ZSD) for general reports. Subgroups for specialty users should be named as the user group plus the “_” and a short name (i.e. ZSD_VC).

• Tcodes – These should named based on Functional Domain preference which could either be a sequential numeric or significant short name (i.e. ZSD_001 or ZSD_CUSMST).

• Variants – All queries requiring a variant should have a standard variant created named “CUS&STANDARD” to set defaults and hide fields as required for all users. SAP only allows variants created with the prefix ‘CUS&” to be transported in the global area. User specific variants should be created in Production.

Page 34: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 34

ABAP Query

Clean Up

Page 35: SAP ABAP Query Creation Tutorial

Development Team04/30/2006 Page 35

ABAP Query Clean Up• User groups will need to be set up in the global area by the Functional

Domains if they do not already exist, complying with naming conventions.

• All new query objects will be created using the new standards and conventions.

• As existing objects are modified, they would need to be converted to conform to the existing standards and conventions. InfoSet Maintenance allows for conversion of objects from the Standard Area to the Global Area.

• Unneeded Query objects should be cleaned up by the creating Client group, whether it be a Functional Domain or the Development Team.

• An on-going effort should be put forth to ensure clean-up of all query objects prior to the upgrade, if possible.