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.


Let’s 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' -> 'CBA'
'12345' -> '54321'
'OTTO' -> 'OTTO'

© SAP AG 2004, SAP TechEd / ABAP201 / 12


Checkpoints in ABAP

Demo

© SAP AG 2004, SAP TechEd / ABAP201 / 13


Checkpoints in ABAP
system state

normal termination
consistent state

program flow

© SAP AG 2004, SAP TechEd / ABAP201 / 14


Checkpoints in ABAP

unexpected
behavior
system state

normal termination
consistent state

program flow

© SAP AG 2004, SAP TechEd / ABAP201 / 15


Checkpoints in ABAP

unexpected
: assertion
behavior
system state

system state
runtime
error

normal termination
normal termination
consistent state consistent state

program flow program flow

Æ find cause of error in shorter time

© SAP AG 2004, SAP TechEd / ABAP201 / 16


Checkpoints in ABAP

: assertion
system state

system state
undetected
error
runtime

normal termination
normal termination
error

consistent state consistent state

program flow program flow

Æ find more errors Æ enhance program correctness

© SAP AG 2004, SAP TechEd / ABAP201 / 17


Checkpoints in ABAP

ASSERT - Statement:
ASSERT ID group
SUBKEY subkey
FIELDS dobj1 dobj2 ...
CONDITION 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 Strings
Class Instances (Objects) 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 Common
Data Data

User X User Y
Session Session

© SAP AG 2004, SAP TechEd / ABAP201 / 27


Data Access with Buffering

EXPORT Shared Memory


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

User X User Y
Session Session

© SAP AG 2004, SAP TechEd / ABAP201 / 28


Data Access with Shared Objects

Attach for Write


Shared Memory
Common data
Common
DB Data „ computed once
„ written in place in
shared memory
Attach for read
„ accessed without
copying by a read
attach

User X User Y
Session Session

© SAP AG 2004, SAP TechEd / ABAP201 / 29


Areas and Area Instances

Shared Objects memory Shared Memory


„ Part of the shared memory Shared Objects Memory

Shared Objects areas


Area Area
„ Organizational units
I
„ Defined at design time n I
s I n
t n s
Shared Objects area instances a s t
n t a
„ Content stored at runtime c a n
e n c
„ Identified by unique name c e
e

© SAP AG 2004, SAP TechEd / ABAP201 / 30


Working with Area Instances

Attach for write Instance


Fill the contents Root

© SAP AG 2004, SAP TechEd / ABAP201 / 31


Working with Area Instances

Attach for write Instance


Fill the contents Root

Commit changes

© SAP AG 2004, SAP TechEd / ABAP201 / 32


Working with Area Instances

Attach for write Instance


Fill the contents Root

Commit changes

Attach reader1

© SAP AG 2004, SAP TechEd / ABAP201 / 33


Working with Area Instances

Attach for write Instance


Fill the contents Root

Commit changes

Attach reader1
Attach reader2

© SAP AG 2004, SAP TechEd / ABAP201 / 34


Working with Area Instances

Attach for write Instance


Fill the contents Root

Commit changes

Attach reader1
Attach reader2

Detach reader1

© SAP AG 2004, SAP TechEd / ABAP201 / 35


Working with Area Instances

Attach for write Instance


Fill the contents Root

Commit changes

Attach reader1
Attach reader2

Detach reader1
Detach reader2

© 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_INTFDESCR
CL_ABAP_INTFDESCR
CL_ABAP_ELEMDESCR

CL_ABAP_CLASSDESCR
CL_ABAP_CLASSDESCR
CL_ABAP_REFDESCR
CL_ABAP_REFDESCR

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 Perfect, but now we are lost !
(from_clause).
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_INTFDESCR
CL_ABAP_INTFDESCR
CL_ABAP_ELEMDESCR

CL_ABAP_CLASSDESCR
CL_ABAP_CLASSDESCR
CL_ABAP_REFDESCR
CL_ABAP_REFDESCR

method CREATE CL_ABAP_COMPLEXDESCR


CL_ABAP_COMPLEXDESCR

CL_ABAP_STRUCTDESCR
CL_ABAP_STRUCTDESCR CL_ABAP_TABLEDESCR
CL_ABAP_TABLEDESCR

method CREATE method CREATE

© SAP AG 2004, SAP TechEd / ABAP201 / 48


Working with Type Objects

Getting type objects


CL_ABAP_STRUCTDESCR

„ by name (method: describe_by_name) struc name


age
o
o

„ by creation (method: create)

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) struc name


age
o
o

„ by creation (method: create)

TYPES: BEGIN OF struc,


name TYPE string,
age TYPE i,
Working with type objects 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

ABAP in
XML
Data new
6.40
Doc

XS
LT

LT
Simple
XS

Transformations … .. ….
…. … ..
.. …. …. ..
… …. .. .. Network

XSLT

DB
XS

LT
L

XS
T

… .. ….
…. … ..
.. …. …. ..

HTML / Text

© SAP AG 2004, SAP TechEd / ABAP201 / 53


ABAP / XML Mapping Languages

XSLT (since 6.10)


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

Simple Transformations (since 6.40)


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

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…
Some years after the dismissal of Mr. Dummy
we visit again our company XYZ.
Manager
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