Application Development 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: 

ABSTRACT class and method

Former Member
0 Kudos
3,717

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
646

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

4 REPLIES 4

Former Member
0 Kudos
647

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

0 Kudos
646

Hi Bhanu P.,

Really appreciate your valuable answers.

It works!

Shivani11
Explorer
646

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.

0 Kudos
646

It's what the accepted answer already says. Any reason to post again the same answer, 15 years later?