You are on page 1of 65

ABAP201: Best of ABAP The Ultimate ABAP 6.

40 Feature Show

Contributing Speakers
Andreas Blumenthal
SAP AG

Karsten Bohlmann
SAP AG

Boris Gebhardt
SAP AG

Christoph Stoeck
SAP AG

SAP AG 2004, SAP TechEd / ABAP201 / 2

Agenda

Generic Programming

Checkpoints in ABAP

ABAP Debugger

Shared Objects

ABAP Unit

Simple Transformations

Memory Inspector

SAP AG 2004, SAP TechEd / ABAP201 / 3

ABAP Unit

SAP AG 2004, SAP TechEd / ABAP201 / 4

ABAP Unit A Little Story (Version 1)


We visit a mid sized company XYZ based somewhere in the US. They developed their own SAP NetWeaver based flight booking system.

ABAP Developer Mr. Dummy Development request from Controlling: Please sort the flights in our flight booking system by price (ascending) so that all employees will most likely choose the cheapest flight.
SAP AG 2004, SAP TechEd / ABAP201 / 5

ABAP Unit What Should I Know ?


What is ABAP Unit?
ABAP Unit is the ABAP framework for module/unit tests.

What is an Unit?
An unit can be considered as a non-trivial, accessible code portion (method, function or form) where a given input or action causes a verifiable effect. Ideally it is the smallest code part which can be tested in isolation.

How does an ABAP Unit test looks like?


The ABAP Unit tests are realized as methods of a local class (with the addition FOR TESTING). This local class is part of the class, function group or program you want to test.

SAP AG 2004, SAP TechEd / ABAP201 / 6

ABAP UNIT What Should I Know ?


Why is the test class part of the productive code?
ABAP Unit tests and the linked production code are in sync In a productive system the ABAP Unit tests are not part of the productive program load. (-> No performance or security drawbacks)

Which services are provided by ABAP UNIT?


ABAP Unit provides a service class CL_AUNIT_ASSERT, which contains static methods (e.g. ASSERT_EQUALS) to compare e.g. strings or internal tables in order to verify test results.

SAP AG 2004, SAP TechEd / ABAP201 / 7

ABAP Unit A Little Story (Version 2)


This time the flight system is verified by ABAP Unit tests. Lets see how this will influence the fate of Mr. Dummy.

SAP AG 2004, SAP TechEd / ABAP201 / 8

Still Need of Integration and System Testing

SAP AG 2004, SAP TechEd / ABAP201 / 9

Thank you

Test a lot, test well, be on the safe side!

SAP AG 2004, SAP TechEd / ABAP201 / 10

Checkpoints in ABAP

SAP AG 2004, SAP TechEd / ABAP201 / 11

Checkpoints in ABAP
Task: Create utility for reversing strings

Examples:
'ABC' 'OTTO' -> 'CBA' -> 'OTTO' '12345' -> '54321'

SAP AG 2004, SAP TechEd / ABAP201 / 12

Checkpoints in ABAP

Demo

SAP AG 2004, SAP TechEd / ABAP201 / 13

Checkpoints in ABAP

system state

consistent state program flow

SAP AG 2004, SAP TechEd / ABAP201 / 14

normal termination

Checkpoints in ABAP

system state

unexpected behavior

consistent state program flow

SAP AG 2004, SAP TechEd / ABAP201 / 15

normal termination

Checkpoints in ABAP

system state

system state

unexpected behavior

: assertion runtime error normal termination

consistent state program flow

normal termination

consistent state program flow

find cause of error in shorter time

SAP AG 2004, SAP TechEd / ABAP201 / 16

Checkpoints in ABAP

system state

undetected error normal termination

system state

: assertion

consistent state program flow

consistent state program flow

find more errors

enhance program correctness

SAP AG 2004, SAP TechEd / ABAP201 / 17

normal termination

runtime error

Checkpoints in ABAP

ASSERT - Statement:
ASSERT ID SUBKEY FIELDS CONDITION group subkey dobj1 dobj2 ... log_exp.

BREAK-POINT - Statement:
BREAK-POINT ID group.

SAP AG 2004, SAP TechEd / ABAP201 / 18

Checkpoints in ABAP

Demo

SAP AG 2004, SAP TechEd / ABAP201 / 19

Checkpoints in ABAP
Activation method
dynamic, while system is running

Activation granularity
Logical checkpoint groups Compose variants from Checkpoint groups, variants, All checkpoints in programs, function groups, classes Extract checkpoint groups from programs, function groups, classes, packages, development components User, server

