abap oops basics

Upload: kandimalla-satish

Post on 04-Jun-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Abap Oops Basics

    1/2

    1. METHODSa) They can access all the attributes of a class.b) Methods have parameters (Signature).c) IMPORTING, EXPORTING, CHANGING, RETURNING, EXCEPTIONS, RAISINGd) Syntax: IMPORTING var Type type,

    RETURNING VALUE (var) TYPE type,

    EXCEPTIONS exception

    RAISING class exception

    e) Public Methodscan be called from anywhere; Private Methodscan be called onlywithin the class.

    f) Instance Methodscan use both static and instance attributes and can be called using aninstance. They are called using CALL METHODrefvar->instancemethod. You can access

    instance attributes using ->.

    g) Static Methodsalso called as class methods can only use static components and can becalled using a class. They are called using CALL METHOD classname => classmethod. If

    you are calling a static method from within the class, you can omit the class name. You

    can access static attributes using =>

    h) => and -> are the component selectors.i) Functional Methods:Methods that have a RETURNING parameter are described as

    functional methods. These methods cannot have EXPORTING or CHANGING parameters,

    but has many (or as few) IMPORTING parameters and exceptions as required. You can

    only do this for a single parameter, which additionally must be passed as a value.

    2. Reference variable: A reference variable act as a pointer to an object.DATA: lv_vehicle TYPE REF TO lcl_vehicle.

    3. Creating Objects: we can create multiple objects. Syntax Create Object lcl_vehicle. Gt_itab TypeTable of REF TO lcl_vehicle.

    4. The Garbage Collectoris a system routine that automatically deletes objects that can no longerbe addressed from the main memory and releases the memory space they occupied.

    5. Constructor:The constructor is a special instance method in a class with the name constructor.a) Each class can have one constructor and is executed only once per instance.b) The constructor is automatically called at runtime within the CREATE OBJECT statement.c) If you need to implement the constructor, then you must define and implement it in the

    PUBLIC SECTION. You cannot normally call the constructor explicitly.

    d) Used for creating objects with defined initial state.e) Only has IMPORTING and EXCEPTIONS parameters.f) Static Constructor: The static constructor is a special static method in a class with the

    name class_constructor. It is executed precisely once per program. The static

    constructor cannot be called explicitly.

  • 8/13/2019 Abap Oops Basics

    2/2

    6. Reference variable ME:7. Inheritance:Inheritance is a relationship, in which one class (the subclass) inherits all the main

    characteristics of another class (the superclass). The subclass can also add new components

    (attributes, methods, and so on) and replace inherited methods with its own implementations.

    a) ABAP OO has only Single Inheritance. Syntax is CLASS lcl_truck DEFINITION INHERITINGFROM lcl_vehicle.

    b) Redefining Methodsc)

    8. Visibility in Inheritance: Public: Visible to all Protected: Only visible within the class and its subclasses Private: Only visible within the class and not even its subclass.

    9. Interface: They dont contain any implementation.a) Interface provides only services. The user never actually knows the providers of these

    services, but communicates with them through the interface.

    b) In this way the user is protected from actual implementations and can work in the sameway with different classes/objects, as long as they provide the services required. This is

    known as polymorphism with interfaces.

    c) Syntax: INTERFACE testMETHODS: display.

    ENDINTERFACE.

    INTERFACES test

    METHOD test~display.

    Lcl_vehicle-> test~display. (obj ref should refer to class which implements

    interface)

    10.Compound Interface:A compound interface contains other interfaces as components(component interfaces) and summarizes the extension of these component interfaces.

    11.Events: By triggering an event, an object or class announces a change of state, or that acertain state has been achieved.