ABAP Objects, part 2 - East Tennessee State University

9 downloads 147 Views 352KB Size Report
3/14/2011. 1. Spring 2011. Enterprise Programming. ABAP OBJECTS, PART 2. Discussion Topics. ✓ Working with static method and attributes. ✓ Object ...
3/14/2011

ABAP OBJECTS, PART 2

Spring 2011

Enterprise Programming

Discussion Topics  Working with static method and attributes  Object Instantiation

1

3/14/2011

Working with classes in programs Classes, when instantiated, become objects. Not all classes need to be instantiated to be used within programs. Static attributes (CLASS-DATA) Static methods (CLASS-METHODS) To reference a static public attribute: classname=>attributename myvar = classname=>attributename To call a static method: CALL METHOD classname=>methodname. "traditional classname=>methodname( ). "as of Web AS 6.10 Static vs. instance: Static uses => Instance uses -> Other syntax elements are the same.

Calling methods Cannot be a space before opening parenthesis. Must be one after. If only one importing parameter in method definition, list the actual parameter in the parenthesis by listing data object name only. class=>method( data1 ). If several importing parameters, parameters must be listed in pairs: formal parameter = actual parameter. class=>method( par1 = data1 par2 = data2 ). If there are parameters of types other than importing, the type of parameter passing must be listed. class=>method( EXPORTING p1 = d1 p2 = d2 IMPORTING par3 = data3 CHANGING par4 = data4 ).

2

3/14/2011

Calling methods Functional methods (those that return a value) The value to be returned by be listed in the method call interface using the parameter passing type RECEIVING. class=>method( IMPORTING p1 = d1 RECEIVING par4 = data4 ). The value to be returned may be captured through assignment (more typical). data3 = class=>method( d1 ).

Calling methods Parameter passing types defined in the method definition correspond to parameter passing types in the caller but are not the same. Method Definition

Method Call

IMPORTING

EXPORTING

EXPORTING

IMPORTING

CHANGING

CHANGING

RETURNING

RECEIVING

I am exporting a value to you Method Call

I am importing a value from you Method Definition

3

3/14/2011

Let's Practice

Static Rules Static methods can only access static attributes. Static method may define local data objects. Instance methods can access static and instance attributes.

4

3/14/2011

Object Creation Objects are created by defining an object reference variable and then creating the object. The START-OF-SELECTION keyword indicates where the runtime environment should begin control flow. * Object definitions here START-OF-SELECTION. DATA objectname TYPE REF TO classname. CREATE OBJECT objectname.

Copyrights Presentation prepared by and copyright of Dr. Tony Pittarese, East Tennessee State University, Computer and Information Sciences Dept. ([email protected]) Podcast lecture related to this presentation available via ETSU iTunesU. Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation. Linux is the registered trademark of Linus Torvalds in the U.S. and other countries. Oracle is a registered trademark of Oracle Corporation. 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. SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, 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 other countries. Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company. Other products mentioned in this presentation are trademarks of their respective owners.

5