Assertion mechanism
Abort, debug or protocol

SAP AG 2004, SAP TechEd / ABAP201 / 20

Checkpoints in ABAP

ABAP checkpoints support developers in writing correct code


Activated in SAP development systems ( abort, protocol )

Code instrumented with checkpoints is easier to support and maintain


Can be activated on the fly in productive systems ( activation for dedicated user, server )

No activation, no performance loss !!!

SAP AG 2004, SAP TechEd / ABAP201 / 21

Memory Inspector

SAP AG 2004, SAP TechEd / ABAP201 / 22

Memory Inspector: Motivation


What is the Memory Inspector ? Tool to analyze dynamic memory consumption Why do we need the Memory Inspector ? Increasing usage of dynamic memory objects, like
Internal Tables Class Instances (Objects) Strings Anonymous Data Objects

Increasing number of long-running transactions

T1

T2

T3

T4

T1

SAP AG 2004, SAP TechEd / ABAP201 / 23

Memory Inspector

Demo

SAP AG 2004, SAP TechEd / ABAP201 / 24

Memory Inspector: Features Summary


In ABAP Debugger
TopN-Consumer-Lists
Aggregation of types (class/data) Find References

Memory consumption overview

In Stand-Alone TA
Analyzing memory snapshots Comparing memory snapshots
Growth of memory objects in different views

Available in Release 6.20 ( SP 29, Sept.2003 )

SAP AG 2004, SAP TechEd / ABAP201 / 25

Shared Objects

SAP AG 2004, SAP TechEd / ABAP201 / 26

Data Access without Buffering

Common data
DB computed and/or copied for each user session Common Data User X Session Common Data User Y Session

SAP AG 2004, SAP TechEd / ABAP201 / 27

Data Access with Buffering


EXPORT

Shared Memory

DB

Common Data

Common data
computed once exported (copied) to shared memory imported (copied) into each user session

IMPORT

Common Data User X Session

Common Data User Y Session

SAP AG 2004, SAP TechEd / ABAP201 / 28

Data Access with Shared Objects


Attach for Write Shared Memory

DB

Common Data

Common data
computed once written in place in shared memory accessed without copying by a read attach

Attach for read

User X Session

User Y Session

SAP AG 2004, SAP TechEd / ABAP201 / 29

Areas and Area Instances Shared Objects memory


Part of the shared memory Shared Memory Shared Objects Memory Area I n s t a n c e I n s t a n c e Area I n s t a n c e

Shared Objects areas


Organizational units Defined at design time

Shared Objects area instances


Content stored at runtime Identified by unique name

SAP AG 2004, SAP TechEd / ABAP201 / 30

Working with Area Instances

Attach for write Fill the contents

Instance Root

SAP AG 2004, SAP TechEd / ABAP201 / 31

Working with Area Instances

Attach for write Fill the contents Commit changes

Instance Root

SAP AG 2004, SAP TechEd / ABAP201 / 32

Working with Area Instances

Attach for write Fill the contents Commit changes Attach reader1

Instance Root

SAP AG 2004, SAP TechEd / ABAP201 / 33

Working with Area Instances

Attach for write Fill the contents Commit changes Attach reader1 Attach reader2

Instance Root

SAP AG 2004, SAP TechEd / ABAP201 / 34

Working with Area Instances

Attach for write Fill the contents Commit changes Attach reader1 Attach reader2 Detach reader1

Instance Root

SAP AG 2004, SAP TechEd / ABAP201 / 35

Working with Area Instances

Attach for write Fill the contents Commit changes Attach reader1 Attach reader2 Detach reader1 Detach reader2

Instance Root

SAP AG 2004, SAP TechEd / ABAP201 / 36

Shared Objects

Demo

SAP AG 2004, SAP TechEd / ABAP201 / 37

Additional Features Versioning Auto-Build (e.g. at 1st read attach) Transactionality Propagation of area invalidation across AppServer instances Client dependency Displacement Customizable memory and lifetime restrictions Multi-Attach to different areas at once

SAP AG 2004, SAP TechEd / ABAP201 / 38

Generic Programming

SAP AG 2004, SAP TechEd / ABAP201 / 39

Challenging Development Request


Senior management wants a generic table display tool where they can display joined tables freely. e.g. Flight connection and Carrier IDs or Flights and bookings or

SAP AG 2004, SAP TechEd / ABAP201 / 40

