2007 Dec 29 12:06 PM
2007 Dec 29 12:10 PM
In ABAP interfaces are implemented in addition to, and independently of classes. An interface only has a declaration part, and do not have visibility sections. Components (Attributes, methods, constants, types) can be defined the same way as in classes.
Interfaces are listed in the definition part of the class, and must always be in the PUBLIC SECTION.
Operations defined in the interface are implemented as methods of the class. All methods of the interface must be present in the implementation part of the class.
Attributes, events, constants and types defined in the interface are automatically available to the class carrying out the implementation.
Interface components are addressed in the class by <interface name>~<component name>
[Interface Program|http://saptechnical.com/Tutorials/OOPS/Interfaces/page1.htm]
Thank you,
In ABAP interfaces are implemented in addition to, and independently of classes. An interface only has a declaration part, and do not have visibility sections. Components (Attributes, methods, constants, types) can be defined the same way as in classes.
Interfaces are listed in the definition part of the class, and must always be in the PUBLIC SECTION.
Operations defined in the interface are implemented as methods of the class. All methods of the interface must be present in the implementation part of the class.
Attributes, events, constants and types defined in the interface are automatically available to the class carrying out the implementation.
Interface components are addressed in the class by <interface name>~<component name>
[Interface Program|http://saptechnical.com/Tutorials/OOPS/Interfaces/page1.htm]
Thank you,
2007 Dec 29 12:10 PM
In ABAP interfaces are implemented in addition to, and independently of classes. An interface only has a declaration part, and do not have visibility sections. Components (Attributes, methods, constants, types) can be defined the same way as in classes.
Interfaces are listed in the definition part of the class, and must always be in the PUBLIC SECTION.
Operations defined in the interface are implemented as methods of the class. All methods of the interface must be present in the implementation part of the class.
Attributes, events, constants and types defined in the interface are automatically available to the class carrying out the implementation.
Interface components are addressed in the class by <interface name>~<component name>
[Interface Program|http://saptechnical.com/Tutorials/OOPS/Interfaces/page1.htm]
Thank you,
2007 Dec 30 6:43 AM
Hi,
interfaces contains methods, for that methods we can write the implemnetation of the method.
interface should be public.
we can access any where in the program.
i am giving program please see it.
&----
*& Report ZLCL_IF_ONE *
*& *
&----
*& *
*& *
&----
REPORT ZLCL_IF_ONE .
DATA: P3 TYPE I.
----
INTERFACE INTF1
----
*
----
INTERFACE INTF1.
METHODS: M1,
CALC IMPORTING P1 TYPE I
P2 TYPE I
EXPORTING P3 TYPE I.
ENDINTERFACE. "INTF1
----
CLASS CL_ABS DEFINITION
----
*
----
CLASS CL_ABS DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS: M2 ABSTRACT.
ENDCLASS. "CL_ABS DEFINITION
----
CLASS CL_INTF1 DEFINITION
----
*
----
CLASS CL_INTF1 DEFINITION INHERITING FROM CL_ABS.
PUBLIC SECTION.
INTERFACES INTF1.
METHODS: M1,
M2 REDEFINITION.
ALIASES: AL1 FOR INTF1~M1,
AL2 FOR INTF1~CALC.
ENDCLASS. "CL_INTF1 DEFINITION
----
CLASS CL_INTF1 IMPLEMENTATION
----
*
----
CLASS CL_INTF1 IMPLEMENTATION.
METHOD M1.
WRITE:/ 'M1 CLASS METHOD'.
ENDMETHOD. "M1
METHOD INTF1~M1.
WRITE:/ 'INTERFACE METHOD M1 IMPLEMENTED IN CLASS'.
ENDMETHOD. "INTF1~M1
METHOD INTF1~CALC.
P3 = P1 + P2.
ENDMETHOD. "INTF1~CALC
METHOD M2.
WRITE:/ 'ABSTRACT CLASS METHOD REDEFINED IN CLASS'.
ENDMETHOD. "M2
ENDCLASS. "CL_INTF1 IMPLEMENTATION
DATA: OBJ TYPE REF TO CL_INTF1.
START-OF-SELECTION.
CREATE OBJECT OBJ.
CALL METHOD: OBJ->M1.
*--CALLING ABSTRACT CLASS METHOD
CALL METHOD: OBJ->M2.
*--CALLING ABSTRACT CLASS METHOD
CALL METHOD: OBJ->INTF1~M1.
*--CALLING ABSTRACT CLASS METHOD VIA ALIAS
CALL METHOD: OBJ->AL1.
*--CALLING ABSTRACT CLASS METHOD VIA ALIAS
CALL METHOD: OBJ->INTF1~CALC
EXPORTING
P1 = 10
P2 = 20
IMPORTING
P3 = P3.
WRITE:/ P3.
*--CALLING ABSTRACT CLASS METHOD VIA ALIAS
CALL METHOD: OBJ->AL2
EXPORTING
P1 = 10
P2 = 20
IMPORTING
P3 = P3.
WRITE:/ P3.
please reward points, if is useful
regards,
satish.
2007 Dec 31 11:39 AM
Hi this sample will help u.
TABLES ZVIJIRANK.
DATA IT LIKE TABLE OF ZVIJIRANK WITH HEADER LINE.
INTERFACE I1.
METHODS : GETDATA.
ENDINTERFACE.
CLASS CL1 DEFINITION.
PUBLIC SECTION.
INTERFACES I1.
ENDCLASS.
CLASS CL2 DEFINITION.
PUBLIC SECTION.
INTERFACES I1.
ENDCLASS.
CLASS CL1 IMPLEMENTATION.
METHOD I1~GETDATA.
SELECT * FROM ZVIJIRANK INTO TABLE IT.
ENDMETHOD.
ENDCLASS.
CLASS CL2 IMPLEMENTATION.
METHOD I1~GETDATA.
SELECT * FROM ZVIJIRANK INTO TABLE IT WHERE REG_NO = '101'.
ENDMETHOD.
ENDCLASS.
DATA: OBJ1 TYPE REF TO CL1,
OBJ2 TYPE REF TO CL2.
START-OF-SELECTION.
CREATE OBJECT: OBJ1 , OBJ2.
CALL METHOD OBJ1->I1~GETDATA.
LOOP AT IT.
WRITE : / IT-REG_NO , IT-NAME , IT-BRANCH.
ENDLOOP.
CALL METHOD OBJ2->I1~GETDATA.
LOOP AT IT.
WRITE : / IT-REG_NO , IT-NAME , IT-BRANCH.
ENDLOOP.
If you have doubt means go through the following links.
http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
with regards,
Hema Sundara.
reward if u find it helpful.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |