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

Error while calling a super class public method in the subclass constructor

Former Member
0 Likes
2,052

Hi ,

I have code like this:

CLASS gacl_applog DEFINITION ABSTRACT.

PUBLIC SECTION.

METHODS:

create_new_a

IMPORTING pf_obj TYPE balobj_d

pf_subobj TYPE balsubobj

pf_extnumber TYPE string

EXPORTING pfx_log_hndl TYPE balloghndl

EXCEPTIONS error

ENDCLASS.

CLASS gacl_applog IMPLEMENTATION.

METHOD create_new_a.

DATA: ls_log TYPE bal_s_log.

  • Header aufsetzen

MOVE pf_extnumber TO ls_log-extnumber.

ls_log-object = pf_obj.

ls_log-subobject = pf_subobj.

ls_log-aluser = sy-uname.

ls_log-alprog = sy-repid.

ls_log-aldate = sy-datum.

ls_log-altime = sy-uzeit.

ls_log-aldate_del = ls_log-aldate + 1.

CALL FUNCTION 'BAL_LOG_CREATE'

EXPORTING

i_s_log = ls_log

IMPORTING

e_log_handle = pfx_log_hndl

EXCEPTIONS

OTHERS = 1.

IF ( sy-subrc NE 0 ).

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4

RAISING error.

ENDIF.

ENDMETHOD.

CLASS gcl_applog_temp DEFINITION INHERITING FROM gacl_applog.

PUBLIC SECTION.

DATA: log_hndl TYPE balloghndl READ-ONLY

, t_log_hndl TYPE bal_t_logh READ-ONLY

.

METHODS: constructor

IMPORTING pf_obj TYPE balobj_d

pf_subobj TYPE balsubobj

pf_extnumber TYPE string

EXCEPTIONS error

, msg_add REDEFINITION

, display REDEFINITION

.

ENDCLASS.

CLASS gcl_applog_temp IMPLEMENTATION.

METHOD constructor.

CALL METHOD create_new_a

EXPORTING pf_obj = pf_obj

pf_subobj = pf_subobj

pf_extnumber = pf_extnumber

IMPORTING pfx_log_hndl = log_hndl.

IF ( sy-subrc NE 0 ).

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4

RAISING error.

ENDIF.

ENDMETHOD.

A public method of Super class has been called from the constructor of the sub class. we are getting the syntax error :

' In the constructor method, you can only access instance attributes, instance methods, or "ME" after calling the constructor of the superclass…'

Can you please suggest how to change the code with out affecting the functioanlity.

Thank you ,

Lakshmi.

2 REPLIES 2
Read only

Former Member
0 Likes
731

hi

try calling the method by using

super->method

otherwide you can try to call the method like this

divide_1_by( EXPORTING operand = 4 IMPORTING result = res ).

regards

Read only

Former Member
0 Likes
731

Hi,

Call that method by instance of Subclass. OR

SUPER-->method.

Read very useful document

Constructors

Constructors are special methods that cannot be called using CALL METHOD. Instead, they are called automatically by the system to set the starting state of a new object or class. There are two types of constructors - instance constructors and static constructors. Constructors are methods with a predefined name. To use them, you must declare them explicitly in the class.

The instance constructor of a class is the predefined instance method CONSTRUCTOR. You declare it in the public section as follows:

METHODS CONSTRUCTOR

IMPORTING.. [VALUE(]<ii>[)] TYPE type [OPTIONAL]..

EXCEPTIONS.. <ei>.

and implement it in the implementation section like any other method. The system calls the instance constructor once for each instance of the class, directly after the object has been created in the CREATE OBJECT statement. You can pass the input parameters of the instance constructor and handle its exceptions using the EXPORTING and EXCEPTIONS additions in the CREATE OBJECT statement.

The static constructor of a class is the predefined static method CLASS_CONSTRUCTOR. You declare it in the public section as follows:

CLASS-METHODS CLASS_CONSTRUCTOR.

and implement it in the implementation section like any other method. The static constructor has no parameters. The system calls the static constructor once for each class, before the class is accessed for the first time. The static constructor cannot therefore access the components of its own class.

Pls. reward if useful....