2008 Jul 09 6:48 AM
Dear all Abaper experts,
I am doubt on a abap object program shown as below. It is a ABSTRACT class and method. However, during compiling, an error message is displayed "The abstract method 'WRITE_STATUS' may not be implemented". Anyone knows what does it mean? And how to resolve this error?
REPORT ZOOP_ABSTRACT.
* Class Declaration
CLASS vehicle DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS: accelerate,
write_status ABSTRACT.
PROTECTED SECTION.
DATA speed TYPE i.
ENDCLASS.
CLASS plane DEFINITION INHERITING FROM vehicle.
PUBLIC SECTION.
METHODS: rise.
PROTECTED SECTION.
DATA altitude TYPE i.
ENDCLASS.
CLASS ship DEFINITION INHERITING FROM vehicle.
ENDCLASS.
* Class Implementation
CLASS vehicle IMPLEMENTATION.
METHOD accelerate.
speed = speed + 1.
ENDMETHOD.
ENDCLASS.
CLASS plane IMPLEMENTATION.
METHOD rise.
altitude = altitude + 1.
ENDMETHOD.
METHOD write_status.
WRITE: / 'Plane speed:', speed.
WRITE: / 'Altitude:', altitude.
ENDMETHOD.
ENDCLASS.
CLASS ship IMPLEMENTATION.
ENDCLASS.
* Global Data
DATA: plane_ref TYPE REF TO plane,
ship_ref TYPE REF TO ship.
* Classical Processing Blocks
START-OF-SELECTION.
CREATE OBJECT: plane_ref,
ship_ref.
CALL METHOD: plane_ref->accelerate,
plane_ref->rise,
plane_ref->write_status,
plane_ref->accelerate,
plane_ref->write_status.
All answers are welcome and appreciate for the help.
2008 Jul 09 7:49 AM
Hi,
If you define a class from an abstract class you must redefine the abstract methods also.
Here vehicle is an abstract class.
you inherited plane and ship from that abstract class.
so you must redefine the write_status method here also and it must be implemented.
Check this code now,
****************
REPORT ZOOP_ABSTRACT.
Class Declaration
CLASS vehicle DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS: accelerate,
write_status ABSTRACT.
PROTECTED SECTION.
DATA speed TYPE i.
ENDCLASS.
CLASS plane DEFINITION INHERITING FROM vehicle.
PUBLIC SECTION.
METHODS: rise.
METHODS: write_status REDEFINITION.
PROTECTED SECTION.
DATA altitude TYPE i.
ENDCLASS.
CLASS ship DEFINITION INHERITING FROM vehicle.
PUBLIC SECTION.
METHODS: write_status REDEFINITION.
ENDCLASS.
Class Implementation
CLASS vehicle IMPLEMENTATION.
METHOD accelerate.
speed = speed + 1.
ENDMETHOD.
ENDCLASS.
CLASS plane IMPLEMENTATION.
METHOD rise.
altitude = altitude + 1.
ENDMETHOD.
METHOD write_status.
WRITE: / 'Plane speed:', speed.
WRITE: / 'Altitude:', altitude.
ENDMETHOD.
ENDCLASS.
CLASS ship IMPLEMENTATION.
METHOD write_status.
WRITE: / 'Plane speed:', speed.
ENDMETHOD.
ENDCLASS.
Global Data
DATA: plane_ref TYPE REF TO plane,
ship_ref TYPE REF TO ship.
Classical Processing Blocks
START-OF-SELECTION.
CREATE OBJECT: plane_ref,
ship_ref.
CALL METHOD: plane_ref->accelerate,
plane_ref->rise,
plane_ref->write_status,
plane_ref->accelerate,
plane_ref->write_status.
****************************
Regards,
Bhanu
2008 Jul 09 7:49 AM
Hi,
If you define a class from an abstract class you must redefine the abstract methods also.
Here vehicle is an abstract class.
you inherited plane and ship from that abstract class.
so you must redefine the write_status method here also and it must be implemented.
Check this code now,
****************
REPORT ZOOP_ABSTRACT.
Class Declaration
CLASS vehicle DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS: accelerate,
write_status ABSTRACT.
PROTECTED SECTION.
DATA speed TYPE i.
ENDCLASS.
CLASS plane DEFINITION INHERITING FROM vehicle.
PUBLIC SECTION.
METHODS: rise.
METHODS: write_status REDEFINITION.
PROTECTED SECTION.
DATA altitude TYPE i.
ENDCLASS.
CLASS ship DEFINITION INHERITING FROM vehicle.
PUBLIC SECTION.
METHODS: write_status REDEFINITION.
ENDCLASS.
Class Implementation
CLASS vehicle IMPLEMENTATION.
METHOD accelerate.
speed = speed + 1.
ENDMETHOD.
ENDCLASS.
CLASS plane IMPLEMENTATION.
METHOD rise.
altitude = altitude + 1.
ENDMETHOD.
METHOD write_status.
WRITE: / 'Plane speed:', speed.
WRITE: / 'Altitude:', altitude.
ENDMETHOD.
ENDCLASS.
CLASS ship IMPLEMENTATION.
METHOD write_status.
WRITE: / 'Plane speed:', speed.
ENDMETHOD.
ENDCLASS.
Global Data
DATA: plane_ref TYPE REF TO plane,
ship_ref TYPE REF TO ship.
Classical Processing Blocks
START-OF-SELECTION.
CREATE OBJECT: plane_ref,
ship_ref.
CALL METHOD: plane_ref->accelerate,
plane_ref->rise,
plane_ref->write_status,
plane_ref->accelerate,
plane_ref->write_status.
****************************
Regards,
Bhanu
2008 Jul 09 8:17 AM
Hi Bhanu P.,
Really appreciate your valuable answers.
It works!
2023 Jun 12 12:36 PM
Hi,
Each and every method which is defined in definition section, that needs to be implemented in implementation section.
For abstract method, we need to redefine it.
2023 Jun 12 12:55 PM
It's what the accepted answer already says. Any reason to post again the same answer, 15 years later?