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: 

build class taht inhertance from class

Former Member
0 Kudos

Hi,

i build Z Class in se24 and i wont to build other Class that inheritance from it ,

how can i do that (i think i have to use superclass in properties but i need all the step from begining ?

Regards

1 ACCEPTED SOLUTION

former_member188685
Active Contributor
0 Kudos

> i build Z Class in se24 and i wont to build other Class that inheritance from it ,

> (i think i have to use superclass in properties but i need all the step from begining

include the first class in second class as Super class in the Attributes section. that you already know...

Now go to methods and what ever method you want to redefine, just select and click on Redefine button and redefine. and if you want to include any attributes you can include the new attributes.

activate finally.

But i dont know what steps you are looking for, the main step is including the superclass. that you already know.

8 REPLIES 8

former_member188685
Active Contributor
0 Kudos

> i build Z Class in se24 and i wont to build other Class that inheritance from it ,

> (i think i have to use superclass in properties but i need all the step from begining

include the first class in second class as Super class in the Attributes section. that you already know...

Now go to methods and what ever method you want to redefine, just select and click on Redefine button and redefine. and if you want to include any attributes you can include the new attributes.

activate finally.

But i dont know what steps you are looking for, the main step is including the superclass. that you already know.

0 Kudos

Hi Vijay ,

i build subclass and i go to super class and i wont to add the class that i wont to inheratee from it,

and i get massage :

Class Z_GET_L_UNDER is final - it cannot have subclasses.

how i can change it?

Regards

0 Kudos

Hi Ricardo,

You cannot Inherit a class declared as FINAL.

Please check this Thread :

[;

Regards

Hemant Khemani

0 Kudos

It is not possible yo Inherit the final class. so if you want to inherit the classs you go class Z_GET_L_UNDER and change the peroperty. Otherwise it is not possible to inherit..

0 Kudos

Hi,

Thanks but how i Change it?

Regards

0 Kudos

Go to the Zclass in change mode.

in the Properties Tab, you can see that Final with Checked, you uncheck it. and activate the class.

former_member598013
Active Contributor
0 Kudos

Hi Ricardo,

Below code might help you to solve the problem.


*&---------------------------------------------------------------------*
*& Report  Z7CC_OBJECT1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  Z7CC_OBJECT1.

*---------------------------------------------------------------------*
*       Global Selection Screen
*---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF SCREEN 100 AS WINDOW  TITLE text-100.
PARAMETERS: button1 RADIOBUTTON GROUP grp,
            button2 RADIOBUTTON GROUP grp,
            button3 RADIOBUTTON GROUP grp,
            button4 RADIOBUTTON GROUP grp.
SELECTION-SCREEN END OF SCREEN 100.

*---------------------------------------------------------------------*
*       INTERFACE status
*---------------------------------------------------------------------*
*       Interface definition                                          *
*---------------------------------------------------------------------*
INTERFACE status.
  METHODS write.
ENDINTERFACE.

*---------------------------------------------------------------------*
*       CLASS vessel DEFINITION
*---------------------------------------------------------------------*
*       Superclass definition                                         *
*---------------------------------------------------------------------*
CLASS vessel DEFINITION.
  PUBLIC SECTION.
    METHODS: constructor,
             drive IMPORTING speed_up TYPE i,
             get_id RETURNING value(id) TYPE i.
  PROTECTED SECTION.
    DATA: speed TYPE i,
          max_speed TYPE i VALUE 100.
  PRIVATE SECTION.
    CLASS-DATA object_count TYPE i.
    DATA id TYPE i.
ENDCLASS.

*---------------------------------------------------------------------*
*       CLASS vessel IMPLEMENTATION
*---------------------------------------------------------------------*
*       Superclass implementation                                     *
*---------------------------------------------------------------------*
CLASS vessel IMPLEMENTATION.
  METHOD constructor.
    object_count = object_count + 1.
    id = object_count.
  ENDMETHOD.
  METHOD drive.
    speed = speed + speed_up.
    IF speed > max_speed.
      speed = max_speed.
    ENDIF.
  ENDMETHOD.
  METHOD get_id.
    id = me->id.
  ENDMETHOD.
ENDCLASS.

*---------------------------------------------------------------------*
*       CLASS ship DEFINITION
*---------------------------------------------------------------------*
*       Subclass definition                                           *
*---------------------------------------------------------------------*
CLASS ship DEFINITION INHERITING FROM vessel.
  PUBLIC SECTION.
    INTERFACES status.
    DATA name TYPE string READ-ONLY.
    METHODS: constructor IMPORTING name TYPE string,
             drive REDEFINITION.
    EVENTS emergency_call.
ENDCLASS.

*---------------------------------------------------------------------*
*       CLASS ship IMPLEMENTATION
*---------------------------------------------------------------------*
*       Subclass implementation                                       *
*---------------------------------------------------------------------*
CLASS ship IMPLEMENTATION.
  METHOD constructor.
    CALL METHOD super->constructor.
    max_speed = 30.
    me->name = name.
  ENDMETHOD.
  METHOD status~write.
    DATA id.
    id = me->get_id( ).
    WRITE: / name, 'is vessel', id,
                        'and has speed', speed.
  ENDMETHOD.
  METHOD drive.
    speed = speed + speed_up.
    IF speed > max_speed.
      max_speed = 0.
      speed = 0.
      RAISE EVENT emergency_call.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

*---------------------------------------------------------------------*
*       CLASS coast_guard DEFINITION
*---------------------------------------------------------------------*
*       Event handler definition                                      *
*---------------------------------------------------------------------*
CLASS coast_guard DEFINITION.
  PUBLIC SECTION.
    INTERFACES status.
    METHODS receive FOR EVENT emergency_call OF ship IMPORTING sender.
    ALIASES write FOR status~write.
  PRIVATE SECTION.
    DATA caller TYPE string.
ENDCLASS.

*---------------------------------------------------------------------*
*       CLASS coast_guard IMPLEMENTATION
*---------------------------------------------------------------------*
*       Event handler implementation                                  *
*---------------------------------------------------------------------*
CLASS coast_guard IMPLEMENTATION.
  METHOD status~write.
    IF caller IS INITIAL.
      WRITE: / 'Coast guard received no call'.
    ELSE.
      WRITE: / 'Coast guard received a call from', caller.
    ENDIF.
  ENDMETHOD.
  METHOD receive.
    caller = sender->name.
    CALL METHOD write.
  ENDMETHOD.
ENDCLASS.

*---------------------------------------------------------------------*
*       CLASS main DEFINITION
*---------------------------------------------------------------------*
*       Main class definition                                         *
*---------------------------------------------------------------------*
CLASS main DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS: start,
                   objects,
                   inheritance,
                   interfaces,
                   events.
ENDCLASS.

*---------------------------------------------------------------------*
*      CLASS main IMPLEMENTATION
*---------------------------------------------------------------------*
*      Main class implementation                                      *
*---------------------------------------------------------------------*
CLASS main IMPLEMENTATION.

  METHOD start.
    CALL SELECTION-SCREEN 100 STARTING AT 10 3
                                ENDING AT 42 7.
    IF sy-subrc NE 0.
      EXIT.
    ELSEIF button1 = 'X'.
      CALL METHOD objects.
    ELSEIF button2 = 'X'.
      CALL METHOD inheritance.
    ELSEIF button3 = 'X'.
      CALL METHOD interfaces.
    ELSEIF button4 = 'X'.
      CALL METHOD events.
    ENDIF.
  ENDMETHOD.

  METHOD objects.
    DATA: vessel1 TYPE REF TO vessel,
          vessel2 TYPE REF TO vessel.
    DATA: vessel_id  TYPE i.
    CREATE OBJECT: vessel1 TYPE vessel,
                   vessel2 TYPE vessel.
    CALL METHOD: vessel1->drive( 50 ),
                 vessel2->drive( 80 ).
    vessel_id = vessel1->get_id( ).
    WRITE: / 'Vessel ID is', vessel_id.
    vessel_id = vessel2->get_id( ).
    WRITE: / 'Vessel ID is', vessel_id.
  ENDMETHOD.

  METHOD inheritance.
    DATA: vessel TYPE REF TO vessel,
            ship TYPE REF TO ship.
    CREATE OBJECT ship TYPE ship EXPORTING name = 'Titanic'.
    CALL METHOD ship->drive( 20 ).
    MOVE ship TO vessel.
    CALL METHOD vessel->drive( 10 ).
    CALL METHOD ship->status~write.
  ENDMETHOD.

  METHOD interfaces.
    DATA: status_tab TYPE TABLE OF REF TO status,
          status TYPE REF TO status.
    DATA: ship TYPE REF TO ship,
          station TYPE REF TO coast_guard.
    CREATE OBJECT: ship EXPORTING name = 'Titanic'.
    APPEND ship TO status_tab.
    CREATE OBJECT station.
    APPEND station TO status_tab.
    LOOP AT status_tab INTO status.
      CALL METHOD status->write.
    ENDLOOP.
  ENDMETHOD.

  METHOD events.
    DATA: ship TYPE REF TO ship,
          station TYPE REF TO coast_guard.
    CREATE OBJECT: ship EXPORTING name = 'Titanic',
                   station.
    SET HANDLER station->receive FOR ship.
    DO 5 TIMES.
      CALL METHOD ship->drive( 10 ).
    ENDDO.
  ENDMETHOD.

ENDCLASS.

*---------------------------------------------------------------------*
*      System event START-OF-SELECTION
*---------------------------------------------------------------------*
*      Triggered by the ABAP runtime environment automatically        *
*---------------------------------------------------------------------*

START-OF-SELECTION.
  CALL METHOD main=>start.

0 Kudos

Chidanand,

Your code is copy&pasted from here: http://www.sap-press.de/katalog/buecher/htmlleseproben/gp/htmlprobID-28

... without crediting the source... that makes it look like your code; which it is not!

I have removed your points and will be investigating your other posts...

Cheers,

Julius