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 b/w Class definition and implementation

Former Member
0 Likes
3,597

Hi All,

What is the exact difference b/w Class definition and implementation in OOABAP, What is exact purpose?

Please let me know.

Akshitha.

5 REPLIES 5
Read only

Sm1tje
Active Contributor
0 Likes
1,618

In the definition part you declare all your methods, attributes. And in the implementation part, you 'implement' the methods you defined, meaning you add the coding to your methods.

Definition: define class, methods, variables.

implementation: add coding to methods.

in a nutshell.

Read only

Former Member
0 Likes
1,618

hi,

class definition:

Defined in the global area of a local program :-

CLASS <class name> DEFINITION.

…..

ENDCLASS.

All the attributes , methods, events and interfaces are declared here.

Cannot be declared inside a subroutine/function module.

Class definition cannot be nested

class implementation:

Local class in a program is implemented as follows:-

CLASS <class name> IMPLEMENTATION.

…..

ENDCLASS.

Methods used by the class are described here.

A class can be implemented

At the end of the program( like subroutines).

After the class definition.

If the latter is adopted, one must then assign subsequent non-declarative statements explicitly to a processing block, such as START-OF-SELECTION, so that they can be accessed.

pls reward if useful.

regards,

rekha

Read only

Former Member
0 Likes
1,618

Hi,

Class definition : Definition means declaration of all

variables ,methods ..........

Class implementation : Here you have to write the logic

(functionality) for methods .

Ex:

CLASS C_COUNTER DEFINITION.

PUBLIC SECTION.

METHODS: SET_COUNTER IMPORTING VALUE(SET_VALUE) TYPE I,

INCREMENT_COUNTER,

GET_COUNTER EXPORTING VALUE(GET_VALUE) TYPE I.

PRIVATE SECTION.

DATA COUNT TYPE I.

ENDCLASS.

CLASS C_COUNTER IMPLEMENTATION.

METHOD SET_COUNTER.

COUNT = SET_VALUE.

ENDMETHOD.

METHOD INCREMENT_COUNTER.

ADD 1 TO COUNT.

ENDMETHOD.

METHOD GET_COUNTER.

GET_VALUE = COUNT.

ENDMETHOD.

ENDCLASS.

Pls. reward if useful...

Read only

ak_upadhyay
Contributor
0 Likes
1,618

Hi,

Defining Local Classes

Local classes consist of ABAP source code, where the ABAP statements CLASS...ENDCLASS are enclosed. A complete class definition consists of the following parts, a declaration part and, if required, an implementation part. It is found that the declaration part of a class IMPLEMENTATION¦

ENDCLASSThe implementation part of a class actually contains the implementation of all methods of the class because it is observed that the implementation part of a local class is a processing block. Therefore, subsequent coding itself is not a part of a processing block and is not accessible.

Class Structure

A class contains components where each component is assigned to a visibility section. Moreover, the classes implement methods. Let us define these components one by one.

Components

This is the first component and is declared in the declaration part of the class. The components define the attributes of the objects in a class. When you define a class, each component is assigned to one of the three visibility sections. This defines the external interface of the class and all of the components of a class are visible within the class. All components are in the same namespace. This means that all components of the class must have names that are unique within the class. There are two kinds of components in a class:

One that exists separately for each object in the class.

The other consists of those that exist only once for the whole class, regardless of the number of instances.

Attributes

It is the instance-specific components, which are known as instance components. The static components are those components that are not instance-specific. The classes can define the following components in ABAP Objects.

The attributes are internal data fields that can have any ABAP data type within a class. The state of an object is determined by the contents of its attributes. One kind of attribute is the reference variable. The reference variables are also very important as they allow you to create and address objects. Reference variables can be defined in classes, which allow you to access objects from within a class.

Reward points if useful....

Regards

AK

Read only

Former Member
0 Likes
1,618

Hi

in class definition we just decalre the methods,variables...

class c1 definition.

public section.

data:v_ref type i value 5.

class-data :

s_num type i value 6 .

methods: m1.

endclass.

whereas in class implementation we write the logic for that method which we have decalred earlier...

class c1 implementation .

method m1.

write: /'form class c1',v_ref.

endmethod.

endclass.