Bs bopf+basic+training+-+08+queries

21
BS-BOPF Basic Training 08 Queries BOPF Team 29 July 2010

description

 

Transcript of Bs bopf+basic+training+-+08+queries

Page 1: Bs bopf+basic+training+-+08+queries

BS-BOPF Basic Training

08 Queries

BOPF Team

29 July 2010

Page 2: Bs bopf+basic+training+-+08+queries

© SAP 2007 / Page 2

Agenda

1. Introduction

2. Creating a Query

3. Implementation of a Custom Query

4. Questions and Answers

Page 3: Bs bopf+basic+training+-+08+queries

Introduction

The application for maintaining customer invoices shall offer a screen in order to display all

overdue invoices. This is realized by the help of a query located at the customer invoice

business object returning the affected invoices.

© SAP 2007 / Page 3

I would like to see all

overdue invoices…

Page 4: Bs bopf+basic+training+-+08+queries

© SAP 2007 / Page 4

A query is a business object entity and is always assigned to a certain node, whose

instances shall be returned

The consumer is able to query either only the keys or the whole data of the resulting

node instances

Queries never modify any node instance data*

There are three types of queries:

Node Attribute Query

Custom Query

Generic Result Query

Introduction

Query Definition

Page 5: Bs bopf+basic+training+-+08+queries

© SAP 2007 / Page 5

Resolved by BOPF DAC without any implementation effort

There are two inbuilt node attribute queries available:

SELECT_ALL:

No query parameter structure

Returns all node instances of the assigned node

of the query

SELECT_BY_ELEMENTS:

Query parameter structure corresponds to a

range table related to the assigned nodes’

attributes

Returns only node instances of the assigned

node whose attributes are compliant to this range

table

Query Types in Detail:

Node Attribute Query

Page 6: Bs bopf+basic+training+-+08+queries

© SAP 2007 / Page 6

Custom Query

Necessary in order to provide application specific

queries, whose logic is not covered by node attribute

query

Resolved by the help of an implementing class

Query parameter structure is arbitrary

Returns only node instances of the assigned node of

the query

Example: GET_OVERDUE_INVOICES

Generic Result Query (special kind of Custom Query)

Necessary in rarely use cases, which can not be

realized with custom queries due to performance

reasons (e.g. denormalized read only lists for the UI)

May return arbitrary data tables (but these must

contain a KEY component relating to the instances of

the assigned node)

Must only be used after consultation of your local

BOPF expert!

Query Types in Detail :

Custom Query and Generic Result Query

Page 7: Bs bopf+basic+training+-+08+queries

© SAP 2007 / Page 7

Agenda

1. Introduction

2. Creating a Query

3. Implementation of a Query

4. Questions and Answers

Page 8: Bs bopf+basic+training+-+08+queries

Creating a Node Attribute Query

(SELECT_ALL or SELECT_BY_ELEMENTS)

In order to create a SELECT_ALL query, just create a query and name it „SELECT_ALL“ (or

„SELECT_BY_ELEMENTS“ if the query parameters are equal to the attributes of the

assigned node).

© SAP 2007 / Page 8

Page 9: Bs bopf+basic+training+-+08+queries

Creating a Custom Query

Maintain the implementing class and the data type:

The query class must implement interface /BOBF/IF_FRW_QUERY and contains the query logic

The data type can be an structure with arbitrary components and could be used by a generic UI do

display a range table based input form. At runtime, as soon as the query is executed after the form

is filled, the parameter IT_SELECTION_PARAMETERS is handed over containing those values.

Each line of it represents a value range related to a component contained in this data type (but

not each component of the data type must always have a corresponding line in

IT_SELECTION_PARAMETERS – handing over a value range is optional). The query

implementation can use the selection parameters for dynamically selections.

© SAP 2007 / Page 9

Page 10: Bs bopf+basic+training+-+08+queries

© SAP 2007 / Page 10

Agenda

