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: 

Differ-imp

Former Member
0 Kudos

can anybody explain what is the main difference between static and instance components of a class in all aspects.

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos

Hello Sandeep

There are two major differences:

1. Static components are "always" there meaning it is not required to create an instance of the class. Example: public static attribute CL_GUI_CFW=>FALSE.

2. Instance attributes are not visible in static method (whereas static attributes are visible in instance methods). Example: If you try to reference ME within a static class you get a syntax error.

Regards

Uwe

2 REPLIES 2

uwe_schieferstein
Active Contributor
0 Kudos

Hello Sandeep

There are two major differences:

1. Static components are "always" there meaning it is not required to create an instance of the class. Example: public static attribute CL_GUI_CFW=>FALSE.

2. Instance attributes are not visible in static method (whereas static attributes are visible in instance methods). Example: If you try to reference ME within a static class you get a syntax error.

Regards

Uwe

GrahamRobbo
Active Contributor
0 Kudos

Hi Sandy,

"instance" components need to be instantiated. Static components do not.

By example, take a static method of class myclass called mymethod. To call this method you just need to do something like this

call method myclass=>mymethod

It is essentally the same as a function module you could call like this.

call function 'myfunction'

Instance components require the class to be instantiated and copies of the components are created for each instantiated class. So you could instantiate the same class twice and the components of each class would be very separate.

Instantiation can happen a few different ways, but simplistically you would have to do something like this.

data myinstance type ref to myclass.
create object myinstance.
call method myinstance1->mymethod

Cheers

Graham Robbo