Vous êtes sur la page 1sur 9

Introduction :

A programming technique in which solutions reflect real world objects


What are objects ?
An object is an instantiation of a class. E.g. If lAnimall is a class, A cat
can be an object of that class .
With respect to code, Object refers to a set of services ( methods /
attributes ) and can contain data

What are classes ?
A class defines the properties of an object. A class can be instantiated
as many number of times
1. Simplicity:
Software objects model real world objects, so the complexity is reduced and the program structure is very
clear.

2. Modularity:
Each object forms a separate entity whose internal workings are decoupled from other parts of the system.

3. Modifiability:
It is easy to make minor changes in the data representation or the procedures in an OO program. Changes
inside a class do not affect any other part of a program, since the only public interface that the external world
has to a class is through the use of methods.

4. Extensibility:
Adding new features or responding to changing operating environments can be solved by introducing a few
new objects and modifying some existing ones.

5. Maintainability:
Objects can be maintained separately, making locating and fixing problems easier.

6. Re-usability:
Objects can be reused in different programs.
' OOPS REPORT
Create a container. There are 2 type of containers: docking and custom.
Go to SE38.Create a program. Use Pattern button to create object for docking container. Click ABAP Object Pattern
radio button. Click Create object radio button. Give Instance as o_docking and class as cl_gui_docking_contianer.
Step 2:
Create a grid inside the container.
Use Pattern button to create the same. Make the parent of grid as container.
Click ABAP Object Pattern radio button. Click Create object radio button. Give Instance as o_grid and class as
cl_gui_alv_grid. Create object o_grid.
Step 3:
Call the function lvc_fieldcatalog_merge to get the field catalog.
Pass the structure name.
Step 4:
Fill the internal table itab with values by using logic.
select * from mara into table itab up to 100 rows.
call screen 9000.
Step 5:
Create a screen by double clicking 9000 in the above line. Fill the description for the screen. In the flow logic,
uncomment the PBO and PAI module and create those in main program (for simplicity).
Step 6:
Create GUI status. Create GUI Title if required. That can be done by using display object List
(Ctrl+Shift+F5).Then in left side, right click the program and create GUI Status and Title.
Step 7:
Free the memory occupied once the BACK, EXIT or CANCEL button is clicked. Use Pattern button to
call the method FREE of cl_gui_alv_grid and cl_gui_docking_container.
Click ABAP Object Pattern radio button. Click Call Method radio button. Give Instance as o_grid and
Class/Interface as cl_gui_alv_grid and Method as Free.
Similarly Click Call Method radio button. Give Instance as o_docking and Class/Interface as
cl_gui_docking_container and Method as Free.
1.Principles of oops?
Attributes of Object Oriented Programming:
O Inheritance.
O Abstraction.
O Encapsulation.
O Polymorphism
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: Single Inheritance and Multiple 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.
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 :

-straction: 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.

2. What is difference -etween procedural & OO Programming?
Features Procedure Oriented
approach
Object Oriented approach
Emphasis Emphasis on tasks Emphasis on things that does
those tasks.
Modularization Programs are divided into
smaller programs known as
functions
Programs are organized into
classes and objects and the
functionalities are embedded
into methods of a class.
Data security Most of the functions share
global data
Data can be hidden and cannot
be accessed by external
sources.
Extensibility Relatively more time
consuming to modify for
extending existing
functionality.
New data and functions can be
easily added whenever
necessary

3. What is class?
4. What is object?
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.

,8808: 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.
4caI and GI4baI CIasses
As mentioned earlier a class is an abstract description of an object. Classes in ABAP Objects can be
declared either globally or locally.
GI4baI CIass: 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
4caI CIass: 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
efiniti4n: 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.
$tructure 4f a CIass
The following statements define the structure of a class:
A class contains components
Each component is assigned to a visibility section
Classes implement methods
C4254nents 4f a CIass are as f4II4
OAttributes:- Any data,constants,types declared within a class form the attribute of the class.
e 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.
e Events:- A mechanism set within a class which can help a class to trigger methods of other
class.
e 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 ` => .
VisibiIity 4f C4254nents
Each class component has a visibility. In ABAP Objects the whole class definition is separated into
three visibility sections: PUBLIC, PROTECTED, and PRIVATE.
e Data declared in public section can be accessed by the class itself, by its subclasses as well as
by other users outside the class.
e 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.
e 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> DEFNTON.
PUBLC SECTON.
...
PROTECTED SECTON.
...
PRVATE SECTON.
...
ENDCLASS.
We shall see an example on Visibility of Components once we become familiar with attributes of ABAP
Objects.

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

5. Can we instantiate a class within implementation of other class?
6. What is deferred key word?
Definition deferred means that you can refer to objects in your program which haven't yet been
defined but will be later on in your code.
You could have two classes in an abap say and data elements / types in the first class refer to the 2nd
class such as obj1 type ref to zclass2 definition deferred.
The zclass2 definition will appear later in your abap.

7. How we can refer to a class without defining it?
we can refer with Type Ref To or using ME keyword

8. Can we put non declarative statement e.g. START-OF-SELECTION within a class
no
9. What is static attribute & method?
10. How to create a glo-al class ?
Creation of Local class
CLASS zcl_test DEFINITION.
PUBLIC SECTION.
METHODS: display.
ENDCLASS. "zcl_test DEFINITION
*--------------------------------------------------------*
* CLASS zcl_test IMPLEMENTATION
*--------------------------------------------------------*
*
*--------------------------------------------------------*
CLASS zcl_test IMPLEMENTATION.
METHOD display.
WRITE: 'SAPTechnical.com'.
ENDMETHOD. "display
ENDCLASS. "zcl_test IMPLEMENTATION
Creation of global class from local class
Se24 - Import local class give the name and save

18. What is me varia-le?

19. What is constructor ?What are type 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?











66. What is persistant class

Vous aimerez peut-être aussi