Do's and Don'ts: SAP TM Development
Do's and Don'ts: SAP TM Development
Do's and Don'ts: SAP TM Development
SAP TM Development
March 2014
Customer
March 2014
Agenda
• iv_detlevel and iv_probclass define with user Message Settings (à IMG), if message is visible
In general…
Define one aggregated message with Level of Detail 2
Add detailed messages with Level of Detail 3
© 2014 SAP AG or an SAP affiliate company. All rights reserved. Customer 7
General Do’s and Don’ts
Implementation Rules
BOPF
Queries QUERY_BY_ELEMENTS for node spec. queries,
QUERY_BY_ATTRIBUTES for nodes spanning queries
Determinations DET_<node>_<timepoint>
Validations VAL_<node>_CONSISTENCY, VAL_<node>_<action>
Actions Some clear command
Associations Some clear description, e.g. TO_ITEM_FILTER
Secondary indices
all node table types (/SCMTMS/T_*_K) should have a primary key with attribute KEY and a
secondary keys with attribute PARENT_KEY of type non-unique sorted
– of course, all READ TABLE ... WITH KEY and LOOP AT ... WHERE accesses must use these
secondary indices.
define and use application-specific secondary keys for most frequently accessed fields of all
table types
– keep in mind that unique sorted and unique hashed keys are always updated (=at every insert/append/
delete), whereas non-unique sorted ones are instantiated at the first read access
Keep in mind that your coding will most likely run in high volume scenarios
when READing oder LOOPing internal tables, they may be large
– use primary/secondary keys and/or binary searches when accessing large tables in loops
– or rewrite the coding to reduce the nesting levels
clear unused data containers as soon as they’re not needed anymore
Modify
• Better use io_modify->modify instead of io_modify->create or ->delete or ->update
– Mass processing possible
– Build up modification table sorted using library methods
o /SCMTMS/CL_COMMON_HELPER=>SORT_CREATE_MODIFICATIONS
o /SCMTMS/CL_COMMON_HELPER=>SORT_UPD_DEL_MODIFICATIONS
Queries
• See section about Queries
Accessing DO node instances you can’t use the DO node keys from the DO
constants interface
Determine runtime DO node keys using one of the methods
– /SCMTMS/CL_COMMON_HELPER=>GET_DO_NODE_KEY (preferred for Retrieve)
– /SCMTMS/CL_COMMON_HELPER=>GET_DO_KEYS_4_RBA (preferred for RbA)
– /SCMTMS/CL_COMMON_HELPER=>GET_DO_NODE_KEY_BY_NAME
Modelled Queries are only extendable by extending the underlying node structure
Not extendable with other nodes attributes
That is why the main query of a BO should be an implemented one
Implemented BOPF Queries are per se not extensible
Implemented TM Queries for attributes just of one node
Define query structure and enter directly the class /SCMTMS/CL_Q_SUPERCLASS as query class
Implemented TM Queries
Do not use subqueries and merge the results after their execution à Performance killer
Create a subclass of /SCMTMS/CL_Q_SUPERCLASS and overwrite method
GET_QUERY_ENHANCE_TABLE filling table ET_QUERY_ENHANCE
– Superclass contains also a BAdI for customer extensions
– Superclass concept can be used in future to replace DB selection by Enterprise Search (optional)
– Also database tables, views and external BO nodes can be included
Implement only queries that are necessary; no pool queries without direct use case
See also Class Documentation of /SCMTMS/CL_Q_SUPERCLASS
Don‘t use BOPF Service Manager for Retrieve, RbA, Convert Alternative Key,
or Standard Queries
Only in very exceptional cases
Do select a database table once and select all needed data with one fetch
Do include authority check relevant attributes into the query result structure
Authority checks are directly performed on the query results
Within the Query Enhance Table you define where and how the system should
resolve the selection parameters with which a query is executed
The simplier the selection parameters are, the better the performance of the query will be
Try to define as many selection parameters as possible via the Query Enhance Table
– It is not necessary to define an Query Enhance Table entry for selection parameters from the query
node
For complex cases you have three alternatives:
– Overwrite method GET_PRESELECTED_FILTER_KEYS()
Select keys of instances matching the complex selection parameter criteria and return them in
CT_FILTER_KEY. This leads to that only these instances are selected from database and
further filtered by the other selection parameters.
– Overwrite method ADAPT_SELECTION_PARAMETERS()
Convert complex selection parameters into simple ones, e.g. having selection parameters for
BUPA street and city, you could find all business partners for the given street and city and
replace the selection parameters for BUPA street and city by the BUPA Keys.
– Mark the selection parameter with FILTER_AFTER_SELECTION = ABAP_TRUE
With this the selection parameter is ignored during database selection. Instead it is used after
selection to reduce the query result set accordingly.
Within the Result Enhance Table you define where and how the system can
find the attributes of the query result set
Let the Query Superclass handle only the simple query result attributes
– You need not to define anything for attributes from the query node
– Simple joins can also be handled by the Query Superclass
Mark complex query result attributes with super_ignore = abap_true
– The query superclass will not select these attributes from database
– Implement method ADAPT_QUERY_RESULT() fetching all additional result list data that was not
handled by the query superclass
The Query result structure should contain
– all attributes being relevant for authority check
– All attributes being relevant for the query use cases
The Query should not
– use complex helper classes from TM backend
– Not mass enabled method, function modules or forms
The query should be able to optimize the coding in ADAPT_QUERY_RESULT() on basis of
requested attibutes
Method GET_QUERY_ENHANCE_TABLE
Enhancement structure [query_key, attr_node_key, db_counter, node_attr, query_attr]
DATA: ls_enh TYPE /scmtms/s_query_enhance.
CLEAR et_query_enhance.
ls_enh-query_key = /scmtms/if_tor_c=>sc_query-root-root_elements.
ls_enh-attr_node_key = /scmtms/if_tor_c=>sc_node-main.
ls_enh-node_attr = /scmtms/if_tor_c=>sc_node_attribute-main-mtr.
ls_enh-query_attr = /scmtms/if_tor_c=>sc_query_attribute-main-mtr.
APPEND ls_enh TO et_query_enhance.
Method QUERY_CALL_BADI
Calls BAdI /SCMTMS/FRW_QUERY
– Parameters
o Same as for method /BOBF/IF_FRW_QUERY->QUERY
o ET_QUERY_ENHANCE : Query extension via enhancement table
o EV_SKIP_QUERY : Skip modelled query?
Use Alternative Keys instead of Query to determine a key for an external BO instance ID
Using secondary index on DB
Using buffer if already available
DATA: lt_prod_ids TYPE /bobf/t_demo_product_id,
ls_prod_id TYPE /bobf/s_demo_product_id,
lt_prod_results TYPE /bobf/t_frw_keyindex,
ls_result TYPE /bobf/s_frw_keyindex.
…
* Extract BP names and build up altkey keys
LOOP AT lt_item ASSIGNING <ls_item>
WHERE prod_name IS NOT INITIAL.
ls_prod_id-product_id = <ls_item>-prod_name.
APPEND ls_prod_id TO lt_prod_ids.
ENDLOOP.
SORT lt_prod_ids BY product_id.
DELETE ADJACENT DUPLICATES FROM lt_prod_ids COMPARING product_id.
Before Retrieve
Transient Determinations only
Called for transient nodes only
Called before every retrieve of the trigger nodes
– Should be used with care! Performance impact!
After Loading
Transient Determinations only
Called once after node was loaded into buffer
– Following retrieves do not trigger such determinations
Called for all After-Loading-Determinations of the same Loading Group
Not called in a nested scenario
– After-Loading-Determinations of foreign loading groups are not executed
The BOPF Test UI (BOBF/TEST_UI) can be used to check and verify business
object functionality
Restrictions
• Can‘t handle deep BO Node Structures. This leads to that not every SAP TM
functionality can be tested with this generic Test UI.
• Very technical UI
• No support for problems in connection with the BOPF Test UI
Constants in /BOBF/IF_FRW_C
/BOBF/IF_FRW_C=>SC_MODIFY_...
• Debugger Scripts
– Helper class for Debugger Scripts
o /SCMTMS/CL_DEBUGGER_SCRIPT_H
– TM Scripts
o /SCMTMS/DEBUGGER_SCRIPT_*
Contact information:
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG or an
SAP affiliate company.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG
(or an SAP affiliate company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional
trademark information and notices.
Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.
These materials are provided by SAP AG or an SAP affiliate company for informational purposes only, without representation or warranty of any kind,
and SAP AG or its affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP AG or
SAP affiliate company products and services are those that are set forth in the express warranty statements accompanying such products and
services, if any. Nothing herein should be construed as constituting an additional warranty.
In particular, SAP AG or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related
presentation, or to develop or release any functionality mentioned therein. This document, or any related presentation, and SAP AG’s or its affiliated
companies’ strategy and possible future developments, products, and/or platform directions and functionality are all subject to change and may be
changed by SAP AG or its affiliated companies at any time for any reason without notice. The information in this document is not a commitment,
promise, or legal obligation to deliver any material, code, or functionality. All forward-looking statements are subject to various risks and uncertainties
that could cause actual results to differ materially from expectations. Readers are cautioned not to place undue reliance on these forward-looking
statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.
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 oder ein SAP-Konzernunternehmen nicht gestattet.
SAP und andere in diesem Dokument erwähnte Produkte und Dienstleistungen von SAP sowie die dazugehörigen Logos sind Marken oder
eingetragene Marken der SAP AG (oder von einem SAP-Konzernunternehmen) in Deutschland und verschiedenen anderen Ländern weltweit.
Weitere Hinweise und Informationen zum Markenrecht finden Sie unter http://global.sap.com/corporate-de/legal/copyright/index.epx.
Die von SAP AG oder deren Vertriebsfirmen angebotenen Softwareprodukte können Softwarekomponenten auch anderer Softwarehersteller enthalten.
Die vorliegenden Unterlagen werden von der SAP AG oder einem SAP-Konzernunternehmen bereitgestellt und dienen ausschließlich zu Informations-
zwecken. Die SAP AG oder ihre Konzernunternehmen übernehmen keinerlei Haftung oder Gewährleistung für Fehler oder Unvollständigkeiten in
dieser Publikation. Die SAP AG oder ein SAP-Konzernunternehmen steht lediglich für Produkte und Dienstleistungen nach der Maßgabe ein, die in der
Vereinbarung über die jeweiligen Produkte und Dienstleistungen ausdrücklich geregelt ist. Keine der hierin enthaltenen Informationen ist als zusätzliche
Garantie zu interpretieren.
Insbesondere sind die SAP AG oder ihre Konzernunternehmen in keiner Weise verpflichtet, in dieser Publikation oder einer zugehörigen Präsentation
dargestellte Geschäftsabläufe zu verfolgen oder hierin wiedergegebene Funktionen zu entwickeln oder zu veröffentlichen. Diese Publikation oder
eine zugehörige Präsentation, die Strategie und etwaige künftige Entwicklungen, Produkte und/oder Plattformen der SAP AG oder ihrer Konzern-
unternehmen können von der SAP AG oder ihren Konzernunternehmen jederzeit und ohne Angabe von Gründen unangekündigt geändert werden.
Die in dieser Publikation enthaltenen Informationen stellen keine Zusage, kein Versprechen und keine rechtliche Verpflichtung zur Lieferung von
Material, Code oder Funktionen dar. Sämtliche vorausschauenden Aussagen unterliegen unterschiedlichen Risiken und Unsicherheiten, durch die
die tatsächlichen Ergebnisse von den Erwartungen abweichen können. Die vorausschauenden Aussagen geben die Sicht zu dem Zeitpunkt wieder,
zu dem sie getätigt wurden. Dem Leser wird empfohlen, diesen Aussagen kein übertriebenes Vertrauen zu schenken und sich bei Kaufentscheidungen
nicht auf sie zu stützen.