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

difference between DATA and CLASS-DATA ?

Former Member
0 Likes
6,181

Hi Friends,

Can any one explain me clearly the difference between DATA and CLASS-DATA ?

<b>pls no links or copy-paste</b>

points will be awarded for clear cut explanation..

Thanks and Regards

Vijaya

1 ACCEPTED SOLUTION
Read only

Former Member
3,102

HI,

Declares static attributes in a class or an interface in ABAP Objects.

You can only use this statement in the declaration part of a class declaration or in an interface definition . The CLASS- prefix to the DATA statement means that the attribute a is declared as a static attribute. Otherwise, the CLASS-DATA statement has the same syntax as the DATA statement for instance attributes.

Static attributes belong to the static components of a class. Unlike instance attributes, which exist separately for each instance (object) of a class, and can only be used after you have created at least one instance, static attributes exist once only and are shared by all instances in the class. They contain data that is shared by all instances, describing the part of the state of a class that is common.

rgds,

bharat.

7 REPLIES 7
Read only

Former Member
3,103

HI,

Declares static attributes in a class or an interface in ABAP Objects.

You can only use this statement in the declaration part of a class declaration or in an interface definition . The CLASS- prefix to the DATA statement means that the attribute a is declared as a static attribute. Otherwise, the CLASS-DATA statement has the same syntax as the DATA statement for instance attributes.

Static attributes belong to the static components of a class. Unlike instance attributes, which exist separately for each instance (object) of a class, and can only be used after you have created at least one instance, static attributes exist once only and are shared by all instances in the class. They contain data that is shared by all instances, describing the part of the state of a class that is common.

rgds,

bharat.

Read only

Former Member
3,102

Hi Vijaya,

DATA : is used to declare a general attribute.

CLASS-DATA : is used to declare a statis attribute.

Some more information here

Only static methods can access the static attributes.

Static Methods are declare using CLASS-METHODS.

Thanks,

Chandru

Read only

Former Member
0 Likes
3,102

DATA is used to declare Instance attributes,where as class-data is used to declare static attributes,

Regards,

Omkar.

Read only

0 Likes
3,102

what is the difference between Instance attributes,static attributes ?

Read only

0 Likes
3,102

Hi,

Instance attributes are confined to each instance of class where as static attributes are common for all the instances of class.

for eg...lets say sales order...the user name and customer name is same....

where as items will differ..

so Customer name is static attribute....Items are Instance attribute..

I think u got the point..

Regards,

Omkar.

Read only

Former Member
0 Likes
3,102

Hi Renu,

<b>Instance attributes</b>

Instance attributes are attributes that exist once per object, that is, once per

runtime instance of the class. They are defined with the syntax element

DATA.

<b>Static attributes</b>

Static attributes exist once for each class and are visible for all runtime

instances in that class. They are defined with the syntax element

CLASS-DATA.

Static attributes usually contain information that applies to all instances,

such as:

1. Types and constants

2. Central application data buffers

3. Administrative information, such as the instance counter

Technical literature often refers to static attributes as class attributes (compare to

the CLASS-DATA syntax element). In ABAP Objects, as in C++ and Java, the

official term is static attribute.

Thanks,

Chandru

Read only

Former Member
0 Likes
3,102

DATA - Dynamic values....

CLASS-DATA = Static values....

A simple example....

Each one of your team is having seperate id-card....with different details...(name, empno...) are dynamic...

But your company name is similar to all (static)....