‎2011 Nov 10 1:17 PM
Is it possible to create objects dynamically?
so that the name of the class is set via parameters and also the variables and which class is the superclass?
something like:
fieldsymbols: <a> type any.
data: data_object type ref to object.
create new class type data_object.
data_object-name = 'dynamic'.
data_object-subclass = 'superclass'.
create object <a> like class 'dynamic'
<a>-(method of superclass)( ) etc...
It is not ABAP code, but i hope you know what i mean?
Kindly hear from you!
Anton Pierhagen
‎2011 Nov 14 8:56 AM
Hi Anton,
Try using :
Function Module - SEO_CLASS_CREATE_COMPLETE.
Sample Program - SBMIG_CREATE_CLASS_AND_TTYPES
Regards,
Varun
‎2011 Nov 10 1:53 PM
Anton,
it's not quite clear what you are trying to achieve here. Do you want to dynamically create a class like is done in SE24 manually?
Or do you want to instantiate an object locally with reference to a global class defined in SE24?
Gr. Micky.
‎2011 Nov 10 1:55 PM
‎2011 Nov 10 2:18 PM
I guess it is, and a good start would be to look at function groups starting with SEO*.
I believe this question was asked in the forum before. Maybe searching for a similar question will give you some additional information.
Gr. Micky.
‎2011 Nov 10 4:29 PM
Hi
Thanks for your replies, but is not it what i am looking for i think. The class in the example of Naimesh Patel must be created in the system ? It is not the case that ABAP builds with this code a class ZCLASS?
And with code you can create methods, variables, etc.. voor this new builded class ZCLASS?
‎2011 Nov 12 6:04 AM
Anton,
May be following steps might help.
1. Create a new include program(keep this program blank) and include that to your program
2. Refresh above include program through your program and add lines of code dynamically to above program(by creating new subroutine)
3. Invoke above subroutine from required place of your program
I just got this an idea, but there might be several other ways to fulfill your requirement.
‎2011 Nov 14 7:04 AM
hi, i don't understand how dynamic classes can be made via this approach. Can you elleborate it?
‎2011 Nov 10 2:12 PM
You can use dynamic reference to instantiate your objects.
Like:
data: lo_ref type ref to object.
create object lo_Ref type ('ZCLASS').
call method lo_ref->('METH_1').
But problem in this design would be that your class & method name is hardcoded and it would be only checked at runtime, not at the design time. To overcome, this you can use the [Factory Method Design pattern|http://help-abap.zevolving.com/2011/10/abap-objects-design-patterns-factory-method/].
Regards,
Naimesh Patel
‎2011 Nov 14 8:56 AM
Hi Anton,
Try using :
Function Module - SEO_CLASS_CREATE_COMPLETE.
Sample Program - SBMIG_CREATE_CLASS_AND_TTYPES
Regards,
Varun
‎2011 Nov 14 9:11 AM