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: 

class-data versus data and methods versus class-methods in OO ABAP

Former Member
0 Kudos

Hi

I was going thorugh following OO ABAP code.

CLASS vessel DEFINITION.

PUBLIC SECTION.

METHODS: constructor,

drive IMPORTING speed_up TYPE i,

get_id RETURNING value(id) TYPE i.

CLASS-METHODS: start,

objects,

inheritance,

interfaces,

events.

PROTECTED SECTION.

DATA: speed TYPE i,

max_speed TYPE i VALUE 100.

PRIVATE SECTION.

CLASS-DATA object_count TYPE i.

DATA id TYPE i.

ENDCLASS.

Whats is difference between methods and class-methods ?

What is the difference between data and class-data ?

4 REPLIES 4

Former Member
0 Kudos

Hi Rajesh,

<b>CLASS-METHODS and CLASS-DATA are static methods and static data in OO ABAP.</b>

<b>1)The diffrence between static methods and non static methods are</b>

a) static methods are referenced either by CLASS name or with instance of CLASS but instance methods are referenced ONLY by class references.

b) static methods are loaded into memory for their first reference to that method by CLASS or object reference.

<b>2)The diffrence between static members and instance component members are</b>

a)static methods are referenced either by CLASS name or with instance of CLASS but instance methods are referenced ONLY by class references.

b)The value of static components data is dependent on objects of CLASS instance components data is independent to each object ie If the value of static data is changed by one object will be changed in all objects of that CLASS references.

Thanks,

Vinay

0 Kudos

Please foucs some more light on static data and static methods versus general data and general methods..

0 Kudos

CLass-methods and class-data are static. which means that you can use them or access them without creating an object of the class. For example you can directly make a call to a method without creating an instance of the class.

cl_gui_frontend_services=>execute
       exporting
           document = 'C:test.txt'.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi Rajesh,

There are two types of componenets in a class

1)Static components

2) Instance components

Instance components exist for every instance of the class, while static exist only once for any number of instances of the class.

Components of the class are methods, attributes, events etc.

static attributes are represented by CLASS-DATA and instance attributes are represented by DATA.

static methods hence are done by CLASS-METHODS and can access only static attributes.

Instance methods are done by METHODS and can access any attribute.

For eg: supposing that in a class, there is a static attribute. Suppose after one instance is created, we are setting this static attribute value as 10. Now we are creating another instance of the same class. Now when you try to display the value of this attribute, it will be 10.ie. it needs to be initialized once and can be shared between instances.

Just go through this document..You will get nice info from this.

http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt

http://esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf

If you want to go deeper, like object persistence and all, just refer this document.

http://esnips.com/doc/92be4457-1b6e-4061-92e5-8e4b3a6e3239/Object-Oriented-ABAP.ppt

Regards,

SP.