07-15-2008 9:49 AM
Dear All,
What kind of classes can be instantiated and how it can be done?
Can you please explain me in brief and provide sample code for it?
Thanks,
Anup Garg
07-16-2008 7:22 AM
Hi,
All classes except Abstract class can be instantiated means we can create object of that class.
To do this in your report, First ceate a referance variable of that class.
Suppose class name is CLASS and we want to create referance variable REF.
than write, DATA REF TYPE REF TO CLASS. and than create object(instance), CREATE OBJECT REF.
By using object you can access all public attributes and Public methods of that class.
If you are using global class than create object and call methods using PATTERN button after declaring reference variable.
With Thanks & Regards.
Vishal Thakur.
07-15-2008 10:03 AM
Hi Anup..
All the classes can be instantiated.
To instantiate ... use the statement CREATE OBJECT <class_name>.
Alternatively ... In you SE38 editor, press the Pattern Button. (Same used for FMs)
From your tool bar, press the button PATTERN. Select the radio button 'ABAP Object Patterns' and hit enter. Now select the radio button 'Create Object'. Now enter name of variable in field INSTANCE and enter the class name. Hit enter and you will see the code automatically populated.
Job done..
07-15-2008 10:05 AM
Hiii!
Class is just a description or you can say a set of rules, to access a class, you need to create its runtime object or instance. Any number of instances can be created for any class.
Check out this link
Regards
Abhijeet
07-15-2008 10:25 AM
Hi Anup,
Not all classes can be instantiated..
Whether a class can be instanced or not is determined by the visibility area where you are creating the instances, or whether it is an abstract class.
Instances of Abstract class cannot be created.
Moreover, instances of Private, Protected classes cannot be created publicly but only in the corresponding visibility section.
~ Piyush Patil
07-15-2008 3:03 PM
Piyush Patil's answer is the only entirely correct answer. All other answers so far are incomplete.
You instantiate a non-abstract class either through CREATE OBJECT or via a factory method on the class or its superclass.
matt
07-15-2008 3:39 PM
Hi,
Can you please let me know the syntex for Final class? Means how to know whether class is final or not. Instant of final class also can not be created.
Thanks,
Anup Garg
07-16-2008 5:48 AM
Hi Anup,
You can create instances of a Final class...its just that you cannot override its behaviour...
btw...If you are coding the whole class, you can define a class as Final as below
CLASS CLASS_NAME DEFINITION FINAL
.....
ENDCLASS
Else, if you use the class builder (SE24), you just need to check the Final checkbox available in the Properties section of the class.
~ Piyush Patil
07-15-2008 10:35 AM
hi anup,
All the classes can be instantiated except abstract classes.
if it useful, reward points. <= not allowed! Points will be removed.
By
Prasad G.V.K
Edited by: Julius Bussche on Jul 15, 2008 2:06 PM
Please read [the rules|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/rulesofEngagement] before posting.
07-15-2008 11:08 AM
all classes can be instantiated except abstract. but you can create a reference variable of abstract class type.
thanks
07-16-2008 7:22 AM
Hi,
All classes except Abstract class can be instantiated means we can create object of that class.
To do this in your report, First ceate a referance variable of that class.
Suppose class name is CLASS and we want to create referance variable REF.
than write, DATA REF TYPE REF TO CLASS. and than create object(instance), CREATE OBJECT REF.
By using object you can access all public attributes and Public methods of that class.
If you are using global class than create object and call methods using PATTERN button after declaring reference variable.
With Thanks & Regards.
Vishal Thakur.