SlideShare une entreprise Scribd logo
1  sur  12
What is Object Orientation?

In the past, information systems used to be defined primarily by their functionality: Data and functions
were kept separate and linked together by means of input and output relations.

The object-oriented approach, however, focuses on objects that represent abstract or concrete things of
the real world. These objects are first defined by their character and their properties, which are
represented by their internal structure and their attributes (data). The behavior of these objects is
described by methods (functionality).

Comparison between Procedural and Object Oriented Programming

     Features         Procedure Oriented approach           Object Oriented approach


     Emphasis              Emphasis on tasks.             Emphasis on things that does
                                                                 those tasks.

  Modularization        Programs are divided into          Programs are organized into
                       smaller programs known as           classes and objects and the
                                functions.              functionalities are embedded into
                                                               methods of a class.
   Data security       Most of the functions share      Data can be hidden and cannot be
                               global data.               accessed by external sources.

    Extensibility          Relatively more time          New data and functions can be
                         consuming to modify for        easily added whenever necessary.
                            extending existing
                               functionality.




Object Oriented Approach - key features

    1.    Better Programming Structure.
    2.    Real world entity can be modeled very well.
    3.    Stress on data security and access.
    4.    Reduction in code redundancy.
    5.    Data encapsulation and abstraction.

Objects

An object is a section of source code that contains data and provides services. The data forms the attributes of
the object. The services are known as methods (also known as operations or functions). They form a capsule
which combines the character to the respective behavior. Objects should enable programmers to map a real
problem and its proposed software solution on a one-to-one basis.

Classes

Classes describe objects. From a technical point of view, objects are runtime instances of a class. In theory,
you can create any number of objects based on a single class. Each instance (object) of a class has a unique
identity and its own set of values for its attributes.
Local and Global Classes

As mentioned earlier a class is an abstract description of an object. Classes in ABAP Objects can be declared
either globally or locally.

Global Class

Global classes and interfaces are defined in the Class Builder (Transaction SE24) in the ABAP Workbench.
They are stored centrally in class pools in the class library in the R/3 Repository. All of the ABAP programs in
an R/3 System can access the global classes

Local Class

Local classes are define in an ABAP program (Transaction SE38) and can only be used in the program in
which they are defined.

                                Global Class                        Local Class

Accessed By                     Any program            Only the program where it is defined.

   Stored In               In the Class Repository    Only in the program where it is defined.

 Created By          Created using transaction SE24            Created using SE38

 Namespace                 Must begin with Y or Z          Can begin with any character


Local Classes

Every class will have two sections.

       (1)   Definition.

       (2)   Implementation.

Definition

This section is used to declare the components of the classes such as attributes, methods, events .They
are enclosed in the ABAP statements CLASS ... ENDCLASS.

CLASS <class> DEFINITION.

....
....

ENDCLASS.

Implementation

This section of a class contains the implementation of all methods of the class. The implementation part
of a local class is a processing block.
CLASS <class> IMPLEMENTATION.

...
...

ENDCLASS.

Structure of a Class

The following statements define the structure of a class:

      1.   A class contains components.
      2.   Each component is assigned to a visibility section.
      3.   Classes implement methods.

1. Components of a Class are as follow:

           Attributes: Any data, constants, types declared within a class form the attribute of the class.

           Methods: Block of code, providing some functionality offered by the class. Can be compared to
           function modules. They can access all of the attributes of a class.

           Methods are defined in the definition part of a class and implement it in the implementation part
           using the following processing block:
           METHOD <meth>.

              ...

             ENDMETHOD.

           Methods are called using the CALL METHOD statement.

           Events:    A mechanism set within a class which can help a class to trigger methods of other
           class.

           Interfaces: Interfaces are independent structures that you can implement in a class to extend
           the scope of that class.


           Instance and Static Components:

           Instance components exist separately in each instance (object) of the class and are referred
           using instance component selector using ‘’.

           Static components only exist once per class and are valid for all instances of the class. They are
           declared with the CLASS- keywords.

           Static components can be used without even creating an instance of the class and are referred to
           using static component selector ‘=>’.
2. Visibility of Components

       Data declared in public section can be accessed by the class itself, by its subclasses as well as
       by other users outside the class.

       Data declared in the protected section can be accessed by the class itself, and also by its
       subclasses but not by external users outside the class.

       Data declared in the private section can be accessed by the class only, but not by its subclasses
       and by external users outside the class.

           CLASS <class> DEFINITION.

             PUBLIC SECTION.

               ...

              PROTECTED SECTION.

               ...

              PRIVATE SECTION.

              ...
            ENDCLASS.

   Example on Visibility of Components
