




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An introduction to object-oriented programming (oop) in abap, specifically using abap objects. It covers the basics of oop, class definition, attribute definition, method definition, constructor, and object creation. Abap objects is similar to languages like c++ and java and supports inheritance, polymorphism, and events. It is divided into class definition and class implementation, and attributes can be designated as public or private.
Typology: Slides
1 / 8
This page cannot be seen from the preview
Don't miss anything!
Class Definition Attributes Methods
Simple Object Instantiation
Object Oriented ABAP Development
OO often considered superior to procedural programming due to encapsulation of data with related functionality.
ABAP Objects similar conceptually to languages like C++ and Java.
Backwards compatible with procedural ABAP, so objects can be used in procedural coding.
Some language constructs considered deprecated (yet still supported in procedural ABAP) are disallowed in ABAP objects.
Just as in other OO languages, ABAP Objects supports:
Inheritance —one class shares structure and behavior with another Polymorphism —different (but related) objects have the same communication interface Events —objects respond when triggered. Objects can trigger an event.
OO ABAP
Class —definition of the structure and functionality of an object-to-be. Defines data the object will contain ( attributes ) and related functionality ( methods ). ABAP class syntax divides the class definition (containing attribute declarations and method interface definitions) and the class implementation (method functionality definitions).
Can be defined locally or globally (using Class Builder trans SE24).
Object —instantiation of a class, storing actual data and/or allowing method execution.
CLASS exampleclass DEFINITION.
ENDCLASS.
CLASS exampleclass IMPLEMENTATION.
ENDCLASS.
Quick Practice
Method Definition
In the class definition , the method definition indicates a method's interface. Method parameters Method return type ( method signature ) Method exception (to be covered later)
Methods may be designated as public or private. A private method may only be called from within another method of the class.
CLASS-METHODS may be defined. These methods may only access static attributes. Class methods may be invoked either using the name of the class or on an object of the class. An object does not need to be instantiated to invoke a class method.
Method Parameters
Method parameter types: IMPORTING—input parameters Used to transfer data to a method. May be designated as OPTIONAL. May have a DEFAULT value specified. Value of parameter may not be changed in method definition. (system enforced) EXPORTING—output parameters At end of method value of formal parameter copied back to actual. Export parameters are always optional (by default). Intent is for the incoming value of the parameter to not be used ( not system enforced). CHANGING—combination of above Passed to method for use. Can be changed. May be designated as OPTIONAL. May have a DEFAULT value specified. With any of the above, parameters may be designated pass by value.
Method return values
A method may be defined to return a single value.
This is specified by listing RETURNING in the interface.
If RETURNING is indicated, EXPORTING and CHANGING parameters may not be specified.
The return operation is not done with an explicit RETURN statement but rather by assigning a value to the name of the data object listed in the RETURNING statement.
A method with a return value is called a functional method. Unlike other methods, functional methods they can be called within other statements such as IF, CASE, and WHILE.
Constructor
A class may define a constructor method named constructor.
The method must be public and only have importing parameters.
The constructor is not called explicitly, but rather is called implicitly when a new object is created.
Constructors are useful for:
Initializing attributes for an object. Allocating resources for the object. Modifying static attributes (programmatically). Triggering other activities that need to happen when a new object is created.
A static constructor method can be created named class_constructor. This method will be called first time an object of this class is created or a static attribute or static method of the class is used.
Self-reference
Within a method, reference to object attributes or other methods is generally unambiguous. In the event of ambiguity (a parameter has the same name as an attribute), you can refer to the object, its attributes, and its methods using me. Syntax: me->attributename
Quick Practice
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.
Further instantiation details (showing parameter) passing shown in the lesson immediately following.