Tuesday 14 June 2016

Class


  • Classes are templates for objects. Conversely, you can say that the type of an object is the same as its class.
  • A class is an abstract description of an object.
  • You could say that it is a set of instructions for building an object.
  • The attributes of objects are defined by the components of the class, which describe the state and behavior of objects.
  • Classes in ABAP Objects can be declared 2 ways.
  1. Global Class Builder(Transaction SE24).
  2. Local Class  (Transaction SE38 / SE80 ).


Difference

  • Global Class
  1. These are stored centrally in the class library in the r/3 Repository.
  2. Transaction code: SE24.
  3. All of the ABAP programs in an R/3 System can access the global classes.
  • Local Class
  1. Local Classes are defined within an ABAP program.
  2. Local classes and interfaces can only be used in the program in which they are defined.
  3. When you use a class in an ABAP program, the system first searches for a local class with a specified name. If it does not find one, it then looks for a global class.

Components of a Class

  1. Attributes: Attributes are variables, constants declared within a class.
  2. Methods: Methods are coding blocks that provide some functionality.
  3. Constructor and class_constructor: special types of methods. Constructor and class_constructor are automatically called when you create an object or when you first access the components of a class.
  4. Events: Objects or classes can use events to trigger event handler methods in other objects or classes. In a normal method call, one method can be called by any number of users. When an event is triggered, any number of event handler methods can be called.
  5. Types: We can define our own ABAP data types within a class using the TYPES statement. Types are not instance-specific and exist once only for all of the objects in a class. 
  6. Constants: Constants are special static attributes. We can set their values when we declare them, and they can then no longer be changed. We can declare constants using the CONSTANTS statement.


Visibility of Components of Class

  1. Public
  2. Protected.
  3. Private.
  • Public section: Data declared in a public section can be accessed by the class itself, by its sub-classes as well as by other users outside the class.
  • Protected section: Data declared in the protected section can be accessed by the class itself, and also by its sub-classes but not by external users outside the class.
  • Private Section: Data declared in the private section can be accessed by the class only, but not by its sub-classes and by external users outside the class.

Instance and Static Components

  • Instance components
  1. These components exist separately in each instance (object) of the class and are referred to using instance component selector using ->.
  2. A separate copy will create for each object.
  3. Instance components can call static components.
  • Static components
  1. These components exist globally for a class and are referred to using static component selector =>.
  2. If you change the value, then the original value will get affected.
  3. Static data will always class-specific.
                                         more information..............
   

No comments:

Post a Comment