The yellow block of code is CLASS Definition

    The Green block of code is CLASS Implementation

    The Grey block of code is for object creation. This object creation includes two steps:

     Step1: is Create a reference variable with reference to the class.

       Syntax: DATA : <object name> TYPE REF TO <class name>.

     Step 2: Create an object from the reference variable:-

       Syntax: CREATE OBJECT <object name> .

    Output for the above code is




Attributes of Object Oriented Programming

        Inheritance.
        Abstraction.
        Encapsulation.
        Polymorphism

Inheritance

Inheritance is the concept of adopting the features from the parent and reusing them. It involves passing the
behavior of a class to another class. You can use an existing class to derive a new class. Derived classes
inherit the data and methods of the super class. However, they can overwrite existing methods, and also add
new ones.

Inheritance is of two types:

1) Single Inheritance

2) Multiple Inheritance
Single Inheritance

Single Inheriting: Acquiring the properties from a single parent. (Children can be more).




                                    Example for Single Inheritance

Multiple inheritance

Acquiring the properties from more than one parent.

Example

Tomato4 (Best Color, Size, Taste)

Tomato1 (Best Color)

Tomato2 (Best Size)

Tomato3 (Best Tast)




Syntax: CLASS <subclass> DEFINITION INHERITING FROM <superclass>.
Let us see a very simple example for creating subclass(child) from a superclass(parent)




Multiple Inheritance is not supported by ABAP.

Output is as follows:
Abstraction: Everything is visualized in terms of classes and objects.

Encapsulation The wrapping up of data and methods into a single unit (called class) is known as
Encapsulation. The data is not accessible to the outside world only those methods, which are wrapped in
the class, can access it.

Polymorphism: Methods of same name behave differently in different classes. Identical (identically-
named) methods behave differently in different classes. Object-oriented programming contains
constructions called interfaces. They enable you to address methods with the same name in different
objects. Although the form of address is always the same, the implementation of the method is specific to
a particular class.




Sample Program for Local Class.

TABLES: RBKP,
       RSEG.

TYPES: BEGIN OF TY_RSEG,
       BELNR TYPE RE_BELNR,
      BUZEI TYPE RBLGP,
      MATNR TYPE MATNR,
      MENGE TYPE MENGE_D,
      END OF TY_RSEG.

SELECT-OPTIONS: INVOICE FOR RBKP-BELNR.

CLASS CL DEFINITION.
 PUBLIC SECTION.
 METHODS: GETDATA IMPORTING IRLOW TYPE RE_BELNR
                           IRHIGH TYPE RE_BELNR,
           DISPLAYDATA.

 DATA: WA TYPE TY_RSEG,
      ITAB TYPE STANDARD TABLE OF TY_RSEG.

ENDCLASS.

CLASS CL IMPLEMENTATION.
 METHOD GETDATA.
  SELECT BELNR
     BUZEI
     MATNR
     MENGE FROM RSEG
     INTO TABLE ITAB
     WHERE BELNR BETWEEN IRLOW AND IRHIGH.

 ENDMETHOD.

 METHOD DISPLAYDATA.
  IF NOT ITAB[] IS INITIAL.
  SORT ITAB[] BY BELNR.
  LOOP AT ITAB[] INTO WA.
   WRITE:/ WA-BELNR,
WA-BUZEI,
       WA-MATNR,
       WA-MENGE.
  ENDLOOP.
  ENDIF.
 ENDMETHOD.
ENDCLASS.

DATA: OBJ TYPE REF TO CL.
START-OF-SELECTION.
CREATE OBJECT OBJ.
CALL METHOD OBJ->GETDATA
EXPORTING
 IRLOW = INVOICE-LOW
 IRHIGH = INVOICE-HIGH.
CALL METHOD OBJ->DISPLAYDATA.




Reference:

http://www.saptechnical.com/Tutorials/OOPS/Concepts/page1.htm

http://wiki.sdn.sap.com/wiki/display/ABAP/Object+Oriented

http://wiki.sdn.sap.com/wiki/display/ABAP/Object+Oriented+ABAP+%28OO-ABAP%29

http://wiki.sdn.sap.com/wiki/display/ABAP/Polymorphism+using+OO+ABAP