Problem Analysis
Selecting the Data from the database: e.g. Join of SPFLI and SCARR SELECT SPFLI~MANDT SPFLI~CARRID SCARR~CURRCODE SCARR~URL FROM SPFLI join SCARR ON SPFLI~MANDT = SCARR~MANDT AND SPFLI~CARRID = SCARR~CARRID

SAP AG 2004, SAP TechEd / ABAP201 / 41

Problem Analysis
Selecting the Data from the database: e.g. Join of SFLIGHT and SBOOK SELECT SFLIGHT~MANDT SFLIGHT~CARRID SBOOK~BOOKID SBOOK~CUSTOMID FROM SFLIGHT join SBOOK ON SFLIGHT~MANDT = SBOOK~MANDT AND SFLIGHT~CARRID = SBOOK~CARRID AND SFLIGHT-CONNID = SBOOK-CONNID.

SAP AG 2004, SAP TechEd / ABAP201 / 42

Problem Solution Step 1


How shall I cover all these different SELECTS in one program ?

Use Dynamic Open SQL:


SELECT (select_clause_it) FROM (from_clause).
Dr. ABAP
SAP AG 2004, SAP TechEd / ABAP201 / 43

Problem Solution Step 2


Nice, but where do I get the DB table components from ?

Dr. ABAP

Use RTTS:
struct_type ?= cl_abap_typedescr=>describe_by_name( dbtable ). components = struct_type->get_components( ).

SAP AG 2004, SAP TechEd / ABAP201 / 44

RTTS Class Hierarchy


CL_ABAP_TYPEDESCR CL_ABAP_TYPEDESCR

CL_ABAP_DATADESCR CL_ABAP_DATADESCR

CL_ABAP_OBJECTDESCR CL_ABAP_OBJECTDESCR

CL_ABAP_ELEMDESCR CL_ABAP_ELEMDESCR CL_ABAP_REFDESCR CL_ABAP_REFDESCR

CL_ABAP_INTFDESCR CL_ABAP_INTFDESCR CL_ABAP_CLASSDESCR CL_ABAP_CLASSDESCR

CL_ABAP_COMPLEXDESCR CL_ABAP_COMPLEXDESCR

CL_ABAP_STRUCTDESCR CL_ABAP_STRUCTDESCR

CL_ABAP_TABLEDESCR CL_ABAP_TABLEDESCR

SAP AG 2004, SAP TechEd / ABAP201 / 45

Problem Solution Step 3

SELECT (select_clause) INTO TABLE ITAB FROM (from_clause).

Perfect, but now we are lost ! For each DB table combination I need a result table ITAB with totally different components!

SAP AG 2004, SAP TechEd / ABAP201 / 46

Problem Solution Step 3

Create the internal table you need during runtime !

Dr. ABAP

SAP AG 2004, SAP TechEd / ABAP201 / 47

RTTS Class Hierarchy


CL_ABAP_TYPEDESCR CL_ABAP_TYPEDESCR

CL_ABAP_DATADESCR CL_ABAP_DATADESCR

CL_ABAP_OBJECTDESCR CL_ABAP_OBJECTDESCR

CL_ABAP_ELEMDESCR CL_ABAP_ELEMDESCR CL_ABAP_REFDESCR CL_ABAP_REFDESCR

CL_ABAP_INTFDESCR CL_ABAP_INTFDESCR CL_ABAP_CLASSDESCR CL_ABAP_CLASSDESCR

method CREATE

CL_ABAP_COMPLEXDESCR CL_ABAP_COMPLEXDESCR

CL_ABAP_STRUCTDESCR CL_ABAP_STRUCTDESCR

CL_ABAP_TABLEDESCR CL_ABAP_TABLEDESCR

method CREATE
SAP AG 2004, SAP TechEd / ABAP201 / 48

method CREATE

Working with Type Objects

Getting type objects


CL_ABAP_STRUCTDESCR

by name (method: describe_by_name) by creation (method: create)

struc

name age

o o

TYPES: BEGIN OF struc, name TYPE string, age TYPE i, END OF struc.

SAP AG 2004, SAP TechEd / ABAP201 / 49

Working with Type Objects

Getting type objects


CL_ABAP_STRUCTDESCR

by name (method: describe_by_name) by creation (method: create)

struc

name age

o o

Working with type objects

TYPES: BEGIN OF struc, name TYPE string, age TYPE i, END OF struc.

CREATE DATA ... TYPE HANDLE ... ASSIGN ... CASTING TYPE HANDLE ...

SAP AG 2004, SAP TechEd / ABAP201 / 50

Dynamic Type Creation