1. Introduction

2. Creating a Query

3. Implementation of a Custom Query

4. Questions and Answers

Page 11: Bs bopf+basic+training+-+08+queries

© SAP 2007 / Page 11

methods QUERY

importing

IS_CTX type /BOBF/S_FRW_CTX_QUERY

IT_FILTER_KEY type /BOBF/T_FRW_KEY optional

IT_SELECTION_PARAMETERS type /BOBF/T_FRW_QUERY_SELPARAM optional

IS_QUERY_OPTIONS type /BOBF/S_FRW_QUERY_OPTIONS optional

IO_QUERY type ref to /BOBF/IF_FRW_QUERY

IO_READ type ref to /BOBF/IF_FRW_READ

IO_MODIFY type ref to /BOBF/IF_FRW_MODIFY optional

exporting

EO_MESSAGE type ref to /BOBF/IF_FRW_MESSAGE

ET_KEY type /BOBF/T_FRW_KEY

ES_QUERY_INFO type /BOBF/S_FRW_QUERY_INFO

ET_DATA type index table

raising

/BOBF/CX_FRW .

QUERY

RETRIEVE_DEFAULT_PARAM

(optional)

Queries are classes implementing the /BOBF/IF_FRW_QUERY interface.

methods RETRIEVE_DEFAULT_PARAM

importing

IS_CTX type /BOBF/S_FRW_CTX_QUERY

changing

CT_SELECTION_PARAMETERS type /BOBF/T_FRW_QUERY_SELPARAM

raising

/BOBF/CX_FRW .

Overview of a Query Implementation

Page 12: Bs bopf+basic+training+-+08+queries

RETRIEVE_DEFAULT_PARAM Method

methods RETRIEVE_DEFAULT_PARAM

importing

IS_CTX type /BOBF/S_FRW_CTX_QUERY

changingCT_SELECTION_PARAMETERS type /BOBF/T_FRW_QUERY_SELPARAM

raising

/BOBF/CX_FRW .

Retrieves the default parameters of a query.

IS_CTX: Context information about the query

CT_SELECTION_PARAMETERS: Reference to the parameters of the query which shall be filled with default values by the help of this method

© SAP 2007 / Page 12

Page 13: Bs bopf+basic+training+-+08+queries

QUERY Method

methods QUERY

importing

IS_CTX type /BOBF/S_FRW_CTX_QUERY

IT_FILTER_KEY type /BOBF/T_FRW_KEY optional

IT_SELECTION_PARAMETERS type /BOBF/T_FRW_QUERY_SELPARAM optional

IS_QUERY_OPTIONS type /BOBF/S_FRW_QUERY_OPTIONS optional

IO_QUERY type ref to /BOBF/IF_FRW_QUERY

IO_READ type ref to /BOBF/IF_FRW_READ

IO_MODIFY type ref to /BOBF/IF_FRW_MODIFY optional

exporting

EO_MESSAGE type ref to /BOBF/IF_FRW_MESSAGE

ET_KEY type /BOBF/T_FRW_KEY

ES_QUERY_INFO type /BOBF/S_FRW_QUERY_INFO

ET_DATA type index table

raising

/BOBF/CX_FRW .

Executes the query logic.

© SAP 2007 / Page 13

Page 14: Bs bopf+basic+training+-+08+queries

Query Method Parameters (1/2)

Importing Parameters

© SAP 2007 / Page 14

IS_CTX: Context information about the query (BO key, root node key, assigned node key,…)

IT_FILTER_KEY: If the query shall take only a restricted set of the node instances into account, these can be specified by the consumer with the help of this parameter. If the parameter is empty, all node instances of the query's assigned node are affected by the query.

IT_SELECTION_PARAMETER: This parameter represents a range table of attributes of the query parameter structure. If attributes are supplied, only these must be filled – the other attributes have not to be filled if this increases the performance.

IS_QUERY_OPTIONS:

