What is Object Orientation?In the past, information systems used to be defined primarily by their functionality: Data and ...
Local and Global ClassesAs mentioned earlier a class is an abstract description of an object. Classes in ABAP Objects can ...
CLASS <class> IMPLEMENTATION.......ENDCLASS.Structure of a ClassThe following statements define the structure of a class: ...
2. Visibility of Components       Data declared in public section can be accessed by the class itself, by its subclasses a...
The yellow block of code is CLASS Definition    The Green block of code is CLASS Implementation    The Grey block of code ...
Single InheritanceSingle Inheriting: Acquiring the properties from a single parent. (Children can be more).               ...
Let us see a very simple example for creating subclass(child) from a superclass(parent)Multiple Inheritance is not support...
Abstraction: Everything is visualized in terms of classes and objects.Encapsulation The wrapping up of data and methods in...
WA-BUZEI,       WA-MATNR,       WA-MENGE.  ENDLOOP.  ENDIF. ENDMETHOD.ENDCLASS.DATA: OBJ TYPE REF TO CL.START-OF-SELECTION...
7. How we can refer to a class without defining it?8. Can we put non declarative statement e.g. START-OF-SELECTION within ...
51. When is difference btw native and open sql52. Difference between Modify and Update53. Which is more efficient for all ...
*&      By                                                             **&         Vikram.C for SAPTechnical.COM          ...
Upcoming SlideShare
Loading in …5
×

Object oriented basics

5,251 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
5,251
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
327
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Object oriented basics

  1. 1. What is Object Orientation?In the past, information systems used to be defined primarily by their functionality: Data and functionswere 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 ofthe real world. These objects are first defined by their character and their properties, which arerepresented by their internal structure and their attributes (data). The behavior of these objects isdescribed 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.ObjectsAn object is a section of source code that contains data and provides services. The data forms the attributes ofthe object. The services are known as methods (also known as operations or functions). They form a capsulewhich combines the character to the respective behavior. Objects should enable programmers to map a realproblem and its proposed software solution on a one-to-one basis.ClassesClasses 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 uniqueidentity and its own set of values for its attributes.
  2. 2. Local and Global ClassesAs mentioned earlier a class is an abstract description of an object. Classes in ABAP Objects can be declaredeither globally or locally.Global ClassGlobal 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 inan R/3 System can access the global classesLocal ClassLocal classes are define in an ABAP program (Transaction SE38) and can only be used in the program inwhich they are defined. Global Class Local ClassAccessed 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 characterLocal ClassesEvery class will have two sections. (1) Definition. (2) Implementation.DefinitionThis section is used to declare the components of the classes such as attributes, methods, events .Theyare enclosed in the ABAP statements CLASS ... ENDCLASS.CLASS <class> DEFINITION.........ENDCLASS.ImplementationThis section of a class contains the implementation of all methods of the class. The implementation partof a local class is a processing block.
  3. 3. CLASS <class> IMPLEMENTATION.......ENDCLASS.Structure of a ClassThe 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. 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. 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 isAttributes of Object Oriented Programming Inheritance. Abstraction. Encapsulation. PolymorphismInheritanceInheritance is the concept of adopting the features from the parent and reusing them. It involves passing thebehavior of a class to another class. You can use an existing class to derive a new class. Derived classesinherit the data and methods of the super class. However, they can overwrite existing methods, and also addnew ones.Inheritance is of two types:1) Single Inheritance2) Multiple Inheritance
  6. 6. Single InheritanceSingle Inheriting: Acquiring the properties from a single parent. (Children can be more). Example for Single InheritanceMultiple inheritanceAcquiring the properties from more than one parent.ExampleTomato4 (Best Color, Size, Taste)Tomato1 (Best Color)Tomato2 (Best Size)Tomato3 (Best Tast)Syntax: CLASS <subclass> DEFINITION INHERITING FROM <superclass>.
  7. 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. 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 asEncapsulation. The data is not accessible to the outside world only those methods, which are wrapped inthe 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 containsconstructions called interfaces. They enable you to address methods with the same name in differentobjects. Although the form of address is always the same, the implementation of the method is specific toa 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. 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->GETDATAEXPORTING IRLOW = INVOICE-LOW IRHIGH = INVOICE-HIGH.CALL METHOD OBJ->DISPLAYDATA.Reference:http://www.saptechnical.com/Tutorials/OOPS/Concepts/page1.htmhttp://wiki.sdn.sap.com/wiki/display/ABAP/Object+Orientedhttp://wiki.sdn.sap.com/wiki/display/ABAP/Object+Oriented+ABAP+%28OO-ABAP%29http://wiki.sdn.sap.com/wiki/display/ABAP/Polymorphism+using+OO+ABAPhttp://forums.sdn.sap.com/thread.jspa?threadID=728250http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htmhttp://help.sap.com/saphelp_46c/helpdata/EN/87/56d00722c011d2954a0000e8353423/content.htm#U--------------------------------------------SAP COMMANDSQuestions on OO ABAP1. 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. 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 class9. What is static attribute & method?10. How to create a global class?11. How can we pass importing parameter? Pass by value/pass by reference13. Can we changed pass by reference in any method?14. What is preferred parameter? more than one optional & no mandatory15. Can we pass returing parameter by reference? NO only pass by value16. 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 beimplemented?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 namewhich 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. 11. 51. When is difference btw native and open sql52. Difference between Modify and Update53. 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+OOPhttp://www.saptechnical.com/Tutorials/OOPS/Binding/Procedure.htmhttp://www.scribd.com/doc/35821441/Ooabap-Examples-------------***************Difference between static and instance variablesStatic 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. 12. *& By **& Vikram.C for SAPTechnical.COM **&---------------------------------------------------------------------*REPORT ZLOCALCLASS_VARIABLES.*General local class by using static and instance.*Define the classCLASS 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 classCLASS 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 objectDATA OBJ TYPE REF TO CL_LC.START-OF-SELECTION.CREATE OBJECT OBJ.*Call the instance methodCALL 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.

×