Demo

SAP AG 2004, SAP TechEd / ABAP201 / 51

Simple Transformations

SAP AG 2004, SAP TechEd / ABAP201 / 52

XML Mapping Tasks in ABAP

XS LT

ABAP Data

in ew n 6.40

XML Doc
.. . . .. .. . . .. . .. ..

LT XS

Simple Transformations

Network

XSLT
XS LT
DB

SAP AG 2004, SAP TechEd / ABAP201 / 53

L XS T
.. . . .. .. . . ..

HTML / Text

ABAP / XML Mapping Languages


XSLT (since 6.10)
works on canonical XML representation of ABAP data (asXML) builds DOM for source side arbitrarily complex transformations
basis of: XI 2.0

Simple Transformations (since 6.40)


only for ABAP XML only linear transformations (no DOM) speedup over XSLT: 10 30; unlimited size of data reversible (one program for both directions)
basis of: XI 3.0 / Web Services

Both
symmetric: no generation of ABAP code / XML schemas integrated in workbench (maintenance / transport) integrated in ABAP: CALL TRANSFORMATION

SAP AG 2004, SAP TechEd / ABAP201 / 54

Simple Transformations

Demo

SAP AG 2004, SAP TechEd / ABAP201 / 55

ABAP / XML: When To Use What

System Landscape Integration


Exchange Infrastructure

SOAP-Based Web Services


ABAP Web Services

Direct XML Processing in ABAP


REST-Based Web Services (in: URI, out: XML) e.g.:
http://xml.amazon.com/onca/xml3?locale=us&t=te&dev-t=te&KeywordSearch=ABAP&mode=books&type=lite&f=xml

Custom XML Persistence XML-Based Repositories (e.g. SAP WebDynpro)


Simple mappings, high throughput

Simple Transformations
Complex mappings, limited throughput

XSLT

SAP AG 2004, SAP TechEd / ABAP201 / 56

ABAP Debugger

SAP AG 2004, SAP TechEd / ABAP201 / 57

ABAP Debugger - Our Little Story Continues


Manager Some years after the dismissal of Mr. Dummy we visit again our company XYZ. Mr. Smith, the successor of Mr. Dummy, was promoted and is now manager of all ABAP developers. He wants to book a flight for a business trip. He uses the new version of their internal flight booking system, which was developed by his premium developer.

Premium Developer
SAP AG 2004, SAP TechEd / ABAP201 / 58

New ABAP Debugger Outlook

Please note that this document is subject to change and may be changed by SAP at any time without notice. The document is not intended to be binding upon SAP to any particular course of business, product strategy and/or development.
SAP AG 2004, SAP TechEd / ABAP201 / 59

Further Information
Public Web:
www.sap.com SAP Developer Network: www.sdn.sap.com Search for ABAP Knowledge Center SAP Customer Services Network: www.sap.com/services/

Related SAP Education Training Opportunities


http://www.sap.com/education/

Related Workshops/Lectures at SAP TechEd 2004


ABAP UNIT, Checkpoints ABAP254, New Dynamik Test Tools for ABAP Developers , 4h Hands-on New ABAP Debugger, Memory Inspector ABAP255, New ABAP Debugger and Memory Inspector, 2h Hands-on

SAP AG 2004, SAP TechEd / ABAP201 / 60

Further Information
Related Workshops/Lectures at SAP TechEd 2004
Shared Objects ABAP251, ABAP Shared Objects, Shared Memory Programming Made Easy, 4h Hands on Simple Transformations ABAP252, ABAP - XML Mapping, 4h Hands-on Generic Programming ABAP351, Advanced & Generic Programming in ABAP, 4h Hands-on ABAP Troubleshooting ABAP253, ABAP Troubleshooting, 4h Hands on

SAP AG 2004, SAP TechEd / ABAP201 / 61

SAP Developer Network


Look for SAP TechEd 04 presentations and videos on the SAP Developer Network. Coming in December. http://www.sdn.sap.com/

SAP AG 2004, SAP TechEd / ABAP201 / 62

Questions?

Q&A
SAP AG 2004, SAP TechEd / ABAP201 / 63

Feedback
Please complete your session evaluation. Be courteous deposit your trash, and do not take the handouts for the following session.

Thank You !

SAP AG 2004, SAP TechEd / ABAP201 / 64

Copyright 2004 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. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, and Informix are trademarks or registered trademarks of IBM Corporation in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver 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 are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group 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.
SAP AG 2004, SAP TechEd / ABAP201 / 65

You might also like