Application Development and Automation 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: 
Read only

instance attributes and static attributes

Former Member
0 Likes
13,441

Hi all

Can anybody please explain me instance and static attributes with examples...please

Thanks n Regards

vijaya

1 ACCEPTED SOLUTION
Read only

Former Member
7,762

Hi Vijaya,

Instance attributes

There exist one instance attribute for each instance of the class, thus they exist seperately for each object. Instance attributes are declared with the DATA keyword.

Static attributes

Static attributes exist only once for each class. The data are the same for all instances of the class, and can be used e.g. for instance counters. Static attributes are defined with the keyword CLASS-DATA.

PRIVATE SECTION.

CLASS-DATA: counter type i,

hope this helps.

Regards,

Kinshuk

6 REPLIES 6
Read only

Former Member
0 Likes
7,762

Hi Vijaya,

For Instance attributes, we need to create an object before working with them.ie Suppose there are 5 instance attributes, we need to create objects for all these 5 attributes.

While for static attributes, one object is enough for all of them.

Foe eg: Suppose that you have 5 instance attributes, if we want to assign values to them, you have to create 5 objects and then assign value to them.

On the other hand, if you have 5 static attributes, you need to have just one object . Assigning value to attribute of that object once is enough to assign values to all the 5 of them.

This may sound similar to static variables in other languages like C,C++ etc.

<b>Award points if found useful.</b>

Regards,

SP.

Read only

0 Likes
7,762

Hi sylendar

Can u please give me some example.iam very much confused with this oops concept.also can u suggest me which is the best place to find out some info abt abap objects.

Thanks and regards

vijaya

Read only

Former Member
0 Likes
7,762

Hi Vijaya,

You can go through this link which contains OOP documents I have uploaded...

http://www.esnips.com/web/OOP

You can also go to transaction code ABAPDOCU and go to <b>ABAP Objects</b> section.

You can also get nice programs in this site.

http://www.erpgenie.com/sap/abap/OO/index.htm

<b>Award points if found useful.</b>

Regards,

SP.

Read only

Former Member
0 Likes
7,762

A SIMPLE EXPLANATION TO UR QUESTION WOULD BE

STATIC ATTRIBUTES BELONG TO THE CLASS ITSELF .

WHILE INSTANCE ATTRIBUTES BELONG TO THE INSTANCE OF DAT CLASS i.e. OBJECTS OF THAT CLASS .

STATIC ATTRIBUTES CAN BE ACCESSED EVEN WITHOUT CREATING OBJECT OF DAT CLASS COZ THEY BELONG TO THE CLASS .

WHILE TO ACCESS INSTANCE ATTRIBUTES U NEED TO CREATE OBJECT OF DAT CLASS .

Read only

Former Member
7,762

Hi,

Instance attributes are confined to each instance of the class.

Static attributes remain the same for the whole class irrespective of any number of instances.

For example....

Consider there is a scenario where one user is creating 100 sales orders of type 'OR' (Standard Order). The Order type and the user remain the same. Whereas the details for the sales order like Sold to party, Items specific to each sales order.

So, in the above case Order type and User Id are Static variables, they remain the same across all the instances.

Instance attributes are for example the items of the sales order, Sales order number.

Hope I have answered your question.

Regards,

Vara

Read only

Former Member
7,763

Hi Vijaya,

Instance attributes

There exist one instance attribute for each instance of the class, thus they exist seperately for each object. Instance attributes are declared with the DATA keyword.

Static attributes

Static attributes exist only once for each class. The data are the same for all instances of the class, and can be used e.g. for instance counters. Static attributes are defined with the keyword CLASS-DATA.

PRIVATE SECTION.

CLASS-DATA: counter type i,

hope this helps.

Regards,

Kinshuk