http://forums.sdn.sap.com/thread.jspa?threadID=728250

http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm




http://help.sap.com/saphelp_46c/helpdata/EN/87/56d00722c011d2954a0000e8353423/content.ht
m#U--------------------------------------------SAP COMMANDS



Questions on OO ABAP

1.   Principles of oops?
2.   What is difference between procedural & OO Programming?
3.   What is class?
4.   What is object?
5.   Can we instantiate a class within implementation of other class?
6.   What is deferred key word?
7. How we can refer to a class without defining it?
8. Can we put non declarative statement e.g. START-OF-SELECTION within a class
9. What is static attribute & method?

10. How to create a global class?
11. How can we pass importing parameter? Pass by value/pass by reference
13. Can we changed pass by reference in any method?
14. What is preferred parameter? more than one optional & no mandatory
15. Can we pass returing parameter by reference? NO only pass by value
16. Can static method use instance attribute ?
17. Can a method call itself?
18. What is me variable?
19. What is constructor? What are types of constructor? When it is called?
20. Can we have export parameter in Instance constructor?
21. Can instance constructor raise exception?
22. When static constructor is called?
23. Can we have interface for static class or constructor?
24. What is abstract class?
25. Can we implement abstract method in abstract class? If not then where it can be
implemented?
26. What is final class & Method?
27. Can subclass call super class constructor?
28. Can we call static constructor more than once in a program?
29. What is method redefinition?
30. What is interface?
31. Can we implement interface in private section of any class?
32. Is it mandatory to implement all the methods of interface?
33. What is alias? Instead of specifying full name of interface methods we can assign it a name
which can directly trigger.
34. What is Friendship?
35. What is event handler method?
36. Can we have more than one event handler method for same event?
37. Can event have import parameter?
38. How you handled exception during programming?
39. What is cleanup section?
40. What is BADI?
41. What is check box for multiple usse in BADI?
42. How to search a BADI ?
43. What is Value table and Check table, Difference between them?
44. What are secondary index’s?
45. What is the draw back of secondary index’s?
46. What are conversion routines?
47. At which level are they mantained?
48. what are Predeifined data types?
49. Which predefined data type uses conversion routines?
50. What are logical units of work?
51. When is difference btw native and open sql
52. Difference between Modify and Update
53. Which is more efficient for all entries or joins?
54. When is implicit commit triggered.
55. What are RFC?
56. How do u create a destination system?
57. What are different types of commits used?
58. What are search helps?
59. Types of tables?
60. Difference between pool tables and cluster tables?
61. What is a delivery class?
62. What are the types of delivery class?
63. Difference between System tables and control tables?
64. What is normalization?
65. What is BCNF?
66. What is persistant class?



http://wiki.sdn.sap.com/wiki/display/Snippets/Binding+in+ABAP+OOP

http://www.saptechnical.com/Tutorials/OOPS/Binding/Procedure.htm

http://www.scribd.com/doc/35821441/Ooabap-Examples-------------***************



Difference between static and instance variables
Static attributes:

    1.   The attributes are created only once.
    2.   That means memory allocation for the attribute is only once.
    3.   We can call next time the same attribute by using object then the same memory space is referred.
    4.   We can change the value in the memory.

Instance attributes:

    1.   These attributes are created for every time.
    2.   That means for each and every call statement, the attribute creates a new memory location at every
         time.

Go to SE38 and create the following program.

*&---------------------------------------------------------------------*
*& Report ZLOCALCLASS_VARIABLES                                        *
*&                                                                     *
*&---------------------------------------------------------------------*
*&      By                                                             *
*&         Vikram.C for SAPTechnical.COM                               *
*&---------------------------------------------------------------------*
REPORT ZLOCALCLASS_VARIABLES.
*General local class by using static and instance.
*Define the class
CLASS CL_LC DEFINITION.
PUBLIC SECTION.
DATA: A TYPE I VALUE 10.
CLASS-DATA: B TYPE I VALUE 20.
METHODS DISPLAY.
CLASS-METHODS DISP.
ENDCLASS.
*Implement the class
CLASS CL_LC IMPLEMENTATION.
METHOD DISPLAY.
WRITE:/ 'IT IS INSTANCE METHOD',
      / 'INSTANCE VARIABLE = ', A.
ENDMETHOD.
METHOD DISP.
WRITE:/ 'IT IS STATIC METHOD' COLOR 2,
      / 'STATIC VARIABLE = ', B COLOR 2.
