You are on page 1of 38

` OOPS ABAP

-class:- a template based on which you create real time entities called object.

--class car definition

endclass.

---this is local class scope of the class lies inside only this program.

--class is actually composed of attributes and methods.

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.

--so car what is characterstic is have we have name,color,fuel type.

-- start of selection.

---defin and create object.


--data : car1 type ref to car(object or refrence variable).(define) in this no memory is allocated.

--create object car1.a memory is allocated for car1 object.

- you can create multiple objects based on single class called car.
single class car
name,color,fuel

multiple objects

car1 car2 car3 car4 car5


name,colo,fuel name,colo,fuel name,colo,fuel name,colo,fuel name,colo,fuel

--- use write car->name to acess the attributes of the class.

--default values are getting assign based on data type .

-- car1->name = 'MARUTI SWIFT'.

---now maruti swift is assign to car1.

--we can also create and define it in one line.


define object
data: car1 type ref to car

create object
creat object car1.

ACESS the object


CAR1->NAME,CAR1->COLOR,CAR1->FUEL

PRINT THE OBJECT


CAR->NAME1 = 'MARUTI SWIFT'.

CAR1->COLOR = 'RED'.

CAR1->FUEL TYPE = 'PETROL'

----------------------- CONSTRUCTOR-------------------------
--IT is also method of class

--- define constructor METHODS : constructor.

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

---display method do not call b/c we have not define it explicitely.

--we hace to call like car1->display( ).

--constructor is used to provide default value of object and attributes.

--

method constructor
IMPORTING
IMPORTING IMPORTING

im_name im_color im_fuel_type

= name color fuel type

class

----means provided default value for attributes


--we can also define in another way.

-both attributes and parameter has same name so sap can't differentate it.

--so use me keyword for attribue differentiation.

--- association between class


define another class

--- this statment connect one class to another class ie.person to car class( person o_car)

---now define and create object for person class.

--p1->car means person of one class drives car of other class.

---connects class of car and person .

car
person
NAME,COLOR,FUEL TYPE
NAME AGE
->CONNECT

---p1->car = car1--assign class into method.

--write : p1->car->name.

---instead of direct assign we have to define display method.


-------------------------------------------STATIC V/S INSTANCE VARIABLE--------

--ONLY one memory is assign to static attribute so we can overwrite it also.

---but in instance each object is created there is new memory allocated to it.

---we need to create obejct to call instantaneous method.

------------- abstract class


--it is a class that can have concrete method as well as abstract method.

--concrete method have implementation.

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

-- it automatically throw output sleep.

--if any one of method of is abstract the class will become abstract.

--but if class is abstract it is not necessary that method is also abstract.


--

--abstract class:-it is a class which have partial implemenatation.

---------------------GLOBAL CLASS

--IF click on final means we can't inherit the final class.

----------------------------------- segment function----------


--EX- lv_string = 'ABC,CDE,EFG'.

--there is a comma seprated the indvisual contents of this data .


--we have another deliminator link ABC/CDE/EFG.

--all deliminator is dealing with segment function.

--suraj,sam,jim are the values in lv_data which is seprated by comm.

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

--provide segment definition:-

--and result i will capture in

--write : / lv_result.
--

---index = sy-index when we looping from do enddo it will start from 1 and end with 4.

------------------------------------ for operator


--value operator is used for creating internal table.
---for operator is always used for iteration.
---- one more implemantation tt_data type table of ty_data with empty key.

--meaning when c1>30 take the work area wa and put it in it_data2.

----above statement similar to loop at it_data2 into wa_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.

--but a constructor have importing parameter and exception as well.

-- in class-constructor will call first after that constructor.

--------------------------public private protected----------------------------------------

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

----in this section we define two seprate class.

--to acess into one class we define object and create it.

----only public section attributes can be acess b/w two classes.


---means from different class protected and private attributes is not allowed.

--private section can be acess only the respective class.

-------------------------------------- SUPER KEYWORD------------------------------------------


---

--In this example we define class and subclass.

--- when we calling get_data it will always show get data from subclass.

---so to get the from super class we use:-

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

------------------- --FINAL CLASS AND FINAL METHOD

--if A class is define as final then we can't inherit any subclass.


---a method is define as final you can't redefine this method in subclass.

---- how to check if string is pallindrom or not.

--pallindrom mean s if it is reverse it can't change like TENET.


-----------------------PERSISTANCE CLASS---------------------------

---

-- GO TO SE11
---

--as we create persistance class it has two more classes

--on is base class zcb_pk_persistance_emp which is base class and is always the abstract class means

it is partially implemented.

---other is actor class zca_pk_persistance_emp.

--go to persistance service.


--give the table name in persistance service bc we have to store the data in persistance service

which is lies b/w database layer and application layer.

from database uploading data to persistance service

---how we can use create update delete of persistance data.


----
main class zcl_persistance_emp.

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

--go_emp = go_agent->create_persistent( i_emp_id = 1)

--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-----------------------------

--it is using one class with components of another class.

--single inheritance:one clss inherting the component of another class.

---one class is super class and another is subclass.

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

-------WIDENING CAT AND NARROW CAST-------------------


--- In narrowing cast

---in widening cast:


--example of narrow casting.
lcl_animal_superclass
---- for narrow casting (lo_dog_sub =
method eat.
lo_animal_super) assigning instance of 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.

method eat redfinitaion

object for caliing lo_dog_sub


-- wide casting: assign instance of superclass to the refrence/instance subclass and call the
method of subclass.

--as you assign superclass to subclass but we call from subclass.

--- lo_dog_sub ?= lo_animal_super.

--?= is called wide casting operator.

---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,

WHAT kind of exception is there.


------EXPORT AND IMPORT KEYWOD IN SAP OOPS------------

--

---If we want to export we have to create memory id like'MAX'.

---to that memory id we have to export the data.

---and in second program for ex:-


--we have to submit the program and use import keyowrd.

--- IMPORTING transfers a value from the caller to the called method by passing an actual
parameter

caller method transfer importing calling method

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---------------------

====SIGN OPTION ;OW HIGH===========


---SIGN IS AN INDICATOR which tells whether we can include and exculde the values in low and
high fields.

---I for include E for exclude.

--options means wheter it is equal to low range and high range(EQ) or BT(BETWEEN LOW/HIGH)

---------------------------------------EVENT HANDLER-----------------------------------------

--GLOBALLY

--create event and its parameter.

---

--now create event handler and its parameter


---click on detail view to show event handler is selected.
--create method triger for display o/p and its parameters.
--

--if we don't define set handler than controller do not go to excetute the table it_lfa1 and there
is no o/p.

You might also like