MAXIMUM_ROWS: Maximal number of node instances, which shall be returned by the query. In case of activated paging, the number of node instances of a single page.

SORTING_OPTIONS: The sorting of the result can be influenced by the help of this parameter. It consists of a table allowing to specify the sorting order ascending/ descending for the columns (=attributes).

PAGING_OPTIONS: This parameter allows to configure the paging options.

PAGING_ACTIVE: yes/no

Topmost instance of the current page can either be defined by row (START_ROW) or by key of the instance (START_KEY)

IO_QUERY: Reference to an object allowing the execution of a further query

IO_READ: Reference to an object implementing the read interface to read instance data.

IO_MODIFY: Reference to an object implementing the modify interface to modify instance data.

Page 15: Bs bopf+basic+training+-+08+queries

© SAP 2007 / Page 15

EO_MESSAGE: This message object contains all messages, which have been created during the execution of the query.

ES_QUERY_INFO: This parameter contains the query handle and the paging related information.

COUNT: Total number of results

QUERY_HANDLE: Obsolete

ET_DATA: Returning table for generic result queries

ET_KEY: This parameter represents a set of the keys of the node instances, which are the result of the query.

Query Method Parameters (2/2)

Exporting Parameters

Page 16: Bs bopf+basic+training+-+08+queries

© SAP 2007 / Page 16

Agenda

1. Introduction

2. Creating a Query

3. Implementation of a Query

4. Questions and Answers

Page 17: Bs bopf+basic+training+-+08+queries

Questions and Answers (1/2)

Must SELECT_BY_ELEMENTS and SELECT_ALL queries be implemented?

No, if the /BOBF/CL_DAC_TABLE is used, these queries are automatically resolved.

May queries be assigned to nodes located at a Dependent Object?

No, for instance a SELECT_BY_ELEMENTS query would return all instances fulfilling the

search criterias. If a DO is used in several Business Objects, this result is not related on one

single DO use case and thus the result makes no sence.

Is it possible to set properties for Queries (e.g. enable/ disable)?

No, queries are not node instance related thus node category dependent properties and

dynamic properties do not cover queries.

May I use Queries within entity implementations (e.g. in an action)?

No, queries are only intended to be used by consumers or other queries. Usually you have

node instance keys provided by the BOPF (IT_KEY importing parameter), which can be used

to retrieve/ retrieve_by_associations further related instances. In addition, you can use

convert_alternative_key in order to receive further node instances.

If a new node instance is created during a transaction, will a query executed later on in

the same transaction be able to return it?

No, queries only operate on the database image, which means that the changes done so far

in the current transaction are not taken into account. This is a difference in contrast to

convert_altern_key and retrieve/ retrieve_by_association.

© SAP 2007 / Page 17

Page 18: Bs bopf+basic+training+-+08+queries

Questions and Answers (2/2)

Queries must not change instance data, but why do I need io_modify importing

parameter at all?

If a custom query is assigned to a transient node, the query must write the result instances

to the transient node. This ensures, that the consumer is able to get them using for instance

the retrieve core service.

Is it possible to reuse other queries in the implementation of a custom query?

Use importing parameter IO_QUERY->QUERY(…) in order to call a certain query located at

the same BO.

Shall I use the io_read importing parameter or an SQL statement to the node‘s

database table in the implementation of a custom query?

Use always a SQL statement in order to ensure, that the query returns only instances of the

database state and for performance reasons.

Is it necessary to provide the paging and sorting feature for each query?

Yes, this is part of the query contract which must be fulfilled by each query – a consumer

must be able to rely on that.

© SAP 2007 / Page 18

Page 19: Bs bopf+basic+training+-+08+queries

© SAP 2007 / Page 19

Questions?

Page 20: Bs bopf+basic+training+-+08+queries

© SAP 2007 / Page 20

Thank you!

Page 21: Bs bopf+basic+training+-+08+queries

