Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ABSTRACT class and method

Former Member
0 Likes
1,038

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". What does it mean?


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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
955

Hi,

Abstract class -> it is not must to override all methods in abstract class. Abstract class may contain abstract methods and non abstract methods.. in this case abstract methods should be overriden and non abstract methods are need not to be overriden.

so in your case the problem is because you haven't Implemented the WRITE_STATUS method in the Subclass i.e. CLASS PLANE. or not Redefined in the Subclass.

Best Regards,

Sunil

6 REPLIES 6
Read only

Former Member
0 Likes
956

Hi,

Abstract class -> it is not must to override all methods in abstract class. Abstract class may contain abstract methods and non abstract methods.. in this case abstract methods should be overriden and non abstract methods are need not to be overriden.

so in your case the problem is because you haven't Implemented the WRITE_STATUS method in the Subclass i.e. CLASS PLANE. or not Redefined in the Subclass.

Best Regards,

Sunil

Read only

0 Likes
955

Hi Sunil,

Really appreciate for your prompt reply.

I am a Abap newbie. I may not fully understand what you trying to explain. If you could provide or amend my code in order to make it error free would be highly appreciated.

Read only

0 Likes
955

Hi Sunil,

If not mistaken, I think I have implemented the write_status in the subclass Plane.


CLASS plane IMPLEMENTATION.
  METHOD rise.
    altitude = altitude + 1.
  ENDMETHOD.
  METHOD write_status.
    WRITE: / 'Plane speed:', speed.
    WRITE: / 'Altitude:', altitude.
  ENDMETHOD.
ENDCLASS.

Read only

0 Likes
955

Hi,

try this code I've rearranged your Class Implementation and just added the foll code;

write_status REDEFINITION in the Definition part of the Subclass.

* Class Declaration
 
CLASS vehicle DEFINITION ABSTRACT.
  PUBLIC SECTION.
    METHODS: accelerate,
             write_status ABSTRACT.
  PROTECTED SECTION.
    DATA speed TYPE i.
ENDCLASS.
 
* Class Implementation
 
CLASS vehicle IMPLEMENTATION.
  METHOD accelerate.
    speed = speed + 1.
  ENDMETHOD.
ENDCLASS.
 







CLASS plane DEFINITION INHERITING FROM vehicle.
  PUBLIC SECTION.
    METHODS: rise,
             write_status redefinition.    
  PROTECTED SECTION.
    DATA altitude TYPE i.
ENDCLASS.


CLASS plane IMPLEMENTATION.
  METHOD rise.
    altitude = altitude + 1.
  ENDMETHOD.
  METHOD write_status.
    WRITE: / 'Plane speed:', speed.
    WRITE: / 'Altitude:', altitude.
  ENDMETHOD.
ENDCLASS.









CLASS ship DEFINITION INHERITING FROM vehicle.
  PUBLIC SECTION.
    METHODS: write_status redefinition.  
ENDCLASS.
 
 
CLASS ship IMPLEMENTATION.
  METHOD write_status.
    WRITE: / 'In Ship Class.'.
  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,
               ship_ref->write_status.

Best Regards,

Sunil.

Read only

0 Likes
955

Hi,


CLASS plane DEFINITION INHERITING FROM vehicle.
  PUBLIC SECTION.
    METHODS: rise,
             write_status redefinition.    
  PROTECTED SECTION.
    DATA altitude TYPE i.
ENDCLASS.



CLASS ship DEFINITION INHERITING FROM vehicle.
  PUBLIC SECTION.
    METHODS: write_status redefinition.  
ENDCLASS.

Regards,

Sandeep Patel.

Read only

0 Likes
955

Hi all,

Thanks for your valueable answers.