Professional Documents
Culture Documents
Learning Objectives
Agenda
Background
Conclusion
Next Topic
Background
Conclusion
Background History
User Interface
(SAP GUI, Web, ...)
ABAP
Web
...
SELECT * FROM ... Application
... Server
ABAP Objects
Persistent Data
(Database, Files, ...)
Pure
Object
Oriented
ABAP
World ?
ABAP Non-ABAP
Technically possible!
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 7
Objects
with
Application
Logic
ABAP
Persistence and
Transaction
Services
provided by
ABAP Object Services,
as of
Release 6.10
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 9
GUI Control
Framework,
Office
Integration,
Business
Server
Pages,
etc.
ABAP
ABAP Non-ABAP
System
Application Classes
Coding from
is here! Libraries
Inside Objects?
METHOD...
DATA ... TYPE ...
...
LOOP AT itab
REFERENCE INTO ...
...
ENDMETHOD.
Purified ABAP
Reality ...
CALL
SCREEN
...
CALL
FUNCTION
DESTINATION
...
SELECT
...
ABAP Non-ABAP
Next Topic
Background
Conclusion
No local data
PROCESS ON ...
MODULE ...
MODULE ...
...
...
ENDMODULE.
START-OF-SELECTION
...
No local data
Runtime
Environment Dynpro ABAP Program
FORM ...
FORM ... DATA ...
DATA ... ... Local data
... Local data SELECT * FROM ...
ENDFORM. ...
ENDFORM.
ABAP Program Function Group
Encapsulation
FUNCTION-POOL account. of an account
DATA current_amount TYPE accounts-amount.
FUNCTION deposit.
current_amount = current_amount + amount. Function
ENDFUNCTION. modules
work with
one account
FUNCTION withdraw.
IF current_amount > amount.
current_amount = current_amount - amount.
ELSE.
RAISE EXCEPTION TYPE cx_negative_amount.
ENDIF.
No possibility
ENDFUNCTION. to interact
with other
accounts
Function Group
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 18
FUNCTION-POOL account.
DATA account_tab TYPE SORTED TABLE OF accounts
WITH UNIQUE KEY id.
All data in
LOAD-OF-PROGRAM. one table
SELECT * FROM accounts
INTO TABLE account_tab.
FUNCTION deposit.
DATA account_wa TYPE accounts.
READ TABLE account_tab INTO account_wa
Function
WITH TABLE KEY id = id. modules
account_wa-amount = account_wa-amount + amount. work on
MODIFY TABLE account_tab FROM account_wa.
shared data
ENDFUNCTION.
Function Group
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 19
FUNCTION withdraw.
DATA account_wa TYPE accounts.
READ TABLE account_tab INTO account_wa
WITH TABLE KEY id = id.
IF account_wa-amount > amount.
account_wa-amount = account_wa-amount - amount.
MODIFY TABLE account_tab FROM account_wa.
ELSE.
RAISE EXCEPTION TYPE cx_negative_amount.
ENDIF.
ENDFUNCTION.
FUNCTION transfer.
CALL FUNCTION 'WITHDRAW' Data
EXPORTING identified by
id = id_from input
amount = amount.
CALL FUNCTION 'DEPOSIT' parameters
EXPORTING
id = id_to
amount = amount.
ENDFUNCTION.
Function Group
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 20
Classes
A class unites
functionality
with data
CLASS account DEFINITION.
PUBLIC SECTION.
METHODS: constructor IMPORTING id TYPE accounts-id,
deposit IMPORTING amount TYPE accounts-amount,
withdraw IMPORTING amount TYPE accounts-amount
RAISING cx_negative_amount,
transfer IMPORTING amount TYPE accounts-amount
target TYPE REF TO account
RAISING cx_negative_amount.
PRIVATE SECTION.
DATA amount TYPE accounts-amount. Only data
ENDCLASS. relevant for one
object is
needed
Class Pool
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 22
Class Pool
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 23
Next Topic
Background
Conclusion
Instantiation ABAP/4
TRY.
id1 = ...
Business
id2 = ...
amnt = ... keys identify
CALL FUNCTION 'TRANSFER' data
EXPORTING
id_from = id1
id_to = id2
amount = amnt.
No static
CATCH cx_negative_amount INTO exc_ref. type check
text = exc_ref->get_text( ).
MESSAGE text TYPE 'I'.
ENDTRY.
ABAP Program
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 26
Instances of
classes with
attributes and Explicit
an identity instantiation,
control of
lifetime
Object
DATA: account1 TYPE REF TO account,
reference
account2 TYPE REF TO account, variables as
amnt TYPE p DECIMALS 2, explicit handles
exc_ref TYPE REF TO cx_negative_amount,
text TYPE string.
CREATE OBJECT: account1 EXPORTING id = ..., Independent
account2 EXPORTING id = ... objects based
TRY. on the same
amnt = ... class
account1->transfer( EXPORTING amount = amnt
target = account2 ).
CATCH cx_negative_amount INTO exc_ref.
text = exc_ref->get_text( ). Static type
MESSAGE text TYPE 'I'.
ENDTRY. check
Natural
working with
instances
ABAP Program
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 28
Next Topic
Background
Conclusion
Reuse ABAP/4
FUNCTION withdraw.
*"--------------------------------------------------------------
*" IMPORTING
*" REFERENCE(ID) TYPE ACCOUNTS-ID Steering
*" REFERENCE(KIND) TYPE C DEFAULT 'C
*" REFERENCE(AMOUNT) TYPE ACCOUNTS-AMOUNT parameters
*" RAISING
*" CX_NEGATIVE_AMOUNT
*" CX_UNKNOWN_ACCOUNT_TYPE Additional
*"--------------------------------------------------------------exception
CASE kind.
WHEN 'C'. Checking account
PERFORM withdraw_from_checking_account USING id amount.
WHEN 'S'. "Savings account
PERFORM withdraw_from_saving_account USING id amount.
WHEN OTHERS.
RAISE EXCEPTION TYPE cx_unknown_account_type.
ENDCASE. Procedure
ENDFUNCTION. calls with
parameter
passing
Function Group
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 31
FORM withdraw_from_checking_account
USING l_id TYPE accounts-id
l_amount TYPE accounts-amount.
DATA account_wa TYPE accounts.
READ TABLE account_tab INTO account_wa WITH TABLE KEY id = l_id.
account_wa-amount = account_wa-amount - l_amount.
MODIFY TABLE account_tab FROM account_wa.
IF account_wa-amount < 0.
... " handle debit balance
ENDIF.
ENDFORM. Specialized
FORM withdraw_from_savings_account procedures,
USING l_id TYPE accounts-id no code
l_amount TYPE accounts-amount
RAISING cx_negative_amount. reuse
DATA account_wa TYPE accounts.
READ TABLE account_tab INTO account_wa WITH TABLE KEY id = l_id.
IF account_wa-amount > l_amount.
account_wa-amount = account_wa-amount - l_amount.
MODIFY TABLE account_tab FROM account_wa.
ELSE.
RAISE EXCEPTION TYPE cx_negative_amount.
ENDIF.
ENDFORM.
Function Group
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 32
General superclass
CLASS account DEFINITION.
PUBLIC SECTION.
...
PROTECTED SECTION.
DATA amount TYPE accounts-amount.
Data sharing
ENDCLASS. with subclasses
Class Pool
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 34
Special subclass
CLASS checking_account DEFINITION
INHERITING FROM account.
PUBLIC SECTION.
METHODS withdraw REDEFINITION. Method
ENDCLASS. redefinition
Class Pool
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 35
Special subclass
CLASS savings_account DEFINITION
INHERITING FROM account.
PUBLIC SECTION.
METHODS withdraw REDEFINITION. Method
ENDCLASS. redefinition
Class Pool
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 36
Same object
DATA: account1 TYPE REF TO account,
account2 TYPE REF TO account,
reference
amnt TYPE p DECIMALS 2, variables as
exc_ref TYPE REF TO cx_negative_amount, before
text TYPE string.
CREATE OBJECT: account1 TYPE checking_account
EXPORTING id = ..., General
account2 TYPE savings_account handles for
EXPORTING id = ... specialized
TRY. objects
amnt = ...
account1->transfer( EXPORTING amount = amnt
target = account2 ).
CATCH cx_negative_amount INTO exc_ref.
text = exc_ref->get_text( ).
Same usage of
MESSAGE text TYPE 'I'.
ENDTRY. objects as
before!
Polymorphism
ABAP Program
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 37
Next Topic
Background
Conclusion
Interfaces ABAP/4
Standalone Interfaces
INTERFACE if1. INTERFACE if2.
METHODS: m1 ... METHODS: m2 ...
... ...
ENDINTERFACE. ENDINTERFACE.
CLASS cl_....
INTERFACES: if1,
if2.
...
ENDINTERFACE. METHOD
if1~m1.
...
METHOD
if2~m2.
oref1 oref2 ...
DATA:
oref1 TYPE REF TO if1,
oref2 TYPE REF TO if2.
Class Pool
One interface in
different
classes
CLASS customer DEFINITION.
PUBLIC SECTION.
INTERFACES if_serializable_object.
...
ENDCLASS.
Class Pool
Interface
reference
DATA: account TYPE REF TO account,
customer TYPE REF TO customer, variables
serializable_objects TYPE TABLE
OF REF TO if_serializable_object,
serializable_object TYPE REF TO if_serializable_object,
xmlstr TYPE string.
CREATE OBJECT: account EXPORTING id = ...,
customer. Instantiation of
classes
APPEND: account TO serializable_objects,
customer TO serializable_objects.
... Collection of
LOOP AT serializable_objects INTO serializable_object. references to
CALL TRANSFORMATION id objects of
SOURCE obj = serializable_object different classes
RESULT XML xmlstr.
ENDLOOP.
Polymorphism
ABAP Program
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 44
Next Topic
Background
Conclusion
Events ABAP/4
oref2
oref1
METHOD...
...
SET HANDLER
oref1->handler FOR oref2.
...
ENDMETHOD.
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 47
Class Pool
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 49
Class Pool
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 50
Next Topic
Background
Conclusion
REPORT simple_report.
NODES spfli.
GET spfli.
WRITE: / spfli-carrid, spfli-connid ...
ABAP Program
AT LINE-SELECTION, ...
Next Topic
Background
Conclusion
Explicitness
Logical Databases
Explicit event
CLASS report DEFINITION.
PUBLIC SECTION.
handling
METHODS start.
PRIVATE SECTION.
DATA spfli_tab TYPE TABLE OF spfli.
METHODS: get_spfli FOR EVENT spfli_ready OF ldb
IMPORTING values,
display_spfli.
ENDCLASS. Decoupling of data
display from data
ABAP Program handling
ABAP Program
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 59
Next Topic
Background
Conclusion
Maintainability
more reliable
encapsulation
secure typing
surprise free
Next Topic
Background
Conclusion
DATA BEGIN OF itab OCCURS 10. DATA itab TYPE TABLE OF ...
... ...
CLEAR itab. CLEAR itab.
Inappropriate
ABAP/4 ABAP Objects
short forms
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 66
Unicode-enabled ABAP
Static type checks specified more precisely
Byte and character strings processed separately
Structures handled appropriately for their type
using structural equivalence rules
Uncontrolled memory manipulation no longer
permitted
Unicode-enabled ABAP
Structures are assigned fragment by fragment
DATA: BEGIN OF struc1,
col1(2) TYPE c VALUE 'AB',
col2(2) TYPE c VALUE 'CD',
END OF struc1.
DATA: BEGIN OF struc2, Code page
col1(4) TYPE c, dependent
col2 TYPE i, representation of
END OF struc2.
blanks
struc2 = struc1.
Type specific
Unicode-enabled ABAP
No access to memory outside a data object
DATA: text1(10) TYPE c,
text2(10) TYPE c VALUE 'ABCDEFGHIJ',
off TYPE i.
FIELD-SYMBOLS <fs> TYPE c.
DO 15 TIMES. Memory
off = sy-index - 1.
ASSIGN text1+off(1) TO <fs>. overwriting,
IF <fs> IS ASSIGNED. even for
<fs> = 'X'. references!
ENDIF.
ENDDO.
Memory protection
SAP AG 2003, TechED_Basel / ABAP256, Horst Keller, Stefan Bresch / 71
Next Topic
Background
Conclusion
Future Orientation
Dont get
lost!
Migration
Next Topic
Background
Conclusion
Conclusion - Summary
Conclusion - Recommendation
Appendix
Further Information
ABAP Documentation:
Always the first source of information
Articles in Journals:
http://www.intelligenterp.com/feature/archive/heymann.shtml
http://www.intelligenterp.com/feature/archive/keller.shtml
http://www.sappublications.com/insider/article.htm?key=20248
Questions?
Q&A
Feedback
Thank You !
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, NT, EXCEL, Word, PowerPoint and SQL Server 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, Informix
and Informix Dynamic ServerTM are trademarks of IBM Corporation in USA 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, the Citrix logo, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, MultiWin and
other Citrix product names referenced herein are trademarks of Citrix Systems, Inc.
HTML, DHTML, XML, XHTML 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.
MarketSet and Enterprise Buyer are jointly owned trademarks of SAP AG and Commerce One.
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.