ENDMETHOD.
ENDCLASS.
*Create the object
DATA OBJ TYPE REF TO CL_LC.
START-OF-SELECTION.
CREATE OBJECT OBJ.
*Call the instance method
CALL METHOD OBJ->DISPLAY.
*Call the static method.
CALL METHOD CL_LC=>DISP.


Save it, check it, activate it after that execute it.

Then the output is like this.

Contenu connexe

Tendances

Introducing enhancement framework.doc
Introducing enhancement framework.docIntroducing enhancement framework.doc
Introducing enhancement framework.doc
Kranthi Kumar
 
BATCH DATA COMMUNICATION
BATCH DATA COMMUNICATIONBATCH DATA COMMUNICATION
BATCH DATA COMMUNICATION
Kranthi Kumar
 
Chapter 01 user exits
Chapter 01 user exitsChapter 01 user exits
Chapter 01 user exits
Kranthi Kumar
 
abap list viewer (alv)
abap list viewer (alv)abap list viewer (alv)
abap list viewer (alv)
Kranthi Kumar
 

Tendances (20)

Beginner's Guide: Programming with ABAP on HANA
Beginner's Guide: Programming with ABAP on HANABeginner's Guide: Programming with ABAP on HANA
Beginner's Guide: Programming with ABAP on HANA
 
CDS Views.pptx
CDS Views.pptxCDS Views.pptx
CDS Views.pptx
 
Introducing enhancement framework.doc
Introducing enhancement framework.docIntroducing enhancement framework.doc
Introducing enhancement framework.doc
 
BRF+ Walk through
BRF+ Walk throughBRF+ Walk through
BRF+ Walk through
 
SITIST 2015 Dev - Abap on Hana
SITIST 2015 Dev - Abap on HanaSITIST 2015 Dev - Abap on Hana
SITIST 2015 Dev - Abap on Hana
 
Alv theory
Alv theoryAlv theory
Alv theory
 
Type casting in ooabap
Type casting in ooabapType casting in ooabap
Type casting in ooabap
 
BATCH DATA COMMUNICATION
BATCH DATA COMMUNICATIONBATCH DATA COMMUNICATION
BATCH DATA COMMUNICATION
 
Introduction to SAP Gateway and OData
Introduction to SAP Gateway and ODataIntroduction to SAP Gateway and OData
Introduction to SAP Gateway and OData
 
Charm workflow for urgent changes while adding node
Charm workflow for urgent changes while adding nodeCharm workflow for urgent changes while adding node
Charm workflow for urgent changes while adding node
 
Object oriented approach to ALV Lists in ABAP
Object oriented approach to ALV Lists in ABAPObject oriented approach to ALV Lists in ABAP
Object oriented approach to ALV Lists in ABAP
 
Chapter 01 user exits
Chapter 01 user exitsChapter 01 user exits
Chapter 01 user exits
 
Abap reports
Abap reportsAbap reports
Abap reports
 
Sap Abap Reports
Sap Abap ReportsSap Abap Reports
Sap Abap Reports
 
Ab1011 module pool programming
Ab1011   module pool programmingAb1011   module pool programming
Ab1011 module pool programming
 
Field symbols
Field symbolsField symbols
Field symbols
 
Bapi programming
Bapi programmingBapi programming
Bapi programming
 
abap list viewer (alv)
abap list viewer (alv)abap list viewer (alv)
abap list viewer (alv)
 
Module pool programming
Module pool programmingModule pool programming
Module pool programming
 
Reports
ReportsReports
Reports
 

Similaire à Object oriented basics

oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
ArpitaJana28
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
AnkurSingh340457
 
Application package
Application packageApplication package
Application package
JAYAARC
 

Similaire à Object oriented basics (20)

Oops
OopsOops
Oops
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
 
oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
 
Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1
 
My c++
My c++My c++
My c++
 
Oops
OopsOops
Oops
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
python.pptx
python.pptxpython.pptx
python.pptx
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
12th ip CBSE chapter 4 oop in java notes complete
12th ip CBSE  chapter 4 oop in java notes complete12th ip CBSE  chapter 4 oop in java notes complete
12th ip CBSE chapter 4 oop in java notes complete
 
Oops
OopsOops
Oops
 
Application package
Application packageApplication package
Application package
 
