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

inheritance questions

Former Member
0 Likes
862

Hi,

i inheritance to subclass from super ( global- se24)

and i have 2 constructors

1. CONSTRUCTOR - from the super

2.CLASS_CONSTRUCTOR - of the sub

i want to add parameters to Class constructor and i cant i get this Error (Class constructors and destructors do not have parameters and exceptions) way? the CONSTRUCTOR of the super have parameters .

Regards

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
818

CONSTRUCTOR could have the Importing parameter but the CLASS_CONSTRUCTOR will not have any parameter.

CLASS_CONSTRUCTOR is a static class and parameters to that method are not supported.

Check online help on the class_constructor.

Example from the help:


CLASS some_class DEFINITION. 
  PUBLIC SECTION. 
    CLASS-METHODS class_constructor. 
  PRIVATE SECTION. 
    CLASS-DATA access_program TYPE sy-repid. 
ENDCLASS. 

CLASS some_class IMPLEMENTATION. 
  METHOD class_constructor. 
    access_program = sy-repid. 
  ENDMETHOD. 
ENDCLASS. 

Regards,

Naimesh Patel

Hi,

i inheritance to subclass from super ( global- se24)

and i have 2 constructors

1. CONSTRUCTOR - from the super

2.CLASS_CONSTRUCTOR - of the sub

i want to add parameters to Class constructor and i cant i get this Error (Class constructors and destructors do not have parameters and exceptions) way? the CONSTRUCTOR of the super have parameters .

Regards

5 REPLIES 5
Read only

naimesh_patel
Active Contributor
0 Likes
819

CONSTRUCTOR could have the Importing parameter but the CLASS_CONSTRUCTOR will not have any parameter.

CLASS_CONSTRUCTOR is a static class and parameters to that method are not supported.

Check online help on the class_constructor.

Example from the help:


CLASS some_class DEFINITION. 
  PUBLIC SECTION. 
    CLASS-METHODS class_constructor. 
  PRIVATE SECTION. 
    CLASS-DATA access_program TYPE sy-repid. 
ENDCLASS. 

CLASS some_class IMPLEMENTATION. 
  METHOD class_constructor. 
    access_program = sy-repid. 
  ENDMETHOD. 
ENDCLASS. 

Regards,

Naimesh Patel

Read only

0 Likes
818

HI Naimesh Patel ,

thanks ,

if i want to put parameters in constructor of sub class where i do that?

i ask it becouse i in the sub class i have

1. constructor - of the super class.

2. ClassConstructor - of the sub and i cant put in that parmaters .

so if i want to create object with parameters of type ref to the subcalss with export (to the constucor) how i do that?

Regards

Read only

0 Likes
818

Hi Ricardo,

Please check the CONSTRUCTOR section in this link

http://help.sap.com/saphelp_nw70/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm

Stated that no parameters can be passed to CLASS CONSTRUCTOR.

Hope this would help you.

Good luck

Narin

Read only

0 Likes
818

Go to SE24.

Open your SubClass

And press the "Create Constructor" button

It will ask if you want to include the parameters from the Super class.

If you need than press Yes, else press NO.

So, when you create a reference of this class.

It will first call the Super's Constructor

Than Subclass's construtor.

Regards,

Naimesh Patel

Read only

narin_nandivada3
Active Contributor
0 Likes
818

Hi Ricardo,

CLASS_CONSTRUCTOR's are nothing but Static constructors. They do not have any parameters as

normal Constructors do.. In general these are used to instantiate a class.

In a CLASS_CONSTRUCTOR IMPLEMENTATION specify CREATE OBJECT <obj1>

Obj1 may be the ref of anyother class in your program.

So when ever the program is executed the Object is created for the class its referred.

Hope this would help you.

Good luck

Narin