oops abap ibm

Upload: arivchand

Post on 01-Mar-2016

30 views

Category:

Documents


2 download

DESCRIPTION

Oops Abap Ibm

TRANSCRIPT

  • 7/18/2019 Oops Abap Ibm

    1/123

    IBM Global Services

    Copyright IBM Corporation 2003

    April,2004

  • 7/18/2019 Oops Abap Ibm

    2/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Topics to cover

    Different approaches to Programming

    Class and objects

    Methods

    Constructor

    Inheritance

    Interface

    Friendship between Classes

    Events

    Class-Based Eceptions

  • 7/18/2019 Oops Abap Ibm

    3/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Different approaches of Programming

    !nstructured Programming"Procedural Programming"

    #bject #riented Programming"

  • 7/18/2019 Oops Abap Ibm

    4/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Unstructured Programming

    Consists of onl$ one main program"

    %he program stands for a se&uence of

    commands which modif$ data that isglobal throughout the whole program"

    Characteristics

    Difficult to manage once the programbecomes large"

    'ame se&uence of statements arerepeated at multiple places( if the$ areneeded at multiple locations"

    Disavantages

    report ysubdel.DATA : sal type p decimals 2, itax type p decimals 2,

    net_sal type p decimals 2 .

    sal = 12000. IF sal lt 000 . itax = 0. !"#!. itax = sal $ %0.01%. !&DIF. net_sal = sal ' itax. (rite:) sal , itax ,net_sal.sal = *00.

    IF sal lt 000 . itax = 0.!"#!. itax = sal $ %0.01%.!&DIF. net_sal = sal ' itax. (rite:) sal , itax ,net_sal.

  • 7/18/2019 Oops Abap Ibm

    5/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Procedural Programming

    Programmer combines related se&uencesof statements into one single place( calledprocedure"

    ) procedure call is used to invo*e theprocedure"

    )fter the se&uence is processed( flow ofcontrol proceeds right after the positionwhere the call was made"

    report ysubdel.DATA : sal type p decimals 2 ,

    itax type p decimals 2 ,

    net_sal type p decimals 2.

    sal = 12000.

    PERFORMsub_calc_tax +#I&

    sal itax net_sal. sal = *00.

    PERFORMsub_calc_tax +#I&

    sal itax net_sal.

    FORMsub_calc_tax +#I&-_#A" -_ITA -_&!T_#A".

    IF p_sal lt 000 .

    p_itax = 0.

    !"#!.

    p_itax = sal $ %0.01%.

    !&DIF.

    p_net_sal = p_sal ' p_itax.

    ENDFORM.

  • 7/18/2019 Oops Abap Ibm

    6/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Object Oriented Programming

    Class e!ine an

    i"ple"ente

    #b$ect create !ro"

    the class an %se

    Classes and objects areused to model real worldentit$"

    Methods inside the classesperform the functions"

    Data used b$ the classesare protected between them"

  • 7/18/2019 Oops Abap Ibm

    7/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Comparison between Procedural and Object Oriented

    Programming

    &eat%res 'roce%re #rienteapproach

    #b$ect #riente approach

    ("phasis Emphasis on tas*s Emphasis on things that does thosetas*s

    Mo%lari)ation Programs are divided intosmaller programs *nown as

    functions

    Programs are organi+ed into classes

    and objects and the functionalities

    are embedded into methods of a

    class"Data sec%rity Most of the functions share

    global data

    Data can be hidden and cannot be

    accessed b$ eternal sources"

    (*tensibility ,elativel$ more time consumingto modif$ for etending eisting

    functionalit$"

    ew data and functions can be easil$

    added whenever necessar$

  • 7/18/2019 Oops Abap Ibm

    8/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Object Oriented Approach - ke features

    ." Better Programming 'tructure

    /" ,eal world entit$ can be modeled ver$ well

    0"'tress on data securit$ and access

    1" Data encapsulation and abstraction

    2" ,eduction in code redundanc$

  • 7/18/2019 Oops Abap Ibm

    9/123

    IBM Global Services

    Copyright IBM Corporation 2003

    !e"uirement for learning OOP# in A$AP

    )dopt the universal approach for modern programming"

    3now the latest )B)P technologies-B)DI(wor*flow(4I( Custom controls etc

    !se )B)P to integrate with Microsoft %echnologies (5ava etc

    Eploit class resources and functionalities provided b$ ')P"

  • 7/18/2019 Oops Abap Ibm

    10/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Topics to cover

    Different approaches to Programming

    Class and objects

    Methods

    Constructor

    Inheritance

    Interface

    Friendship between Classes

    Events

    Class-Based Eceptions

  • 7/18/2019 Oops Abap Ibm

    11/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Class and Object

    Class is the te"plate o! an ob$ect+ It is an abstract concept, hich is reali)e by

    creating an ob$ect !ro" it+

    What is your idea about a Maruti-800 car? You will say that it is afour-wheel, ve seater vehicle with a 800 cc engine.

    The idea you have in your ind is the classfor Maruti-800.!et us

    call it as class Maruti-800.

    "ow, you see a real Maruti-800 car in front of you. #o, this is theobjectof class Maruti-800. $n other words, the real car is reali%ation&instantiation of the class Maruti-800.

    Still con!%se--- #+. ++see the e*a"ple belo

  • 7/18/2019 Oops Abap Ibm

    12/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Attributes of Object Oriented Programming

    Abstraction / (verything is vis%ali)e in ter"s o! classes an ob$ects+

    (ncaps%lation /ecessary ata are hien !ro" the %sers in class+

    Inheritance / A class can be replicate into a s%bclass , hich can be "oi!ie+

    'oly"orphis" /Methos o! sa"e na"e behave i!!erently in i!!erent classes+

  • 7/18/2019 Oops Abap Ibm

    13/123

    IBM Global Services

    Copyright IBM Corporation 2003

    %ocal and &lobal Classes

    Global Class 1ocal Class

    )n$ program #nl$ the program where it is defined"

    In the Class ,epositor$ #nl$ in the program where it is

    defined"

    Created using transaction 'E/1 Created using 'E06

    Must begin with 7 or 8 Can begin with an$ character

    Accessed b

    #tored in

    Created b

    'amespace

  • 7/18/2019 Oops Abap Ibm

    14/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Defining %ocal Classes

    /!-/T #+-#13 .

    CLASSc1 DEFINITION.

    -+"I4 #!4TI&.

    data : (_num type i 5alue .

    met6ods : m1.

    ENDCLASS.

    4"A## c1 I7-"!7!&TATI&.

    7!T8D 71.

    9/IT!:) %I am 71 in 41%.

    !&D7!T8D.

    !&D4"A##.#TA/T'F'#!"!4TI&.

    DATA : ore1 T-! /!F T c1 .

    4/!AT! ;!4T : ore1.

    (rite:) ore1'

  • 7/18/2019 Oops Abap Ibm

    15/123

    IBM Global Services

    Copyright IBM Corporation 2003

    (mplementing %ocal Classes

    1ocal class in a progra" is i"ple"ente as

    !ollos/

    CLASS IMPLEMENTATION.

    ..

    ENDCLASS.Methos %se by the class are escribe here+

    A class can be i"ple"ente

    At the en o! the progra" lie s%bro%tines5+

    A!ter the class e!inition+

    I! the latter is aopte, one "%st then assign

    s%bse6%ent noneclarative state"ents e*plicitly to a

    processing bloc, s%ch asSTART-OF-SELECTION( so that they can be accesse"

    /!-/T #+-#13 .

    CLASSc1 DEFINITION.

    -+"I4 #!4TI&.

    data : (_num type i 5alue .

    met6ods : m1.

    ENDCLASS.

    CLASSc1 IMPLEMENTATION.

    7!T8D 71.

    9/IT!:) %I am 71 in 41%.

    !&D7!T8D.

    ENDCLASS.#TA/T'F'#!"!4TI&.

    DATA : ore1 T-! /!F T c1 .

    4/!AT! ;!4T : ore1.

    (rite:) ore1'

  • 7/18/2019 Oops Abap Ibm

    16/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Different places of implementing class

    Class implemented at the end of theprogram

    Class implemented after Definition

  • 7/18/2019 Oops Abap Ibm

    17/123

    IBM Global Services

    Copyright IBM Corporation 2003

    )ho can use a class*

    class c2 e!inition inheriting !ro"c7+

    p%blic section +

    "ethos / "2+

    enclass+

    class c2 i"ple"entation+

    "etho "2+

    rite/89 :+rom subclass, w.num+

    en"etho+

    enclass+

    ;('#;< =S>B##'S7? +

    C1ASS c7 D(&II

  • 7/18/2019 Oops Abap Ibm

    18/123

    IBM Global Services

    Copyright IBM Corporation 2003

    #ections of a Class

    CLASS C1 DEFINITION.

    PUBLIC SECTION.

    DATA:

    METHODS:

    EVENTS:

    PROTECTED SECTION.

    DATA:

    METHODS:

    EVENTS:

    PRIVATE SECTION.

    DATA:

    METHODS:

    EVENTS:

    ENDCLASS.

    A Class p%ts its co"ponents %ner three istinct

    sections/

    Public Sectin!-Co"ponents place here !or"the e*ternal inter!ace o! the class they are

    visible to all %sers o! the class as ell as to

    "ethos ithin the class an to "ethos o!s%bclasses

    P"tecte# Sectin!-Co"ponents place inprotecte section are visible to the chilren o! the

    classs%bclass5 as ell as ithin the class

    P"i$ate Sectin9-Co"ponents place here areaccessible by the class itsel!+

    %here is no default visibilit$ section in a class"

    %his se&uence of visibilit$ must be maintainedin a class

  • 7/18/2019 Oops Abap Ibm

    19/123

    IBM Global Services

    Copyright IBM Corporation 2003

    A #ill 23ample

    7ou are an emplo$ee ;object of class9- emplo$ee

  • 7/18/2019 Oops Abap Ibm

    20/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Components of a Class

    A Class basically contains the !olloing/

    Att"ibutes9-Any ata,constants,types eclare ithin a class !or" the attrib%te o!the class+

    Mets9-Bloc o! coe, proviing so"e !%nctionality o!!ere by the class+ Can beco"pare to !%nction "o%les"

    E$ents9-A "echanis" set ithin a class hich can help a class to trigger "ethos o!

    other class+

    Inte"'aces9-Inter!aces are inepenent str%ct%res that yo% can i"ple"ent in a classto e*ten the scope o! that class"

  • 7/18/2019 Oops Abap Ibm

    21/123

    IBM Global Services

    Copyright IBM Corporation 2003

    (nstance and #tatic Components

    /!-/T #+-#13 .4"A## c1 D!FI&ITI&.-+"I4 #!4TI&. data :i_num type i 5alue . class-data :

    s_num type i 5alue .

    !&D4"A##.

    4"A## c1 I7-"!7!&TATI&.!&D4"A##.

    #TA/T'F'#!"!4TI&.DATA : ore1 T-! /!F T c1 .

    4/!AT! ;!4T : ore1.(rite:) ore1->i_num.(rite:) c1=>s_num .(rite:) ore1->s_num.

    Instance co"ponents e*ist

    separately in each instance

    ob$ect5 o! the class an are

    re!erre %sing instance

    co"ponent selector %sing :+

    Static co"ponents only e*ist

    once per class an are vali !or

    all instances o! the class+

  • 7/18/2019 Oops Abap Ibm

    22/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Two Additions in %ocal Class Definition

    A##itin ( ! CLASS class DEFINITION DEFERRED.

    !sed to refer to a class at some point in a code and the class is notdefined before the line"

    4"A## 42 DEFINITION DEFERRED.

    4"A## 41 D!FI&ITI&.

    -+"I4 #!4TI&.

    DATA 2 TYPE REF TO C2.

    !&D4"A##.

    4"A## 42 D!FI&ITI&.

    public section.

    data : num type i 5alue .

    !&D4"A##.

    start'o'selection.

    data : ob?1 type re to 41.

    4/!AT! ;!4T ob?1.

    create ob?ect ob?1'

  • 7/18/2019 Oops Abap Ibm

    23/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Two Additions in %ocal Class Definition

    A##itin ) ! CLASS class DEFINITION LOAD

    %he co'iler norally loads the descri'tion of a globalclass frothe class librarythe rst tie you use the class in your 'rogra .(owever, if the rst access to a global class in a 'rogra is to its

    static componentsor in the denition of an event handlermethod, you ust load it e)'licitly using the stateent *!+## class$"$T$/" !/+. This variant has no corres'onding "*!+##stateent.

    IBM Gl b l S i

    http://sapevent/http://sapevent/
  • 7/18/2019 Oops Abap Ibm

    24/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Creating an Object

    %o create an object ( the following stepsneed to be followed9-

    'tep .9 Create a reference variable withreference to the class"

    DATA !=object name> T*PE REF TO=class name>"

    'tep / 9 Create an object from the referencevariable9-

    C,E)%E #B5EC% =object name>"

    report ysubdel.

    4"A## c1 D!FI&ITI&.

    -+"I4 #!4TI&.

    DATA : pro@BC type c 5alue%AA-%.

    !&D4"A##.

    4"A## c1 I7-"!7!&TATI&.

    !&D4"A##.

    #TA/T'F'#!"!4TI&.

    DATA : ob?1 type re to c1.

    CREATE OBJECT: ;1.

    (rite:) ob?1'

  • 7/18/2019 Oops Abap Ibm

    25/123

    IBM Global Services

    Copyright IBM Corporation 2003

    C!2AT2 PU$%(C5P!OT2CT2D5P!(6AT2 ADD(T(O'#

    #nta3 /C%A## 7classname1 D2+('(T(O' 8 9C!2AT2 PU$%(C5P!OT2CT2D5P!(6AT2:

    C,E)%E P!B?ICaition is i"plicit in every class e!inition i! the other C;(A

  • 7/18/2019 Oops Abap Ibm

    26/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Attributes

    )ttributes are internal data fields within a class that can have an$ )B)Pdata t$pe"

    (nstance Attributes

    (*ist separatel in each instanceob$ect5 o! the class +

    Declare %sing theDATAstate"ent+

    #ne cannot %se theTA+LESorNODESstate"ent in the eclaration part o! theclass+

    #tatic Attributes

    Available once for each class+

    Declare %sing theCLASS-DATAstate"ent an are retaine thro%gho%t the entirer%nti"e+ All the ob$ects ithin a class can access its static attrib%tes+

    IBM Global Services

    http://sapevent/http://sapevent/http://sapevent/http://sapevent/http://sapevent/http://sapevent/http://sapevent/http://sapevent/
  • 7/18/2019 Oops Abap Ibm

    27/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Attributes8continued

    Tpes and Constants in Classes

    T,%es

    T*PESstate"ent is %se to e!ine any n%"ber o! yo%r on ABA' ata types ithin aclass+

    Cnstants

    Constants are special static attrib%tes, hose val%es are speci!ie hen they are eclare

    an hich cannot be change later+

  • 7/18/2019 Oops Abap Ibm

    28/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Topics to cover

    Different approaches to Programming

    Class and objects

    Methods

    Constructor

    Inheritance

    Interface

    Friendship between Classes

    Events

    Class-Based Eceptions

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    29/123

    IBM Global Services

    Copyright IBM Corporation 2003

    ;ethods

    Methos are the internal proce%res o! a

    class +

    Eave a para"eter inter!ace, thro%gh

    hich the syste" passes val%es to the"

    hen they are calle, an thro%gh hich

    they can ret%rn val%es to the caller+

    Can access all the attrib%tes o! their class+

  • 7/18/2019 Oops Abap Ibm

    30/123

    IBM Global Services

    Copyright IBM Corporation 2003

    #nta3 for defining methods

    Declare in the e!inition part o! a class or in an inter!ace as !ollos/

    METODS IMPORTIN.. /0AL1E23/43 T*PE t,%e /OPTIONAL3..E6PORTIN.. /0AL1E23/43 T*PE t,%e /OPTIONAL3..

    CANIN.. /0AL1E23/43 T*PE t,%e /OPTIONAL3..

    RET1RNIN 0AL1E2

  • 7/18/2019 Oops Abap Ibm

    31/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Tping Parameters

    )ll parameters mustbe declared using the addition T*PEor the addition LI7E"

    ith LI7E$ou can nl,refer to data t$pes of class attributes *nown at this point in A+APOb8ectsand not to data t$pes from the )B)P Dictionar$"

    %he following entries in the table shown below are allowed after T*PEas parameter t$pes"

    #nta3 !elevance

    T*PE t stands for all data t$pes from the )B)P Dictionar$

    and all A+APdata t$pes *nown at this point+ T*PE AN* stands eplicitl$ for a parameter declaration without

    t$pe reference" %his means that the parameter

    inherits all technical attributes of the parameter that

    has been passed when the method is called" T*PE REF TO ci' stands for a class or interface reference"

    T*PE LINE OF itab stands for the line t$pe of an internal table itab"

    T*PE /AN*9INDE69STANDARD9SORTED9

    ASED3 TA+LEstands for the internal table t$pe of the table t$pe

    specified

    IBM Global Services

    http://sapevent/http://sapevent/
  • 7/18/2019 Oops Abap Ibm

    32/123

    IBM Global Services

    Copyright IBM Corporation 2003

    (mplementing ;ethods

    All "ethos eclare in the e!inition part o! a class

    sho%l be i"ple"ente in the i"ple"entation section o!

    the class ithin the !olloing bloc/

    ME%#D =meth>" """

    EDME%#D"#ne sho%l not speci!y any inter!ace para"eters at the

    ti"e o! i"ple"entation, since these are e!ine in the

    "etho eclaration+

  • 7/18/2019 Oops Abap Ibm

    33/123

    IBM Global Services

    Copyright IBM Corporation 2003

    #tatic ;ethod

    o1ie any other class co"ponents , "ethos canbe static or instance+

    o>>

    oStatic "ethos can have i"port an e*port8changing para"eters 5 or ret%rning para"eters + It

    can also raise e*ceptions+

    oStatic "ethos can only or ith the static

    attrib%tes o! yo%r class+ Instance "ethos can

    or ith both static an instance attrib%tes+

    o#ne can call a static "etho %sing an ob$ect o!

    the class or irectly %sing the class by class

    co"ponent selector+

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    34/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Calling ;ethods

    CALL METOD

    E6PORTIN... :....RECEI0IN " : &E6CEPTIONS... : "c

    i...

    All nonoptional inp%t para"eters "%st be

    passe %sing the (F'#;B##'S7? +DA

  • 7/18/2019 Oops Abap Ibm

    35/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Calling ;ethods8continued

    #nta3 !elevance

    CALL METOD ... Methods of the same class;in the implementation part< can

    be called directl$ using their name =meth>"CALL METOD ... " @isible static methods can be called from outside the class

    using this s$nta where =class> is the name of the relevant

    class"CALL METOD

  • 7/18/2019 Oops Abap Ibm

    36/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Calling ;ethods8continued

    #nta3 !elevance

    CALL METOD 2 '4. !sed to call a method where 9-

    %he interface of a method consists onl$ of a single

    IMP#,%IA parameter

    %here is a single non-optional IMP#,%IA parameter and

    several other optional IMP#,%IA parameters"

    )ll the IMP#,%IA parameters are optional ( one being

    declared as P,EFE,,ED P),)ME%E,"'(:

  • 7/18/2019 Oops Abap Ibm

    37/123

    IBM Global Services

    Copyright IBM Corporation 2003

    Dnamic ;ethod Calls

    Instance( self-referenced( and static methodscan all be called d$namicall$ the class namefor static methods can also be determinedd$namicall$9- oref->;method;method;methodIt is callea%to"atically !or the class before it is accessed for

    the first time that is, be!ore one o! the !olloing

    actions/

    C!2AT2 O$?2CTobj !ro" the class+

    Call a static "etho / 9CA%% ;2T=OD: class41meth+

    ;egistering a static event hanler "etho %sing

    #2T =A'D%2! class41meth for obj>

    ;egistering an event hanler "etho !or a static event

    o! the class class+

    Aressing a static attrib%teith class41a+

    /!-/T #+-#2.4"A## c1 D!FI&ITI& .-+"I4 #!4TI&.4"A##'DATA : &+7 T-! I A"+! .4"A##'7!T8D#:4"A##_4T/+4T/.

    !&D4"A##.

    4"A## c1 I7-"!7!&TATI&.

    7!T8D 4"A##_4T/+4T/.9/IT!:) %I am classconstructor%.

    !&D7!T8D.!&D4"A##.

    #TA/T'F'#!"!4TI&.

    9/IT!:) C1=>NUM.

    IBM Global Services

    http://sapevent/http://sapevent/http://sapevent/http://sapevent/http://sapevent/http://sapevent/http://sapevent/http://sapevent/http://sapevent/http://sapevent/http://sapevent/http://sapevent/
  • 7/18/2019 Oops Abap Ibm

    46/123

    Copyright IBM Corporation 2003

    #tatic Constructor8>continued

    Eception9-

  • 7/18/2019 Oops Abap Ibm

    47/123

    Copyright IBM Corporation 2003

    Comparison between Different ;ethods

    Tpe of;ethod

    Triggering mechanism (mportparameter*

    23portParameter*

    ChangingParameter*

    !eturningParameter*

    Can raise23ceptions*

    (nstance Calle by %sing ob$ect = = = = =

    #tatic Calle by %sing ob$ect

    or re!erring to class

    = = = = =

    (nstanceConstructor

    Calle a%to"atically,i""eiately a!ter theC;(A

  • 7/18/2019 Oops Abap Ibm

    48/123

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    49/123

    Copyright IBM Corporation 2003

    Pointer Tables

    It is possible, in the sa"e progra", toinstantiate "any ob$ects o! the sa"eclass+ Eoever, in "any sit%ationsinternal tables are a "ore elegant ay o!creating a list o! the sa"e in o! ataob$ect

    ;e"e"ber, re!erence variables arehanle lie any other ata ob$ect ith anele"entary ata type

    #%tp%t

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    50/123

    Copyright IBM Corporation 2003

    Topics to cover

    Different approaches to Programming

    Class and objects

    Methods

    Constructor

    Inheritance

    Interface

    Friendship between Classes

    Events

    Class-Based Eceptions

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    51/123

    Copyright IBM Corporation 2003

    (nheritance

    'arent Class S%b Class

    ) single class can give birth to itssubclasses b$ inheritance"

    #ne parent class can have "%ltiple

    s%bclasses, b%t one s%bclass can have only

    one parent class+Eence,multi%le

    in&e"itance is nt all@e# in A+AP.'ubclasses have full access to all thepublic and protected components of parentclass" %he$ can modif$ to re-implementthose components of their own")lso(subclasses can create new components inthem"

    Private components of parent classes arenot *nown to subclasses" %here can becomponents with same name in privatesection in both the parent and subclasses (each one wor*ing and being identifiedseparatel$ in their respective classes"

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    52/123

    Copyright IBM Corporation 2003

    6isibilit of Components

    Each class component has a visibility. In ABAP Objects the whole class definition is

    separated into three visibility sections: PUBLIC, PROTECTED, and PRIVATE. One can

    never change component visibility via inheritance.

    P1+LIC!This section is made up of the subclass' own public components together with all

    public components of all superclasses. There is unrestricted access to the public section of

    the subclass.

    PROTECTED!This section is made up of the subclass' own protected components togetherwith all protected components of all superclasses .

    PRI0ATE!This section is made up of the subclass' own private components accessibleonly in that subclass. Each subclass works with its own private components and can't evenuse the private components of its superclasses. But as long as a method inherited from a

    superclass is not redefined, it still uses the private attributes of the superclass, not those of

    the subclass, even if the subclass has private attributes of the same name.

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    53/123

    Copyright IBM Corporation 2003

    Creating #ubclass

    S%bclasses can be create !ro" its

    s%perclass %sing the synta*/

    C?)'' =subclass> DEFII%I#IE,I%IA F,#M =superclass>"

    S%bclass inherits all the p%blic an protecte

    co"ponents o! the s%perclass+

    S%perclass sho%l not be eclare as a

    &IA1 class+

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    54/123

    Copyright IBM Corporation 2003

    ;odifing methods in subclass

  • 7/18/2019 Oops Abap Ibm

    55/123

    Copyright IBM Corporation 2003

    Abstract ;ethods and Classes

    One cannot create an object from an abstract

    class>#nly s%bclasses can be erive !ro"

    the"+

    C%A## 7classname1 D2+('(T(O' A$#T!ACT>

    Abstract methods cannot be implemented in

    the same class+ #nly the s%bclasses o! thatclass can i"ple"ent it+

    ;2T=OD# 7method.name1 8>A$#T!ACT

    An class containing an abstract method has

    to be an abstract class+ All s%bse6%ent

    s%bclasses that o not i"ple"ent the "etho"%st also be abstract+

  • 7/18/2019 Oops Abap Ibm

    56/123

    Copyright IBM Corporation 2003

    +inal ;ethods and Classes

    &inal classes cannot have s%bclasses+ #nly the

    class can be instantiate+

    CLASS DEFINITION FINAL.

    A !inal "etho cannot be ree!ine ins%bclasses

    METHODS .FINAL

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    57/123

    Copyright IBM Corporation 2003

    (nheritance and #tatic Attributes

    Static attrib%tes only e*ist once in

    each inheritance tree+ #ne can

    change the" !ro" o%tsie the class

    %sing the class co"ponent selector

    ith any class na"e, or ithin any

    class in hich they are share+

  • 7/18/2019 Oops Abap Ibm

    58/123

    Copyright IBM Corporation 2003

    (nheritance and (nstance Constructors

    Case Description Necessity of calling

    constructor of

    superclass by subclass

    . one of the superclass and subclass have

    eplicit constructor"

    ot re&uired

    / 'uperclass have eplicit constructor( but

    subclass does not have an$ eplicit constructor"

    ot re&uired

    0 'uperclass does not have an eplicit

    constructor( but subclass have one"

    ,e&uired

    1 Both the superclass and subclass have eplicit

    constructor

    ,e&uired

    S%perclasses an8or s%bclasses can have e*plicit constr%ctors o! their on+

    Constr%ctor o! a s%bclass so"eti"es have to call the constr%ctor o! the s%perclass

    %sing9 CALL METOD ! S1PER->CONSTR1CTORepening on the !olloing/

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    59/123

    Copyright IBM Corporation 2003

    (nheritance and #tatic Constructors

    Every class has a static constructor called CLASS_CONSTRUCTOR.

    The first when a subclass in a program is accessed, its static constructor is executed. But,

    before it can be executed, the static constructors of all of its superclasses must already

    have been executed. A static constructor may only be called once per program. Therefore,

    when one first address a subclass, the system looks for the next-highest superclass whosestatic constructor has not yet been executed. It executes the static constructor of that class,

    followed by those of all classes between that class and the subclass that is addressed.

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    60/123

    Copyright IBM Corporation 2003

    (nheritance and (nstance Creation

    &or eachin#i$i#ual class( theCREATE P1+LIC9PROTECTED9PRI0ATEaitions tothe C1ASSstate"ent control ho can create an instance o! the class or, in other ors,

    can call its instance constr%ctor+

  • 7/18/2019 Oops Abap Ibm

    61/123

    Copyright IBM Corporation 2003

    (nheritance and (nstance Creation

    (. Su%e"class @it& a##itin CREATE PROTECTED

    Subclasses can have every CREATE addition. Without addition they inherit the attribute

    CREATE PROTECTED. The superclass allows its subclasses unlimited instantiation and

    therefore also the publishing of its protected instance constructor.

    (. Su%e"class @it& a##itin CREATE PRI0ATE

    If the subclass is not a friendof super class , the subclass cannot be instantiated. None of

    the CREATEadditions is permitted with the subclass, because this would always lead to

    the unauthorized publishing of the superclass constructor.

    If the subclass is a friendof super class, all CREATEadditions are permitted with thesubclass. The default one is CREATE PRIVATE. As a friend, the subclass can publish the

    superclass' private constructor in any form.

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    62/123

    Copyright IBM Corporation 2003

    #tatic Tpe and Dnamic Tpe of a 6ariable

    The statictype is the type (class or interface) with which the reference variable has beentyped.

    DATA : oref type ref to c1. Static type of oref is pointing to class c1

    The dynamictype is the class of the object to which the reference in a reference variable

    points .

    CREATE OBJECT OREF. Dynamic type also points to c1

    CREATE OBJECT OREF TYPE C2. Dynamic type points to subclass c2 of C1

    If the static and dynamic types of a reference variable are different, the static type should

    always be more general than the dynamic type.

    .

    S%perclass #B@(C< Any classIts s%bclass

    #peciali@ation increases

    &enerali@ation (ncreases

    Class / C0

    Class / C

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    63/123

    Copyright IBM Corporation 2003

    Assignment between !eference 6ariables

    If you make assignments between reference variables, the static type of the target

    variable must always be same or more generic than the dynamic type of the source

    variable.

    For example, a super class is always more generic than its subclass.

    Syntax check for the program ensures that static type of target variable is more general than

    static type of source variable.

    S%perclass #B@(C< Any classIts s%bclass

    #peciali@ation increases

    &enerali@ation (ncreases

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    64/123

    Copyright IBM Corporation 2003

    'arrowing Cast

    NarroingO cast "eans that the assign"ent changes !ro" a "ore speciali)e vie ith

    visibility to "ore co"ponents5 to a "ore generali)e vie ith visibility to !eer

    co"ponents5+

    N'arrowing castO is also re!erre to as N%p castO + N>p castO "eans that the static type o!the target variable can only change to higher noes !ro" the static type o! the so%rce

    variable in the inheritance tree, b%t not vice versa+

    S%perclass #B@(C< Any classIts s%bclass

    #peciali@ation increases

    &enerali@ation (ncreases

    %he static t$pe of the target variable mustalwa$s be more generic than the static t$pe ofthe source variable"

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    65/123

    Copyright IBM Corporation 2003

    23ample of 'arrowing Cast

    !eference variable of a classassigned to reference variable of

    class / object

    !eference variable of a subclass

    assigned to reference variable of its

    superclass>

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    66/123

    Copyright IBM Corporation 2003

    )idening Cast

    DATA: o_ref1 TYPE REF TO object,o_ref TYPE REF TO c!"##.

    ...

    o_ref $% o_ref1.

    ...

    CATH SYSTEM&E'CEPTIONS(o)e_c"#t_error % *.

    o_ref $% o_ref1.

    ENDCATCH.

    In so"e cases, yo% "ay ish to "ae an assign"ent in

    hich the static type o! the target variable is less general

    than the static type o! the so%rce variable+

  • 7/18/2019 Oops Abap Ibm

    67/123

    Copyright IBM Corporation 2003

    Polmorphism via (nheritance

    Kith inheritance, a re!erence variable

    e!ine ith respect to a class "ay not only

    point to instances o! that b%t also to

    instances o! s%bclasses o! the sa"e+ #ne

    can even create s%bclass ob$ects %sing a

    re!erence variable type ith respect to a

    s%per class+

    'oly"orphis" thro%gh inheritance can be

    achieve by playing ith static an yna"ic

    type o! a re!erence variable+

    Instances o! a s%bclass "ay be %se

    thro%gh the s%per classPs inter!ace+ Khenthis is one, a client canPt access all

    co"ponents e!ine in the s%bclass, only

    those inherite !ro" the respective s%per

    class+

    classc1 d!"#"t"$#.. . . . . . .

    #dclass.

    classc1 "%&l%#tat"$#'

    ' ' ' ' ' '

    #dclass'

    classc2 deinition "#()"t"#* !)$%c1.. . . . . .

    #dclass.

    classc2 "%&l%#tat"$#.

    . . . . . . .

    #dclass.

    sta)t-$!-slct"$#.

    data : ore1 type re to c1,

    ore11 type re to c1,

    ore2 type re to c2.

    create ob?ect ore1 type c2 .

    create ob?ect ore2.

    ore11 = ore2.

    (rite:) ore1'

  • 7/18/2019 Oops Abap Ibm

    68/123

    Copyright IBM Corporation 2003

    (nheritance B Object !eferences

    (*ternal Inter!ace

    DATA: oref1 TYPE REF TO C1,oref+ TYPE REF TO C+.

    ...

    CREATE O-ECT oref+.

    oref1 % oref+.

    a0

    m0

    a7

    a2

    a3

    "7

    "2

    "3

    ;e!erence variables eclare ithre!erence to a s%perclass incl%ing an

    abstract class5 can point to an ob$ect o!

    a s%bclass o! this s%perclass, b%t only

    access the co"ponents o! that ob$ect

    that are non to the s%perclass+

    C3 IE(;I

  • 7/18/2019 Oops Abap Ibm

    69/123

    Copyright IBM Corporation 2003

    (nheritance B Object !eferences E

    (*ternal Inter!ace

    DATA: oref1 TYPE REF TO C1....

    CREATE O-ECT oref1 TYPE C+.

    a0

    m0

  • 7/18/2019 Oops Abap Ibm

    70/123

    Copyright IBM Corporation 2003

    Topics to cover

    Different approaches to Programming

    Class and objects

    Methods

    Constructor

    Inheritance

    Interface

    Friendship between Classes

    Events

    Class-Based Eceptions

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    71/123

    Copyright IBM Corporation 2003

    (nterface

    Independent structures containing definition of its own components"

    Incorporated in the public section of a class definition and the methodsof the interface are implemented in the implementation section of thatclass"

    Etends the scope of a class b$ adding their own components to itspublic section"

    )llows users to address different classes via a universal point ofcontact"

    Interfaces( along with inheritance( provide one of the pillars ofpol$morphism( since the$ allow a single method within an interface tobehave differentl$ in different classes"

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    72/123

    Copyright IBM Corporation 2003

    Defining (nterfaces

    Can be eclare globally or locally ithin aprogra"+

    1ocally eclare in the global portion o! a progra"

    %sing/

    ('T2!+AC2 7intf1>

    >>>

    2'D('T2!+AC2>

  • 7/18/2019 Oops Abap Ibm

    73/123

    Copyright IBM Corporation 2003

    Defining (nterfaces8> A few additions

    75 INTERFACE

  • 7/18/2019 Oops Abap Ibm

    74/123

    Copyright IBM Corporation 2003

    Defining (nterfaces8> Additions for (mplementation in Classes

    Addition Efect

    ... A+STRACT METODSmet&( ... met&n

    )ssigns the propert$ A+STRACTto the specifiedinstance methods of the interface"

    ... FINAL METODS met&( ...met&n

    )ssigns the propert$ FINALto the specifiedinstance methods of the interface"

    ... ALL METODS A+STRACT )ssigns the propert$ A+STRACTto all instancemethods of the interface"

    ... ALL METODS FINAL )ssigns the propert$ FINALto all instancemethods of the interface"

    ... DATA 0AL1ES att"( :$al( ... att"n : $aln

    Assigns initial val%es to the attrib%tes speci!ie DATA,

    C%A##-DATA5+

  • 7/18/2019 Oops Abap Ibm

    75/123

    Copyright IBM Corporation 2003

    Component of (nterfaces

    %he interface cm%nentsare declared in the I%E,F)CEEDI%E,F)CEbloc*"

    Instance Cm%nents Static Cm%nents

    DATA for instance attributes CLASS-DATA for static attributes

    METODS for instance methods CLASS-METODS for static methods

    E0ENTS for instance events CLASS-E0ENTS for static events

    T*PES for internal class t$pes CONSTANTS For constants

    Ot&e" Inte"'ace Cm%nents

    I%E,F)CE'!or nesting inter!aces)?I)'E'!or aliases !or co"ponents o! inter!aces

    #ne cannot %se the A1>( aition ith the DA

  • 7/18/2019 Oops Abap Ibm

    76/123

    Copyright IBM Corporation 2003

    (mplementing (nterfaces

    Inter!aces o not have instances+ ;ather, they are i"ple"ente by classes+ &or that,

    inter!aces are incl%e in the p%blic section o! a class e!inition %sing the !olloing

    synta*/

    I%E,F)CE' =intf>"

  • 7/18/2019 Oops Abap Ibm

    77/123

    Copyright IBM Corporation 2003

    (nterface !eference

    1ie classes , re!erence variables can be create ith respect to an inter!ace

  • 7/18/2019 Oops Abap Ibm

    78/123

    Copyright IBM Corporation 2003

    Addressing Objects using (nterface !eference

    I! a class Qclass i"ple"ents an inter!ace Qint!, the inter!ace re!erence variable Qire!

    can be assigne the class re!erence variable Qcre! to "ae the inter!ace re!erence in

    Qire! point to the sa"e ob$ect as the class re!erence in Qcre!+ G =cref>

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    79/123

    Copyright IBM Corporation 2003

    Assignment using (nterface !eferences

    #ne can assign inter!ace re!erences to other inter!ace8class re!erence variables, %sing

    M#( state"ent or the assign"ent operator 5 + Eoever, there are certain restrictions

    hile oing so+ Khen one oes this in a progra", syste" "%st be able to recogni)e in the

    synta* chec hether an assign"ent is possible+

    S%ppose e have a class re!erence Qcre! an inter!ace re!erences Qire!, Qire!7, an

    Qire!2+

  • 7/18/2019 Oops Abap Ibm

    80/123

    Copyright IBM Corporation 2003

    Assignment using (nterface !eferences8check at !untime

    Besies static chec, yna"ic chec to ens%re consistency o! assign"ent o! inter!ace

    re!erences+

    &or that, the casting operator - or M#( -

  • 7/18/2019 Oops Abap Ibm

    81/123

    Copyright IBM Corporation 2003

    (nterfaces B Defining and (mplementing Compound (nterfaces

    CLASS c1 DEFINITION.

    PLIC SECTION.

    INTERFACES: /*.

    ENDCLASS.

    CLASS c1 IMPLEMENTATION.

    METHOD /10(et.

    2

    ENDMETHOD.

    METHOD /0(et.

    2

    ENDMETHOD.

    METHOD /+0(et.

    2

    ENDMETHOD.

    ENDCLASS.

    INTERFACE /1.

    METHODS (et.

    ENDINTERFACE.

    INTERFACE /.

    METHODS (et.

    INTERFACES /1.

    ENDINTERFACE.

    INTERFACE /+.

    METHODS (et.

    INTERFACES: /1, /.

    ENDINTERFACE.

    INTERFACE /*.

    INTERFACES /+.

    ENDINTERFACE.

    =o% can co"pose a ne inter!ace !ro" several e*isting

    ones+ S%ch an inter!ace is calle a compound

    interfaceL an inter!ace hich is containe in another

    inter!ace is calle a component interface

  • 7/18/2019 Oops Abap Ibm

    82/123

    Copyright IBM Corporation 2003

    (nterfaces B Alias 'ames

    CLASS c1 DEFINITION.

    PLIC SECTION.

    INTERFACES: /1.

    ALIASES (1 for/10(et.

    ENDCLASS.

    CLASS c1 IMPLEMENTATION.

    METHOD /10(et.2

    ENDMETHOD.

    ENDCLASS.

    DATA: oref TYPE REF TO c1.

    CREATE O-ECT oref.

    CALL METHOD oref&3(1.

    INTERFACE /1.

    METHODS (et.

    ENDINTERFACE.

    INTERFACE /.

    INTERFACES /1.

    ALIASES (1 FOR /10(et.

    ENDINTERFACE.

    INTERFACE /+.

    INTERFACES /1, /.

    ALIASES (1 FOR /0(1.

    ENDINTERFACE.

  • 7/18/2019 Oops Abap Ibm

    83/123

    Copyright IBM Corporation 2003

    Topics to cover

    Different approaches to Programming

    Class and objects

    Methods

    Constructor

    Inheritance

    Interface

    Friendship between Classes

    Events

    Class-Based Eceptions

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    84/123

    Copyright IBM Corporation 2003

    +riends

    In classes, there is nor"ally a strict ivision beteen o%tsie PU$%(C5 an

    insie P!OT2CT2Dor P!(6AT25+ A %ser can only access the p%blic

    co"ponents o! a class+ A s%bclass have access to p%blic an protecte sections

    o! its s%perclass+

    In rare cases, classes have to or together so closely that they nee access toone anothersP protecte or private co"ponents+ In orer to prevent these

    co"ponents being available to all %sers, there is the concept o! !rienship

    beteen classes+

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    85/123

    Copyright IBM Corporation 2003

    +riends8continued

    A class can eclare other classes an inter!aces an hence all classes that i"ple"ent

    this inter!ace5 as !riens by incl%ing +!(2'D#aitions to the C1ASS +++ D(&II

  • 7/18/2019 Oops Abap Ibm

    86/123

    Copyright IBM Corporation 2003

    6arious Additions to the +riends

    %he CLASS ... DEFINITIONstatement has mainl$ two differentFRIENDSadditions to offer friendship to other classes:interfaces9

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    87/123

    Copyright IBM Corporation 2003

    +riends8continued

    C7 C2&rants friendship to

    C77 C22

    (nherited to (nherited to

    #tatement IesF'o

    C2 can access all attrib%tes8"ethos o! C7 !ro" any section+ =

    C2 can create instances o! C7, irrespective o! its C;(A

  • 7/18/2019 Oops Abap Ibm

    88/123

    Copyright IBM Corporation 2003

    Topics to cover

    Different approaches to Programming

    Class and objects

    Methods

    Constructor

    Inheritance

    Interface

    Friendship between Classes

    Events

    Class-Based Eceptions

  • 7/18/2019 Oops Abap Ibm

    89/123

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    90/123

    Copyright IBM Corporation 2003

    Declaring events

    (vents are eclare in the eclaration part o! a class or in an inter!ace+

  • 7/18/2019 Oops Abap Ibm

    91/123

    Copyright IBM Corporation 2003

    Triggering 2vents

    An instance event in a class can be triggere by any "etho in the class+ Static events

    can be triggere by any static "etho+ G =f i>"""&or each !or"al para"eter 7e i 1that is not e!ine as optional, one "%st pass a

    corresponing act%al para"eter 7f i 1in the (F'#;

  • 7/18/2019 Oops Abap Ibm

    92/123

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    93/123

    Copyright IBM Corporation 2003

    2vents B !egistering

    START&OF&SELECTION.

    8 c1 7ec!"re# "47 r"/#e# e)e4t e1

    8 c "47!e# e)e4t e1

    CREATE O-ECT ref_to_c1,ref_to_c.

    SET HANDLER ref_to_c&3e)e4t_"47!er

    FOR ref_to_c1.

    CALL METHOD:

    ref_to_c1&3tr/99er_e)e4t+

    So !ar e have statically eclare an event an

    i"ple"ente a trigger an a corresponing

    hanler

  • 7/18/2019 Oops Abap Ibm

    94/123

    Copyright IBM Corporation 2003

    e7 hanlerHe7

    e7 hanlerHe7

    2vents B !untime 2nvironment

    C7

    '%blic, 'rotecte,'rivate

    Methos/ triggerHe7

    (vents/ e7

    raises event e7

    C4

    '%blic, 'rotecte,'rivate

    Methos/ hanlerHe7

    hanlerHe2

    C3'%blic, 'rotecte,

    'rivate

    Methos/ hanlerHe7register !or e7

    CREATE O-ECT oref1

    CREATE O-ECT oref+

    CREATE O-ECT oref*

    ore!7triggerHe7register !or e7

    SET HANDLER oref+&

    3"47!er_e1 FOR oref1

    SET HANDLER oref*&

    3"47!er_e1 FOR oref1

    (ach ob$ect that can trigger events has an invisible hanler table, here the entries occ%r as a res%lt

    o! S(< EAD1(; state"ents

  • 7/18/2019 Oops Abap Ibm

    95/123

    Copyright IBM Corporation 2003

    2vents with Parameters

    (vents can have e*port para"eters, hich it passes to its event hanler

    "etho+

  • 7/18/2019 Oops Abap Ibm

    96/123

    Copyright IBM Corporation 2003

    Topics to cover

    Different approaches to Programming

    Class and objects

    Methods

    ConstructorInheritance

    Interface

    Friendship between Classes

    Events

    Class-Based Eceptions

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    97/123

    Copyright IBM Corporation 2003

    )hat is an 23ception*

    )n eception is a situation that occurs during the eecution of an )B)Pprogram( which renders a normal program continuation pointless"

    (*ceptions can be etecte at the ti"e o! progra" co"pilation or at

    r%nti"e+I! the e*ception etecte at r%nti"e is not hanle properly by the

    progra" itsel!, e get a short %"p an the e*ec%tion ter"inates+

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    98/123

    Copyright IBM Corporation 2003

    Classification of 23ceptions

    (*ceptions o! vario%s ins can be broaly classi!ie as /

    (*ceptions that can be hanle+

    (*ceptions that cannot be hanle+

    Eceptions that can be handledinicate error sit%ations in the r%nti"e

    environ"ent or in the ABA' progra", in the case o! hich the progra" e*ec%tioncan be contin%e by hanling the e*ception in the ABA' progra" itho%t the

    syste" reaching a critical conition+ (f such a situation is not handled a runtime

    error will occur.

    Eceptions that cannot be handledinicate critical error sit%ations in ther%nti"e environ"ent, hich cannot be hanle ith8by ABA' "eans an alays

    ca%se a r%nti"e error+ Database space proble" can be an e*a"ple o! s%chcategory+

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    99/123

    Copyright IBM Corporation 2003

    Traditional )as of Catching !untime 23ceptions

    Areas $rief Overview

    In )B)P catch system-exceptions = . . . . . . .

    Endcatch.

    If sy-subrc= .

    < exception handling statements>Endif.

    In function module Creating exceptions for function module, raising them at appropriatepoints in the FM , assigning different sy-subrc values for each

    exceptions at the time of the FM call and later dealing with them.

    In Methods Creating different exceptions at the time of declaring methods,raising those exceptions within the method, assigning different sy-

    subrc values at the time of method call and later dealing with those

    values.

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    100/123

    Copyright IBM Corporation 2003

    )hat is Class-based e3ception handling*

    In Classbase e*ceptions hanling approach, e*ceptions are generally

    represente by ob$ects o! e*ception classes+ sers can also e!ine on e*ception classes globally8locally, i! re6%ire an can

    raise the" %sing !A(#2 2

  • 7/18/2019 Oops Abap Ibm

    101/123

    Copyright IBM Corporation 2003

    T!I8CATC=82'DT!I

    Classbase e*ceptions are hanle %sing

  • 7/18/2019 Oops Abap Ibm

    102/123

    Copyright IBM Corporation 2003

    Class-$ased 23ceptions B #AP 23ception Classes E

    C

  • 7/18/2019 Oops Abap Ibm

    103/123

    Copyright IBM Corporation 2003

    #AP 23ception Classes

    SA' provie e*ceptionclasses are erive !ro" the speci!ic class CFH;##m.;

  • 7/18/2019 Oops Abap Ibm

    111/123

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    112/123

    Copyright IBM Corporation 2003

    Class-$ased 23ceptions B Debug ;ode

  • 7/18/2019 Oops Abap Ibm

    113/123

    Copyright IBM Corporation 2003

    Class-$ased 23ceptions B Debug ;ode

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    114/123

    Copyright IBM Corporation 2003

    Class-$ased 23ceptions B Creating a &lobal 23ception Class 0E

    (nter class na"e Clic Create

    ote S%perclass

    an class type

    S(24

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    115/123

    Copyright IBM Corporation 2003

    Class-$ased 23ceptions B Creating a &lobal 23ception Class E

    ote the 2 attrib%tes inherite !ro" c*Hroot s%perclass

    te3tid >se to e!ine i!!erent te*ts !or e*ceptions o! a partic%lar class+

    A!!ects the res%lt o! "etho getHte*t

    previous I! one e*ception is "appe to another, this attrib%te can store the

    original e*ception+ I! a r%nti"e error occ%rs, the short %"p contains the te*ts

    belonging to all the e*ceptions in the chain

    Go to

    Methos

  • 7/18/2019 Oops Abap Ibm

    116/123

    Copyright IBM Corporation 2003

    Class-$ased 23ceptions B Creating a &lobal 23ception Class E

  • 7/18/2019 Oops Abap Ibm

    117/123

    Copyright IBM Corporation 2003

    Class-$ased 23ceptions B Creating a &lobal 23ception Class KE

    Call to t&e const'(cto' of s(pe'classes is a(to)aticall* +ene'ated

    Clic on

    previo%s

    ob$ect b%tton

    to ret%rn to"ethos tab

  • 7/18/2019 Oops Abap Ibm

    118/123

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    119/123

    Copyright IBM Corporation 2003

    Class-$ased 23ceptions B Creating a &lobal 23ception Class LE

    A line has been ae to the constr%ctor to initiali)e the ne attrib%te+

  • 7/18/2019 Oops Abap Ibm

    120/123

    Copyright IBM Corporation 2003

    Class-$ased 23ceptions B Creating a &lobal 23ception Class ME

    ,o to t&e ets tab and add a tet fo' t&eeception .

    IBM Global Services

    Class-$ased 23ceptions B Creating a &lobal 23ception Class

  • 7/18/2019 Oops Abap Ibm

    121/123

    Copyright IBM Corporation 2003

    p g p

    NE

  • 7/18/2019 Oops Abap Ibm

    122/123

    Copyright IBM Corporation 2003

    Class-$ased 23ceptions B Creating a &lobal 23ception Class E

    Afte' pe'fo')in+ a s*nta c&ec and

    addin+ t&e tets to t&e O23 'et('n to t&e

    Att'ib(tes tab

    IBM Global Services

  • 7/18/2019 Oops Abap Ibm

    123/123

    Class-$ased 23ceptions B Creating a &lobal 23ception Class 0E

    on4t fo'+et to activate t&e object

    ote t&at t&e tet 4s &ave been added to t&e att'ib(tes pa+e as