Object Oriented Javascript part2
Object Oriented Javascript part2Object Oriented Javascript part2
Object Oriented Javascript part2
 
Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Review oop and ood
Review oop and oodReview oop and ood
Review oop and ood
 
Lab 4 (1).pdf
Lab 4 (1).pdfLab 4 (1).pdf
Lab 4 (1).pdf
 
OOSD1-unit1_1_16_09.pptx
OOSD1-unit1_1_16_09.pptxOOSD1-unit1_1_16_09.pptx
OOSD1-unit1_1_16_09.pptx
 

Dernier

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Dernier (20)

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

Object oriented basics

  • 1. What is Object Orientation? In the past, information systems used to be defined primarily by their functionality: Data and functions were kept separate and linked together by means of input and output relations. The object-oriented approach, however, focuses on objects that represent abstract or concrete things of the real world. These objects are first defined by their character and their properties, which are represented by their internal structure and their attributes (data). The behavior of these objects is described by methods (functionality). Comparison between Procedural and Object Oriented Programming Features Procedure Oriented approach Object Oriented approach Emphasis Emphasis on tasks. Emphasis on things that does those tasks. Modularization Programs are divided into Programs are organized into smaller programs known as classes and objects and the functions. functionalities are embedded into methods of a class. Data security Most of the functions share Data can be hidden and cannot be global data. accessed by external sources. Extensibility Relatively more time New data and functions can be consuming to modify for easily added whenever necessary. extending existing functionality. Object Oriented Approach - key features 1. Better Programming Structure. 2. Real world entity can be modeled very well. 3. Stress on data security and access. 4. Reduction in code redundancy. 5. Data encapsulation and abstraction. Objects An object is a section of source code that contains data and provides services. The data forms the attributes of the object. The services are known as methods (also known as operations or functions). They form a capsule which combines the character to the respective behavior. Objects should enable programmers to map a real problem and its proposed software solution on a one-to-one basis. Classes Classes describe objects. From a technical point of view, objects are runtime instances of a class. In theory, you can create any number of objects based on a single class. Each instance (object) of a class has a unique identity and its own set of values for its attributes.
  • 2. Local and Global Classes As mentioned earlier a class is an abstract description of an object. Classes in ABAP Objects can be declared either globally or locally. Global Class Global classes and interfaces are defined in the Class Builder (Transaction SE24) in the ABAP Workbench. They are stored centrally in class pools in the class library in the R/3 Repository. All of the ABAP programs in an R/3 System can access the global classes Local Class Local classes are define in an ABAP program (Transaction SE38) and can only be used in the program in which they are defined. Global Class Local Class Accessed By Any program Only the program where it is defined. Stored In In the Class Repository Only in the program where it is defined. Created By Created using transaction SE24 Created using SE38 Namespace Must begin with Y or Z Can begin with any character Local Classes Every class will have two sections. (1) Definition. (2) Implementation. Definition This section is used to declare the components of the classes such as attributes, methods, events .They are enclosed in the ABAP statements CLASS ... ENDCLASS. CLASS <class> DEFINITION. .... .... ENDCLASS. Implementation This section of a class contains the implementation of all methods of the class. The implementation part of a local class is a processing block.
  • 3. CLASS <class> IMPLEMENTATION. ... ... ENDCLASS. Structure of a Class The following statements define the structure of a class: 1. A class contains components. 2. Each component is assigned to a visibility section. 3. Classes implement methods. 1. Components of a Class are as follow: Attributes: Any data, constants, types declared within a class form the attribute of the class. Methods: Block of code, providing some functionality offered by the class. Can be compared to function modules. They can access all of the attributes of a class. Methods are defined in the definition part of a class and implement it in the implementation part using the following processing block: METHOD <meth>. ... ENDMETHOD. Methods are called using the CALL METHOD statement. Events: A mechanism set within a class which can help a class to trigger methods of other class. Interfaces: Interfaces are independent structures that you can implement in a class to extend the scope of that class. Instance and Static Components: Instance components exist separately in each instance (object) of the class and are referred using instance component selector using ‘’. Static components only exist once per class and are valid for all instances of the class. They are declared with the CLASS- keywords. Static components can be used without even creating an instance of the class and are referred to using static component selector ‘=>’.
  • 4. 2. Visibility of Components Data declared in public section can be accessed by the class itself, by its subclasses as well as by other users outside the class. Data declared in the protected section can be accessed by the class itself, and also by its subclasses but not by external users outside the class. Data declared in the private section can be accessed by the class only, but not by its subclasses and by external users outside the class. CLASS <class> DEFINITION. PUBLIC SECTION. ... PROTECTED SECTION. ... PRIVATE SECTION. ... ENDCLASS. Example on Visibility of Components
  • 5. The yellow block of code is CLASS Definition The Green block of code is CLASS Implementation The Grey block of code is for object creation. This object creation includes two steps: Step1: is Create a reference variable with reference to the class. Syntax: DATA : <object name> TYPE REF TO <class name>. Step 2: Create an object from the reference variable:- Syntax: CREATE OBJECT <object name> . Output for the above code is Attributes of Object Oriented Programming Inheritance. Abstraction. Encapsulation. Polymorphism Inheritance Inheritance is the concept of adopting the features from the parent and reusing them. It involves passing the behavior of a class to another class. You can use an existing class to derive a new class. Derived classes inherit the data and methods of the super class. However, they can overwrite existing methods, and also add new ones. Inheritance is of two types: 1) Single Inheritance 2) Multiple Inheritance
  • 6. Single Inheritance Single Inheriting: Acquiring the properties from a single parent. (Children can be more). Example for Single Inheritance Multiple inheritance Acquiring the properties from more than one parent. Example Tomato4 (Best Color, Size, Taste) Tomato1 (Best Color) Tomato2 (Best Size) Tomato3 (Best Tast) Syntax: CLASS <subclass> DEFINITION INHERITING FROM <superclass>.
  • 7. Let us see a very simple example for creating subclass(child) from a superclass(parent) Multiple Inheritance is not supported by ABAP. Output is as follows:
  • 8. Abstraction: Everything is visualized in terms of classes and objects. Encapsulation The wrapping up of data and methods into a single unit (called class) is known as Encapsulation. The data is not accessible to the outside world only those methods, which are wrapped in the class, can access it. Polymorphism: Methods of same name behave differently in different classes. Identical (identically- named) methods behave differently in different classes. Object-oriented programming contains constructions called interfaces. They enable you to address methods with the same name in different objects. Although the form of address is always the same, the implementation of the method is specific to a particular class. Sample Program for Local Class. TABLES: RBKP, RSEG. TYPES: BEGIN OF TY_RSEG, BELNR TYPE RE_BELNR, BUZEI TYPE RBLGP, MATNR TYPE MATNR, MENGE TYPE MENGE_D, END OF TY_RSEG. SELECT-OPTIONS: INVOICE FOR RBKP-BELNR. CLASS CL DEFINITION. PUBLIC SECTION. METHODS: GETDATA IMPORTING IRLOW TYPE RE_BELNR IRHIGH TYPE RE_BELNR, DISPLAYDATA. DATA: WA TYPE TY_RSEG, ITAB TYPE STANDARD TABLE OF TY_RSEG. ENDCLASS. CLASS CL IMPLEMENTATION. METHOD GETDATA. SELECT BELNR BUZEI MATNR MENGE FROM RSEG INTO TABLE ITAB WHERE BELNR BETWEEN IRLOW AND IRHIGH. ENDMETHOD. METHOD DISPLAYDATA. IF NOT ITAB[] IS INITIAL. SORT ITAB[] BY BELNR. LOOP AT ITAB[] INTO WA. WRITE:/ WA-BELNR,
  • 9. WA-BUZEI, WA-MATNR, WA-MENGE. ENDLOOP. ENDIF. ENDMETHOD. ENDCLASS. DATA: OBJ TYPE REF TO CL. START-OF-SELECTION. CREATE OBJECT OBJ. CALL METHOD OBJ->GETDATA EXPORTING IRLOW = INVOICE-LOW IRHIGH = INVOICE-HIGH. CALL METHOD OBJ->DISPLAYDATA. Reference: http://www.saptechnical.com/Tutorials/OOPS/Concepts/page1.htm http://wiki.sdn.sap.com/wiki/display/ABAP/Object+Oriented http://wiki.sdn.sap.com/wiki/display/ABAP/Object+Oriented+ABAP+%28OO-ABAP%29 http://wiki.sdn.sap.com/wiki/display/ABAP/Polymorphism+using+OO+ABAP http://forums.sdn.sap.com/thread.jspa?threadID=728250 http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm http://help.sap.com/saphelp_46c/helpdata/EN/87/56d00722c011d2954a0000e8353423/content.ht m#U--------------------------------------------SAP COMMANDS Questions on OO ABAP 1. Principles of oops? 2. What is difference between procedural & OO Programming? 3. What is class? 4. What is object? 5. Can we instantiate a class within implementation of other class? 6. What is deferred key word?
  • 10. 7. How we can refer to a class without defining it? 8. Can we put non declarative statement e.g. START-OF-SELECTION within a class 9. What is static attribute & method? 10. How to create a global class? 11. How can we pass importing parameter? Pass by value/pass by reference 13. Can we changed pass by reference in any method? 14. What is preferred parameter? more than one optional & no mandatory 15. Can we pass returing parameter by reference? NO only pass by value 16. Can static method use instance attribute ? 17. Can a method call itself? 18. What is me variable? 19. What is constructor? What are types of constructor? When it is called? 20. Can we have export parameter in Instance constructor? 21. Can instance constructor raise exception? 22. When static constructor is called? 23. Can we have interface for static class or constructor? 24. What is abstract class? 25. Can we implement abstract method in abstract class? If not then where it can be implemented? 26. What is final class & Method? 27. Can subclass call super class constructor? 28. Can we call static constructor more than once in a program? 29. What is method redefinition? 30. What is interface? 31. Can we implement interface in private section of any class? 32. Is it mandatory to implement all the methods of interface? 33. What is alias? Instead of specifying full name of interface methods we can assign it a name which can directly trigger. 34. What is Friendship? 35. What is event handler method? 36. Can we have more than one event handler method for same event? 37. Can event have import parameter? 38. How you handled exception during programming? 39. What is cleanup section? 40. What is BADI? 41. What is check box for multiple usse in BADI? 42. How to search a BADI ? 43. What is Value table and Check table, Difference between them? 44. What are secondary index’s? 45. What is the draw back of secondary index’s? 46. What are conversion routines? 47. At which level are they mantained? 48. what are Predeifined data types? 49. Which predefined data type uses conversion routines? 50. What are logical units of work?
  • 11. 51. When is difference btw native and open sql 52. Difference between Modify and Update 53. Which is more efficient for all entries or joins? 54. When is implicit commit triggered. 55. What are RFC? 56. How do u create a destination system? 57. What are different types of commits used? 58. What are search helps? 59. Types of tables? 60. Difference between pool tables and cluster tables? 61. What is a delivery class? 62. What are the types of delivery class? 63. Difference between System tables and control tables? 64. What is normalization? 65. What is BCNF? 66. What is persistant class? http://wiki.sdn.sap.com/wiki/display/Snippets/Binding+in+ABAP+OOP http://www.saptechnical.com/Tutorials/OOPS/Binding/Procedure.htm http://www.scribd.com/doc/35821441/Ooabap-Examples-------------*************** Difference between static and instance variables Static attributes: 1. The attributes are created only once. 2. That means memory allocation for the attribute is only once. 3. We can call next time the same attribute by using object then the same memory space is referred. 4. We can change the value in the memory. Instance attributes: 1. These attributes are created for every time. 2. That means for each and every call statement, the attribute creates a new memory location at every time. Go to SE38 and create the following program. *&---------------------------------------------------------------------* *& Report ZLOCALCLASS_VARIABLES * *& * *&---------------------------------------------------------------------*
  • 12. *& By * *& Vikram.C for SAPTechnical.COM * *&---------------------------------------------------------------------* REPORT ZLOCALCLASS_VARIABLES. *General local class by using static and instance. *Define the class CLASS CL_LC DEFINITION. PUBLIC SECTION. DATA: A TYPE I VALUE 10. CLASS-DATA: B TYPE I VALUE 20. METHODS DISPLAY. CLASS-METHODS DISP. ENDCLASS. *Implement the class CLASS CL_LC IMPLEMENTATION. METHOD DISPLAY. WRITE:/ 'IT IS INSTANCE METHOD', / 'INSTANCE VARIABLE = ', A. ENDMETHOD. METHOD DISP. WRITE:/ 'IT IS STATIC METHOD' COLOR 2, / 'STATIC VARIABLE = ', B COLOR 2. ENDMETHOD. ENDCLASS. *Create the object DATA OBJ TYPE REF TO CL_LC. START-OF-SELECTION. CREATE OBJECT OBJ. *Call the instance method CALL METHOD OBJ->DISPLAY. *Call the static method. CALL METHOD CL_LC=>DISP. Save it, check it, activate it after that execute it. Then the output is like this.