Abap Oops
Abap Oops
-class:- a template based on which you create real time entities called object.
endclass.
---this is local class scope of the class lies inside only this program.
m
r
a
p
-
t
eh
-
a
l
c
t
e
m
s
d
os
r
--visibility:-public section
-data : in data we enter attribute of class ,so an attribute nothing but character of class.
-- start of selection.
- you can create multiple objects based on single class called car.
single class car
name,color,fuel
multiple objects
create object
creat object car1.
CAR1->COLOR = 'RED'.
----------------------- CONSTRUCTOR-------------------------
--IT is also method of class
--it is first method of class is to call when you create object of that class.
--ex
--we have created object outside the class ,now object calls constructor implicitely.
--
method constructor
IMPORTING
IMPORTING IMPORTING
class
-both attributes and parameter has same name so sap can't differentate it.
--- this statment connect one class to another class ie.person to car class( person o_car)
car
person
NAME,COLOR,FUEL TYPE
NAME AGE
->CONNECT
--write : p1->car->name.
---but in instance each object is created there is new memory allocated to it.
--abstract method which do not have implementation mmeans it just definantion inside class.
--- subclass cat inherited with animal means cat have got sleep character automatically.
--if any one of method of is abstract the class will become abstract.
---------------------GLOBAL CLASS
---segment is that it takes data as index like sooraj is first index sam is second index,john is third
index,jim is fourth index.
--write : / lv_result.
--
---index = sy-index when we looping from do enddo it will start from 1 and end with 4.
--meaning when c1>30 take the work area wa and put it in it_data2.
---------------
----------------------------------- filter operator
--it is a operator which can be used ot filter out entries of internal table based on certain
condition of colums,and this filter entry you can put in a different internal table.
--
CONSTRUCTOR V/S
-
CLASS_CONSTRUCTOR
---CS-it is the static constructor which is gettting called when class is acess first time.
--constructor:-it is instantaneous class.
--we can not declare importing parameter and exception in class constructor.
---public section: attributes writes in public section is accesable through the program.
---we define a class and subclass. if we can acess from subclass only under public and protected method
attributes is called.
---
--in this example v1 attribute and v2 attribute can acess through out the subclass.
--to acess into one class we define object and create it.
--- when we calling get_data it will always show get data from subclass.
---we use super keywork so controller goes first to super class to fetch the data.
----but we have to define it before write of subclass.
--if we define method subclass we can't implement this because it can't define in superclass.
--for calling super class we need to define data in super class and it is redefine in subclass.
---
-- GO TO SE11
---
--on is base class zcb_pk_persistance_emp which is base class and is always the abstract class means
it is partially implemented.
zca_persistance_emp
zcb_persistance_e
mp(base class) (agent class)
-create persistance(method),agent(attribute)
--go_agent(user define)
---connect agent class to persistance class by:-
--now go_emp has created and it has two methods getter and setter.
---employee id has no setter method b/c it is primary key it is get from above statement.
----------------------------INHERTANCE-----------------------------
--multiple inheritance :-when one class taking component of many other class is called multiple
inheritance.
--multi level inheritance :- we can inherit component of any super class.
to the subclass.
object for calling lo_anima_super
---lo_animal_super->eat().means object of superclass is calling to subclass.
inheriting
fromnot call super class method it wil call sub class.
---it will
---lo_animal_super->barking(
lcl_animal dog ). object of super class is used to call method of subclass.
---lo_dog_sub->barking().
---before you done wide casting you have to do it narrow casting otherwise it will give error.
--INTERVIEW Q'S:-
--- before you done wide casting you have to do it narrow casting otherwise it will give error,
--
--- IMPORTING transfers a value from the caller to the called method by passing an actual
parameter
transfer exporting
-- is just opposite to what IMPORTING does. IT passes value from the method to Caller.
EXPORTING
-- CHANGING is transferring the value from caller to method by a variable which is processed or
changed and the changed value is passed back to the Caller. Thus it combines both
IMPORTING and EXPORTING function.
process /changed
---returning --it is also output parameter just like exporting by it passed by value only
caller method
and used with functonal method. by variable
-- When we call a Method, RECEIVING is used for Actual Parameter to receive the return value of Method in data
object.
------------------------------------------FUNCTION MODULE---------------------
--options means wheter it is equal to low range and high range(EQ) or BT(BETWEEN LOW/HIGH)
---------------------------------------EVENT HANDLER-----------------------------------------
--GLOBALLY
---
--if we don't define set handler than controller do not go to excetute the table it_lfa1 and there
is no o/p.