This action might not be possible to undo. Are you sure you want to continue?
Presented by Sylendra Prasad M
OOPS in ABAP
What is Object Orientation? Attributes of Object Oriented Programming ABAP Objects How to implement classes,events... Advantages of OOP in ABAP SAP Business Objects Object Orientation tools in ABAP
OOPS in ABAP 2
What is Object Orientation?
Type of problem-solving method in which the software solution reflects real-world objects. Emphasis is given to data rather than to procedures Data is hidden and cannot be accessed by external functions.
Merits Of Object Orientation Complex software systems become easier to understand. OO systems are easier to scale by using the concept of reusability.
OOPS in ABAP
Attributes of Object Oriented Programming Objects Classes Data Encapsulation Inheritance Polymorphism OOPS in ABAP 4 .
parameters] destination operation parameters receiver object stimulated by message method that is to receive the message information needed for operation to be successful. customer etc ) Contains data and behaviour.OBJECTS Is any real-time entity (eg. Employee. Format of message is message:[destination.operation. Operations are done through message passing. OOPS in ABAP 5 .
Structure of Class Classes contain components. Abstract description of an object.CLASS Central element of object orientation. Components implement methods. Each component is assigned a visibility section. OOPS in ABAP 6 . Defines state and behaviour of objects.
has an interface. OOPS in ABAP 7 . Three visibility mechanisms. can interact with it. Each obj. which determines how other obj. Objs restrict visibility of their resources to other users. Private section Public section Protected section All components defined in public section are accessible to all users of the class.Data Encapsulation Protective covering preventing data and code from being defined outside the covering. methods of the class and any inherited classes.
Attributes will be hidden and user will use methods of class to manipulate the data. Interfaces completely describes how the user of the class interacts with it. OOPS in ABAP 8 . All components declared in protected section are visible to methods of the class and those classes that inherit from this class..Data Encapsulation contd. All components declared in private section are only visible in the methods of same class.
Types of Inheritance 1) 2) 3) 4) Single level Inheritance Multiple Hierarchical Hybrid OOPS in ABAP 9 . events) and replace inherited methods with its own implementation. Subclass can add new components (attributes. methods.INHERITANCE Relationship in which a class (subclass) inherits the main features of another class (superclass).
User can work with different classes in a similar way. When objects from different classes react differently to the same procedural call. regardless of their implementation. OOPS in ABAP 10 .POLYMORPHISM Comes from the Greek word “many forms”. Allows improved code organization and readability as well as creation of “extensible” programs. Allows one interface to be used for a general class of actions.
ABAP Objects Complete set of Object-Oriented statements introduced in conventional ABAP. Friends. Events ABAP Objects was completed with SAP Basis Release 4. Interfaces. Shared Objects OOPS in ABAP 11 .10.20. Dynamic Invoke Some enhancements were added with SAP Web Application Server. 6. ABAP Objects was introduced with SAP Basis Release 4. Releases 6.6 Inheritance.5 Classes.
Object Oriented enhancement of ABAP is based on models of Java and C++. OOPS in ABAP 12 .ABAP Objects contd. Runtime environment ABAP Workbench allows you to create R/3 Repository Objects like programs. Object References Used to access objects from ABAP program and contained in reference variables ( pointers to objects ).. lock objects and so on. Using Function Modules. we can encapsulate functions in different programs with defined interfaces.
<intf> should be declared before actual reference declaration occurs. Interface References are defined using the addition … TYPE REF TO <intf> in the TYPES or DATA statement. OOPS in ABAP 13 Two types of references - . It allows the user to create an instance of the class.ABAP Objects contd… Class References Interface References. Class References are defined using the addition <cref> TYPE REF TO <class> in the TYPES or DATA statement.
you can create an object using the statement CREATE OBJECT <cref>. Addressing the components of objects Instance components To access attributes <attr>: <cref> -> <attr> To access methods <meth>: CALL METHOD <cref>-> <meth> OOPS in ABAP 14 .ABAP Objects contd… After creating a reference variable for a class. This creates an instance of the object and <cref> contains the reference to the object.
you can access individual components using the keyword ME.Static components To access attributes <attr>: <class> => <attr>. For example: ME -> <attr> CALL METHOD ME -> <meth> . OOPS in ABAP 15 . To access methods <meth>: CALL METHOD <class> => <meth> Within a class.
Can be used only with that program. CL_GUI_CUSTOM_CONTAINER OOPS in ABAP 16 . Global Classes Defined in class builder SE24. Stored centrally in class library in R/3 repository. For eg. CL_GUI_ALV_GRID. Can be accessed from all programs in R/3 system.Classes in ABAP Types of Classes Local Classes Defined within ABAP program.
*declare private data. PUBLIC SECTION. OOPS in ABAP 17 . In ABAP. PRIVATE SECTION. Syntax for class definition is CLASS classname DEFINITION. ENDCLASS. Methods and Events. classes are defined between CLASS and ENDCLASS statements.Defining local classes in ABAP The main components are Attributes. *declare public variables and methods. Class definition consists of declaration and implementation parts.
OOPS in ABAP 18 .Understanding Classes contd.. *initialising the variables ENDMETHOD. ENDCLASS. METHOD CONSTRUCTOR. The syntax for class implementation is CLASS class_name IMPLEMENTATION. *write code for the defined methods ENDMETHOD. METHOD method_name.
Static attributes are declared using CLASS-DATA keyword and determine the state of the class. Can be classified into instance attributes and static attributes. Instance attributes are declared using DATA keyword and determine the state of the instance. OOPS in ABAP 19 .Understanding Class Components Attributes They are internal data variables in a class and can take any ABAP data type. Must create an object before working with instance attributes. Need not create an object before working with static attributes.
CHANGING). Like Attributes. there are instance methods and static methods. EXPORTING. Static methods are declared using CLASS-METHODS keyword and can access only static attributes of the class.Methods( Procedures) They can access all class attributes and have parameter interface similar to the Function Modules (IMPORTING. OOPS in ABAP 20 . Instance methods are declared using METHODS keyword and can access all the attributes of the class.
The syntax of using methods is METHODS <met> IMPORTING : [VALUE(] <ii> [)]TYPE type] [OPTIONAL] EXPORTING : [VALUE(] <ei> [)] TYPE type] [OPTIONAL] CHANGING : [VALUE(] <ci> [)] TYPE type] [OPTIONAL] RETURNING VALUE(<r1>) EXCEPTIONS: <ei>. The additions like IMPORTING. EXPORTING etc define attributes of interface parameters like pass-by-value (VALUE). OOPS in ABAP 21 . its type (TYPE) and if it is optional (like OPTIONAL).
OOPS in ABAP 22 . The interface parameters needn’t be specified in implementation. Calling Methods The way of addressing a method depends on the method itself and from where you are calling it. *enter the code here ENDMETHOD. The basic form of calling a method is CALL METHOD methodname. MESSAGE RAISING etc can be used. statements like RAISE <exception> .Implementing methods The syntax for implementation of a method is METHOD methodname. To handle error situations.
METHODS: CONSTRUCTOR IMPORTING: IM_EMPLOYEE_NO TYPE I IM_EMPLOYEE_NAME TYPE STRING. PUBLIC SECTION. NO TYPE I. OOPS in ABAP 23 . DISPLAY_EMPLOYEE. END OF T_EMPLOYEE. TYPES: BEGIN OF T_EMPLOYEE.Class Definition -> An Example CLASS CL_EMPLOYEE DEFINITION. NAME TYPE STRING.
G_NO_OF_EMPLOYEES = G_NO_OF_EMPLOYEES + 1. DATA G_EMPLOYEE TYPE T_EMPLOYEE. CLASS CL_EMPLOYEE IMPLEMENTATION.METHODS: DISPLAY_NO_OF_EMPLOYEES. G_EMPLOYEE-NAME = IM_EMPLOYEE_NAME. PRIVATE SECTION. DATA: G_NO_OF_EMPLOYEES TYPE I. PROTECTED SECTION. G_EMPLOYEE-NO = IM_EMPLOYEE_NO. OOPS in ABAP 24 . METHOD CONSTRUCTOR. ENDCLASS. ENDMETHOD.
G_NO_OF_EMPLOYEES. G_EMPLOYEE-NAME = IM_EMPLOYEE_NAME. OOPS in ABAP 25 . ENDMETHOD. ENDMETHOD. G_EMPLOYEE-NO = IM_EMPLOYEE_NO.Class Implementation -> An Example CLASS CL_EMPLOYEE IMPLEMENTATION. METHOD DISPLAY_NO_OF_EMPLOYEES. WRITE:/ 'Number of employees is : '. ENDCLASS. METHOD DISPLAY_EMPLOYEE. G_EMPLOYEE-NAME. G_NO_OF_EMPLOYEES = G_NO_OF_EMPLOYEES + 1. WRITE:/ 'Employee Name'. WRITE:/ ‘Employee Number’.G_EMPLOYEE_NO. METHOD CONSTRUCTOR. ENDMETHOD.
START-OF-SELECTION.DATA : G_EMPLOYEE1 TYPE REF TO LCL_EMPLOYEE. CALL METHOD G_EMPLOYEE1->DISPLAY_EMPLOYEE. CREATE OBJECT G_EMPLOYEE1 EXPORTING IM_EMPLOYEE_NO = 1 IM_EMPLOYEE_NAME = 'John Jones'. OOPS in ABAP 26 . CALL METHOD G_EMPLOYEE1->DISPLAY_ NO_OF_EMPLOYEES.
OOPS in ABAP 27 .
OOPS in ABAP 28 . any no: of handler methods can be called and the handler determines events to which it want to react.CLASS COMPONENTS contd… Events Events are used to trigger event-handler methods in objects or classes. A method of same or different class can be declared as an event handler method for the event <evt> of class <class> by giving the addition FOR EVENT <evt> OF <class>. Events of a class can be triggered in the methods of same class using RAISE EVENT statement. The link between handler and trigger is established at runtime using the statement SET HANDLER. When an event is triggered.
Triggering Events Instance events can be triggered by any method in the class while static events can be done using only static methods. Declaring Events To declare instance events. CLASS-EVENTS <evt>. a class must a) declare the event in declaration part b) trigger the event in one of its events. To declare static events. OOPS in ABAP 29 .... RAISE EVENT <evt> EXPORTING <ei> = <fi>. VALUE(<ei>) TYPE type [OPTIONAL].Handling and Triggering Events To trigger an event. EVENTS <evt> EXPORTING.
use following statement... After the RAISE EVENT statement. METHODS <meth> FOR EVENT <evt> OF <cif> IMPORTING <ei> = <fi> (for instance method). Handler methods are executed in the order in which are registered. SET HANDLER. a method must a) be defined as an event handler method for that event.. <h>.Handling Events To handle an event. To declare an event handler method. b) be registered at runtime for the event. use the following statement. To register event handler method. all registered event handler methods are executed before the next statement is processed. FOR./ OOPS in ABAP 30 .
threshold TYPE i VALUE 10. OOPS in ABAP 31 . DATA: count TYPE i. METHODS increment_counter. ENDCLASS. CLASS counter DEFINITION. PRIVATE SECTION. METHODS handle_excess FOR EVENT critical_value OF counter IMPORTING excess. ENDCLASS. PUBLIC SECTION. PUBLIC SECTION. EVENTS critical_value EXPORTING value(excess) TYPE i.Event Handling -> An example REPORT ZGAS_NEW . CLASS handler DEFINITION.
ADD 1 TO count. ENDMETHOD.CLASS counter IMPLEMENTATION. diff = count . RAISE EVENT critical_value EXPORTING excess = diff.threshold. IF count > threshold. ENDCLASS. DATA diff TYPE i. ENDIF. METHOD increment_counter. OOPS in ABAP 32 .
ENDCLASS. SET HANDLER h1->handle_excess FOR ALL INSTANCES. DO 20 TIMES. OOPS in ABAP 33 . h1 TYPE REF TO handler. WRITE: / 'Excess is'. START-OF-SELECTION. ENDMETHOD. CALL METHOD r1->increment_counter. CREATE OBJECT: r1. h1.CLASS handler IMPLEMENTATION. DATA: r1 TYPE REF TO counter. excess. METHOD handle_excess. ENDDO.
OOPS in ABAP 34 .
Static Constructors Declared using CLASS-METHODS CLASS CONSTRUCTOR. Used to initialize static attributes. OOPS in ABAP 35 .Constructors Special methods called automatically by the system to set the starting state of an object or class. Types of Constructors Instance constructors Declared using keyword METHODS CONSTRUCTOR Used to initialize instance attributes. Constructor implementation is similar to a method implementation. Called when a class is instantiated.
but may have only one superclass(single inheritance).Inheritance The statement is CLASS <subclass> DEFINTION INHERITING FROM <superclass>. OBJECT C1 C2 OOPS in ABAP 36 . A class can have more than one subclass.
but with a new implementation. OOPS in ABAP 37 . all classes form inheritance tree. which itself a subclass of another class. Redefining Methods Use the addition REDEFINITION in METHODS statement to redefine public or protected instance method in a subclass.Inheritance contd… When subclasses inherit from superclass. The method retains the name and interface.
Interfaces Exclusively describes the external point of contact. in the public section of classes. A class can implement any number of interfaces and interface can be implemented by any number of classes. Interface resolution operator(~) enables to access interface components using an object reference belonging to the class implementing the interface. Has only declaration part. but don’t contain any implementation part. OOPS in ABAP 38 .
Use the statement INTERFACE <intf> ------------------------ENDINTERFACE. Can be defined either globally in R/3 repository or locally in ABAP program. You can define the same components in an interface as in a class. Components don’t have to be assigned individually to a visibility section. Interfaces don’t have an implementation part, since their methods are implemented in the class that implements it.
OOPS in ABAP 39
Use in the declaration part of the class (public section), INTERFACES <intf>. During implementation, components are added to other components in the public section. The class must implement the methods of all interfaces implemented in it . The implementation part of the class must contain a method implementation for each interface method <imeth>: METHOD <intf~imeth> -----------------------------ENDMETHOD.
OOPS in ABAP 40
Advantages of OOPS in ABAP
The implementation of object-oriented elements in ABAP language has considerably increased response times. Use of OOPS in ABAP helps to have a better control of development complexity, a better means for encapsulation and extensibility. Reusability of the objects will reduce the coding effort and helps in utilizing the existing code for other programs.
OOPS in ABAP
• Implement methods. OOPS in ABAP 42 . • Create internal types in a class. Features • Display an overview of global data types and their relationships.Object Orientation Tools in ABAP ABAP Class Builder • Transaction Code: SE24. • Allows you to create and maintain global classes and interfaces. methods and events of global classes and interfaces. • Create and specify attributes.
OOPS in ABAP 43 .
HOW TO USE ALV USING OOPS OOPS in ABAP 44 .
Tcode: SE38 Create a program OOPS in ABAP 45 .
Goto Flow Logic and click on layout OOPS in ABAP 46 .
Add a Custom Control on the screen OOPS in ABAP 47 .
Give a name to custom control OOPS in ABAP 48 .
Declare Gobal variables to be used for ALV Grid OOPS in ABAP 49 .
Fill internal table with list data to be displayed OOPS in ABAP 50 .
In PBO of the flow logic. write a module and inside the module write the code OOPS in ABAP 51 .
Creating custom container instance OOPS in ABAP 52 .If ALV Grid instance not exist.
OOPS in ABAP 53 .
Creating ALV Grid instance OOPS in ABAP 54 .
Call the method for data display OOPS in ABAP 55 .
OOPS in ABAP 56 .
If ALV Grid instance already exists OOPS in ABAP 57 .
Output OOPS in ABAP 58 .
If we assign values for layout structure fields OOPS in ABAP 59 .
Output OOPS in ABAP 60 .
THANK YOU OOPS in ABAP 61 .
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.