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: 

What kind of classes can be instantiated and how it can be done?

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

9 REPLIES 9

former_member69765
Contributor
0 Kudos

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..

Former Member
0 Kudos

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

http://www.sap-press.de/katalog/buecher/htmlleseproben/gp/htmlprobID-28?GalileoSession=22448306A3l7U...

Regards

Abhijeet

Former Member
0 Kudos

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

matt
Active Contributor
0 Kudos

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

0 Kudos

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

0 Kudos

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

former_member230674
Contributor
0 Kudos

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.

former_member8532
Participant
0 Kudos

all classes can be instantiated except abstract. but you can create a reference variable of abstract class type.

thanks

Former Member
0 Kudos

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.