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: 

Does a quick fix exist to create a constructor?

peisenhauer
Explorer

I really like to work with quick fixes, but I’m missing one feature in creation of methods from quick fix. If I take an existing class “ZCL_NEW_CLASS” and try to instatiate an object from it there is no quick fix to add a constructor from the given context. Is this planned or could it be added to the list of quick fixes to enable in future?

Example:

DATA(example) = NEW ZCL_NEW_CLASS( is_marc = ls_marc ).

CTRL+1 on “ZCL_NEW_CLASS” should give the suggestion “Create constructor” with parameter is_marc with type of the supplied ls_marc, as in the normal object->new_method( ) Quick fix.

Regards, Phillip

1 ACCEPTED SOLUTION

pokrakam
Active Contributor

Quick fixes exist to create constructors, class constructors and factory methods. But you need to do it from the class, just position your cursor on the class definition statement. It will ask you which attributes to create importing parameters for and generate the code for those too.

4 REPLIES 4

pokrakam
Active Contributor

Quick fixes exist to create constructors, class constructors and factory methods. But you need to do it from the class, just position your cursor on the class definition statement. It will ask you which attributes to create importing parameters for and generate the code for those too.

0 Kudos

Hey Mike,

okay so there is no other way at the moment? I'm aware of this feature but I hoped there was a way to avoid jumping into the class just for creating the constructor..

Regards,

Phillip

pokrakam
Active Contributor

No, but it's not a huge effort. <F3>, <ctrl-1>, generate constructor/factory method/...

But this won't include parameters. But the quick-fix for creating constructors or factory methods will offer to include the class's attributes as parameters - and I think that makes more sense than your calling code proposing the names.

IMHO constructors should be local or internal to a class anyway, factory method are a far better alternative. If you want, you can include parameters with a quick fix when creating methods. So if you do a quick fix on 'new' it should propose i as a parameter:

data(obj) = zcl_class=>new( i = 1 ).

0 Kudos

Thats the clue I needed thanks. I totally ignored factory methods.