© SAP 2007 / Page 21

Copyright 2007 SAP AG

All rights reserved

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, Duet, Business ByDesign, ByDesign, PartnerEdge and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned and associated logos displayed are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.

The information in this document is proprietary to SAP. This document is a preliminary version and not subject to your license agreement or any other agreement with SAP. This document contains only intended strategies, developments, and functionalities of the SAP® product and is not intended to be binding upon SAP to any particular course of business, product strategy, and/or development. SAP assumes no responsibility for errors or omissions in this document. SAP does not warrant the accuracy or completeness of the information, text, graphics, links, or other items contained within this material. This document is provided without a warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.

SAP shall have no liability for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. This limitation shall not apply in cases of intent or gross negligence.

The statutory liability for personal injury and defective products is not affected. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third-party Web pages nor provide any warranty whatsoever relating to third-party Web pages

Weitergabe und Vervielfältigung dieser Publikation oder von Teilen daraus sind, zu welchem Zweck und in welcher Form auch immer, ohne die ausdrückliche schriftliche Genehmigung durch SAP AG nicht gestattet. In dieser Publikation enthaltene Informationen können ohne vorherige Ankündigung geändert werden.

Einige von der SAP AG und deren Vertriebspartnern vertriebene Softwareprodukte können Softwarekomponenten umfassen, die Eigentum anderer Softwarehersteller sind.

SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, Duet, Business ByDesign, ByDesign, PartnerEdge und andere in diesem Dokument erwähnte SAP-Produkte und Services sowie die dazugehörigen Logos sind Marken oder eingetragene Marken der SAP AG in Deutschland und in mehreren anderen Ländern weltweit. Alle anderen in diesem Dokument erwähnten Namen von Produkten und Services sowie die damit verbundenen Firmenlogos sind Marken der jeweiligen Unternehmen. Die Angaben im Text sind unverbindlich und dienen lediglich zu Informationszwecken. Produkte können länderspezifische Unterschiede aufweisen.

Die in diesem Dokument enthaltenen Informationen sind Eigentum von SAP. Dieses Dokument ist eine Vorabversion und unterliegt nicht Ihrer Lizenzvereinbarung oder einer anderen Vereinbarung mit SAP. Dieses Dokument enthält nur vorgesehene Strategien, Entwicklungen und Funktionen des SAP®-Produkts und ist für SAP nicht bindend, einen bestimmten Geschäftsweg, eine Produktstrategie bzw. -entwicklung einzuschlagen. SAP übernimmt keine Verantwortung für Fehler oder Auslassungen in diesen Materialien. SAP garantiert nicht die Richtigkeit oder Vollständigkeit der Informationen, Texte, Grafiken, Links oder anderer in diesen Materialien enthaltenen Elemente. Diese Publikation wird ohne jegliche Gewähr, weder ausdrücklich noch stillschweigend, bereitgestellt. Dies gilt u. a., aber nicht ausschließlich, hinsichtlich der Gewährleistung der Marktgängigkeit und der Eignung für einen bestimmten Zweck sowie für die Gewährleistung der Nichtverletzung geltenden Rechts.

SAP übernimmt keine Haftung für Schäden jeglicher Art, einschließlich und ohne Einschränkung für direkte, spezielle, indirekte oder Folgeschäden im Zusammenhang mit der Verwendung dieser Unterlagen. Diese Einschränkung gilt nicht bei Vorsatz oder grober Fahrlässigkeit.

Die gesetzliche Haftung bei Personenschäden oder die Produkthaftung bleibt unberührt. Die Informationen, auf die Sie möglicherweise über die in diesem Material enthaltenen Hotlinks zugreifen, unterliegen nicht dem Einfluss von SAP, und SAP unterstützt nicht die Nutzung von Internetseiten Dritter durch Sie und gibt keinerlei Gewährleistungen oder Zusagen über Internetseiten Dritter ab.

Alle Rechte vorbehalten.