Skip to Content
author's profile photo Former Member
Former Member

Regarding Interface in objectoriented abap.

Hi! to every body,

i want to know about the interface definition,source codes,And why we need to use this interface in ooabap?

i need clear cut view in this topic.

Can u help in this topic plz. i am very thank full to u if u replied has i need.

regards,

M.Swapna.

swapnam@mouritech.com

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 01, 2006 at 02:38 PM

    Hi,

    <b>Interface</b> Can be declared globally or locally within a program.

    Locally declared in the global portion of a program using:-

    INTERFACE <intf>.

    ...

    ENDINTERFACE.

    The definition contains the declaration for all components (attributes, methods, events) of the interface.

    Interfaces are included in the public section of a class.

    Interfaces do not have an implementation part, since their methods are implemented in the class that implements the interface.

    Interfaces do not have instances.

    A component <icomp> of an interface <intf> can be addressed as though it were a member of the class under the name <intf~icomp>.

    <b>Addressing Objects Using the class reference variable <cref>:</b>

    To access an attribute <attr>: <cref>-><intf~attr>

    To call a method <meth>:

    CALL METHOD <cref>-><intf~meth>

    <b>Using the interface reference variable <iref>:</b>

    To access an attribute <attr>: < iref>-><attr>

    To call a method <meth>:

    CALL METHOD <iref>-><meth>

    Addressing a constant <const>:

    <intf>=><const> (Cannot use class name).

    Addressing a static attribute <attr>:

    < class>=><intf~attr>

    Calling a static method <meth>:

    CALL METHOD <class>=><intf~meth>

    (Cannot use Interface method ).

    casting operator (?= )

    <cref> ?= <iref>

    For the casting to be successful, the object to which <iref> points must be an object of the same class as the type of the class variable <cref>.

    <b>sample program</b>

    report ysubdel .

    interface i1.

    data : num type i .

    methods : meth1.

    endinterface.

    class c1 definition.

    public section.

    methods : meth1.

    interfaces : i1.

    endclass.

    class c1 implementation.

    method : meth1.

    write:/5 'I am meth1 in c1'.

    endmethod.

    method i1~meth1.

    write:/5 'I am meth1 from i1'.

    endmethod.

    endclass.

    start-of-selection.

    data : oref type ref to c1. create object oref.

    write:/5 oref->i1~num.

    call method oref->meth1.

    call method oref->i1~meth1.

    Regards,

    Sowjanya.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 01, 2006 at 02:59 PM

    Hi Swapna,

    One parent class can have multiple subclasses, but one subclass can have only one parent class.Hence, multiple inheritance is not allowed in ABAP.

    Subclasses have full access to all the public and protected components of parent class. They can modify to re-implement those components of their own.Also, subclasses can create new components in them.

    A single class can give birth to its subclasses by inheritance.

    Private components of parent classes are not known to subclasses. There can be components with same name in private section in both the parent and subclasses , each one working and being identified separately in their respective classes.

    -Anu.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 01, 2006 at 05:28 PM

    Hi Swapna,

    I suppose you have some idea about OO ABAP.

    Interfaces are the collection of public components of any class.Components can be methods, attributes (but usually attributes are made private) etc.

    Regarding methods, only their definition can be made in the interfaces and their implementations are done in the Class containing the interface.

    Correlating to real-world scenario, interfaces can be compared to various parts of a car like Steering, clutch, brake etc. The user has only these parts available to control the car and they don't know how internally the working happens in a car. You can access these components to handle the car.

    Similarly, various components (ie public components ) of the interfaces can be used to work with classes.The data you would be giving to the interface components like methods will be used to communicate with the class , in which the actual implementation is done.

    You can refer these documents that I have uploaded for reference.

    http://esnips.com/doc/448e8302-68b1-4046-9fef-8fa8808caee0/abap-objects-by-helen.pdf

    http://esnips.com/doc/39fdc647-1aed-4b40-a476-4d3042b6ec28/class_builder.ppt

    http://esnips.com/doc/92be4457-1b6e-4061-92e5-8e4b3a6e3239/Object-Oriented-ABAP.ppt

    http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt

    http://esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf

    <b>Award points if found useful.</b>

    Regards,

    SP.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.