This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
SAP TechEd 08
1
COMP361Advanced ABAP Programming
Frank Bertelsmeier, NW F ABAPDaniel Housmans, NW Technical ConsultingSigrid Wortmann, NW F ABAP
This presentation outlines our general product direction and should not be relied on in making a purchase decision. This presentation is not subject to your license agreement or any other agreement with SAP. SAP has no obligation to pursue any course of business outlined in this presentation or to develop or release any functionality mentioned in this presentation. This presentation and SAP's strategy and possible future developments are subject to change and may be changed by SAP at any time for any reason without notice. 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 assumes no responsibility for errors or omissions in this document, except if such damages were caused by SAP intentionally or grossly negligent.
As a result of this workshop, you will be able to:Deploy strings for efficient handling of text-based informationMake use of regular expressions to process strings effectivelyWrite compact code by using extended expression capabilitiesUtilize string templates to create formatted textWork proficiently and efficiently with the new features for internal tables
Implement generic services by using dynamic WHERE conditionsOptimize the performance of your programs using secondary keys
Benefit from new ABAP features of SAP NetWeaver 7.10 and 7.11
Some benefits that ABAP strings provideEfficient management of string storage spaceAutomatic garbage collectionAutomatic value sharing with copy-on-write
Max length of 262.143 charsMax length of 2,000,000,000 bytes
Regular Expressions (REs, regexes)provide powerful pattern language for text processing
Well understoodDeveloped by mathematician Kleene in the 1950s
PowerfulHighly focused special purpose languageMany common text processing tasks turn intosimple one-liners
Standardized and widely usedMade popular by Unix tools: grep, sed, awk, emacsBuilt into some languages like Perl and Java;add-on libraries available for many othersEarly Unix de-facto standard formalized in PCRE and POSIX
ABAP supports POSIX-style regular expressions as of NetWeaver 7.0
<h2 id="slogan">Leading the Web to Its Full Potential...</h2>
<p class="small">The World Wide Web Consortium (<acronym>W3C</acronym>) develops interoperable technologies to lead the Web to its full potential. W3C is a forum for information, commerce, communication, and collective understanding. On this page, you'll find <a href="#news">W3C news</a>, links to <a href="#technologies">W3C technologies</a>and ways to <a href="#contents">get involved</a>. New visitors can find help in <cite><a href="/2002/03/new-to-w3c">Finding Your Way at W3C</a></cite>. We encourage you to read the <cite><a href="/Consortium/Prospectus/">Prospectus </a></cite>and learn <a href="/Consortium/">more about W3C</a>.</p>'
Leading the Web to Its Full Potential... TheWorld Wide Web Consortium (W3C) develops interoperable technologies to lead the Web to its full potential. W3C is a forum for information, commerce, communication, and collective understanding. On this page, you'll find W3C news, links to W3C technologies and ways to get involved. New visitors can find help in Finding Your Way at W3C. We encourage you to read the Prospectusand learn more about W3C.
Exercise: Write simple regular expressions thatmatch all text samples shown in the left column anddo not match any text samples shown in the right column
System accessLog into system M55Start transaction SE38Run report ZTE08_REGEX_EX1
UsageClick on arrows to navigate between individual exercisesClick SHOW to display sample solution
RE support integrated into FIND and REPLACE statementsFinding first occurrence
Replacing all occurrences
Supports all known additions, e.g., IGNORING CASEAdditional support for FIND ALL OCCURRENCESAdditional support for searching internal tablesREs limited to CHARACTER MODE
FIND REGEX pattern IN textMATCH OFFSET off MATCH LENGTH len.
REPLACE ALL OCCURRENCES OF REGEX patternIN text WITH newREPLACEMENT COUNT cnt.
ABAP Objects provides two classes for using REsRegex class cl_abap_regex
Stores preprocessed RE pattern for increasedperformanceShould be reused to avoid costly re-processing
Matcher class cl_abap_matcherCentral class for interaction with REsLinks text to regex objectStores copy of text to process (efficient forstrings, costly for fixed-length fields)Tracks matching and replacing within text
Using regex classes in ABAPCreate regex and matcher and interact with matcherUse static class methods of matcher as a shorthand
New kind of computational expressions: String ExpressionsConcatenations txt1 && txt2
String Templates |…Text…{ expression format = … }…Text…|
String ExpressionsUsed to create formatted or technical text (e.g. xml) convenientlyUsable in expression positions just like arithmetic or binary expressionsSubstitute masses of
WRITE TO and character-like helper variables (for conversions and formatting)CONCATENATE
New Built-In Functions23 functions returning a string result8 functions returning a non-string result4 new predicates on strings
String TemplatesEvaluation includes conversions, formatting and concatenatingDirectly supports the use of control characters (like “\n” for newline)Cannot stretch over multiple lines (use ‘&’ to concatenate across lines)
Replaces WRITE TO statement and many auxiliary variables
s = |Hello, \n| &|today is { sy-datum date = iso } \n| &|now is { sy-uzeit time = iso }|.
if intval < 0.cvar = '-'.write intval to cvar+1 no-sign left-justified no-grouping.s = cvar.
Extended use of expressionsSupported in many operand positions, especially for internal table statementsSeamless integrated in OO context (nested method calls, chaining)
String expressionsSimple, however very powerfulIntuitively use like arithmetic expressionsRich set of formatting optionsRich set of built-in string functions
To learn moreRun ABAP report DEMO_EXPRESSIONSCheck the ABAP online documentation
Dynamic WHERE conditions can also handle the following constructsMethod calls and attribute accessArithmetic expressionsPredefined functionsAccess via data referencesDynamic WHERE condition has full secondary key support
Performance aspectsThe component and value parts should have the same type to avoid internal conversions.
If a table key is appropriately covered (left initial piece for SORTED, all components for HASHED keys) the WHERE condition can be optimized
As an internal optimization a cache is implemented to reuse static information
Benefits from key tables (available since 4.0) Fast O(1) key access for hashed tablesFast O(log n) key access for sorted tablesFast partial sequential processing for sorted tables (LOOP … WHERE optimization)
Benefits from key tables (available since 4.0) Fast O(1) key access for hashed tablesFast O(log n) key access for sorted tablesFast partial sequential processing for sorted tables (LOOP … WHERE optimization)
Non-primary key access Slow O(n) runtime behaviorMight cause performance problemsTo be optimized by error prone hand-coded secondary key access
Secondary keys are part of a table type definition, i.e. they are statically defined
However, the key and its components to be used in a statement (READ, LOOP, …) can be specified dynamically
The definition of a secondary key has to be complete, i.e. the following properties have to be fully specified
Name of the key: it has to be unique for the tableAccess kind: HASHED or SORTEDUniqueness kind: UNIQUE or NON-UNIQUE, where a hash key has to be uniqueKey components: either a user-defined list of componentnames or the pseudo-component TABLE_LINE
Non-unique (sorted) secondary keysLazy index update, i.e. index is not flushed before it is actually used
No memory costs if not used
Thus, perfectly suitable to tune existing programs
Unique secondary keysUniqueness is a semantic constraint, i.e. immediate response (exception/runtime error) if violated by atomic operations (INSERT, MOVE, SELECT, …)
INSERT into a table with secondary keys:There are no syntax extensions for secondary keys for the inserting statements (INSERT, MOVE, SELECT … INTO, …)The primary key is updated immediately
NOOP for a single INSERT on a SORTED or HASHED tables, if the entry already exists (return code instead)Runtime error in case of block operations for DupRecs
Unique secondary keys are also immediately updatedCatchable exception for a single INSERT operationRuntime error in case of block operations for DupRecs
Non-unique secondary keys have a lazy updateThey are updated when the table is accessed using this keyNo memory costs before first use (except basic administrative costs)
Using Secondary Keys:Key Components have to be provided
Using a secondary key in combination with “WHERE ...” or “WITH KEY ...” requires the following:
for a HASHED key all components have to be listedfor a SORTED key at least a left initial part of the key component list has to be given
This is a difference between the (implicitly used) primary table key and secondary keys. The reason is that the expected runtime optimizations canonly be achieved under these conditions.
Tool Support:Performance Hints by the ABAP Compiler (1)
If specified, a secondary keys must be usable:Syntax error if it can be statically decided that a key cannot be usedRuntime error if this occurs in dynamically specified statements
Delayed index update for incremental key changesNo index flush if key components are changed via pointer or reference accessUpdate is delayed until
the next table statement or the table is passed as a parameter to a method, function, …
Avoids duplicate record exception during update for unique keysRequires debugging support (watch points on key changes) because there might be a significant time gap between the key changes and the index flush
Primary key components are write protectedKey components of sorted or hash tables are write protected, i.e. no changes via pointers or references possible (runtime error)
Generalization for secondary keysWithin a loop with respect to a certain secondary key, the corresponding key components are also write protected
Within nested loops, the union of the primary key components and all secondary key components currently in use (active keys) are write protected
Technically this requires key component surveillance at every write operation
Components of non-active keys can be overwritten (delayed index update)
Otherwise, i.e. if all components of all secondary keys would also be write protected: adding additional keys to an already existing internal table might result in incompatibility
The design of secondary keys allows an easy integration in existing and new coding
Few syntax additions (USING KEY, COMPONENTS) to define and use secondary keysSyntax check support by redundancy warnings and performance hintsPerformance of existing programs can easily be improved by supplementing secondary keys (compatibility)Powerful delta management by lazy and delayed update handling
We introduced techniques for Processing text-based information using strings, regular expressions and string functionsWriting compact code using new expressions capabilitiesCreating well-formatted or technical text using string templatesGeneric programming using dynamic WHERE conditionsEfficiently managing large amounts of data stored in internal tables using secondary keys
Check memory consumption with the Memory Analysis Tool:Press button Special Tools Memory AnalysisBound memory: memory that will be available again for the current user session after freeing the tableReferenced memory: includes also memory reachable via references
Make/compare memory snap shots using the Memory Analysis Tool:Press button Special Tools Memory AnalysisPress button to invoke the Memory Analysis Services dialogMake snap shots before and after flushing; invoke Memory InspectorCompare them by pressing the compare button
Avoid DELETE using secondary key on a STANDARD table:Locating the entry to be deleted with respect to some secondary key is fast
However, all other keys have to be updated, too
In particular, the corresponding entry in the primary key has to be search linearly
Thus, overall runtime behavior is linear
Avoid modifying unique secondary keys in the Debugger:Due to the delayed update feature, this may lead to a DupRec error when the next table statement is exceuted
SDN Subscriptions offers developers and consultants like you, an annual license to the complete SAP NetWeaver platform software, related services, and educational content, to keep you at the top of your profession.
SDN Software Subscriptions: (currently available in U.S. and Germany)A one year low cost, development, test, and commercialization license to the complete SAP NetWeaver software platform Automatic notification for patches and updatesContinuous learning presentations and demos to build expertise in each of the SAP NetWeaver platform componentsA personal SAP namespace
SAP NetWeaver Content Subscription: (available globally)An online library of continuous learning content to help build skills.
Starter Kit
Building Your Business with SDN Subscriptions
To learn more or to get your own SDN Subscription, visit us at the Community Clubhouse or at www.sdn.sap.com/irj/sdn/subscriptions
Take advantage of the enhanced, expanded and multi tier certifications from SAP today!
What the industry is saying“Teams with certified architects and
developers deliver projects on specification, on time, and on budget more often than other teams.”2008 IDC Certification Analysis
“82% of hiring managers use certification as a hiring criteria.”2008 SAP Client Survey
“SAP Certified Application Professional status is proof of quality, and that’s what matters most to customers.”*Conny Dahlgren, SAP Certified Professional
Related Workshops/Lectures at SAP TechEd 2008COMP209, News in ABAP Development, LectureCOMP267, ABAP Troubleshooting, WorkshopCOMP106, ABAP Performance and Trace Analysis, LectureCOMP269, Efficient Database Programming, LectureCOMP272, Memory Efficient ABAP Programming, WorkshopCOMP273, Test-Driven and Bulletproof ABAP Development, WorkshopCOMP274, Developing User Interfaces With Web Dynpro for ABAP, WorkshopCOMP275, State-of-the-Art ABAP -- Programming with ABAP Objects, WorkshopCOMP277, ABAP Development: Update Your Skills to SAP NetWeaver 7.0, Workshop
Related SAP Education and Certification Opportunitieshttp://www.sap.com/education/
SAP Public Web:SAP Developer Network (SDN): www.sdn.sap.comBusiness Process Expert (BPX) Community: www.bpx.sap.com
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, xApps, xApp, SAP NetWeaver, Duet, SAP 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. No part of this document may be reproduced, copied, or transmitted in any form or for any purpose without the express prior written permission of SAP AG. 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. Please note that this document is subject to change and may be changed by SAP at any time without notice. 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, xApps, xApp, SAP NetWeaver, Duet, SAP 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 dieser Publikation enthaltene Information ist Eigentum der SAP. Weitergabe und Vervielfältigung dieser Publikation oder von Teilen daraus sind, zu welchem Zweck und in welcher Form auch immer, nur mit ausdrücklicher schriftlicher Genehmigung durch SAP AG gestattet. Bei dieser Publikation handelt es sich um eine vorläufige Version, die nicht Ihrem gültigen Lizenzvertrag oder anderen Vereinbarungen mit SAP unterliegt. Diese Publikation enthält nur vorgesehene Strategien, Entwicklungen und Funktionen des SAP®-Produkts. SAP entsteht aus dieser Publikation keine Verpflichtung zu einer bestimmten Geschäfts- oder Produktstrategie und/oder bestimmten Entwicklungen. Diese Publikation kann von SAP jederzeit ohne vorherige Ankündigung geändert werden.
SAP übernimmt keine Haftung für Fehler oder Auslassungen in dieser Publikation. Des Weiteren übernimmt SAP keine Garantie für die Exaktheit oder Vollständigkeit der Informationen, Texte, Grafiken, Links und sonstigen in dieser Publikation enthaltenen Elementen. 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 haftet nicht für entstandene Schäden. Dies gilt u. a. und uneingeschränkt für konkrete, besondere und mittelbare Schäden oder Folgeschäden, die aus der Nutzung dieser Materialien entstehen können. Diese Einschränkung gilt nicht bei Vorsatz oder grober Fahrlässigkeit.
Die gesetzliche Haftung bei Personenschäden oder 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.