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 definition and Implementation in OOABAP

Former Member
0 Kudos

Hi All,

What is the meaning for Class definition and Implementation in OOABAP, where do we do this def & impl?

Please let me know.

Akshitha.

4 REPLIES 4

Former Member
0 Kudos

hi,

Definition part

The class components (for example, attributes and methods)

are defined in this part.

Implementation part

This part only contains the method implementations. The actual code is written as to how the methods behave.

A class is a description of a number of objects that have the same structure and the same behavior. A

class is therefore like a blueprint, in accordance with which all objects in that class are created.

The components of the class are defined in the definition part. The components are attributes, methods,

events, constants, types and implemented interfaces. Only methods are implemented in the

implementation part.

The CLASS statement cannot be nested, that is, you cannot define a class within a class.

Hope this helps, Do reward.

manuel_bassani
Contributor
0 Kudos

Hi,

in OO Programming, in the definition you define the type of the class (attributes, methods and events)

e.g.

CLASS myClass DEFINITION.

PUBLIC SECTION.
  methods:
    method1 importing par1 type char1,
    method2 returning value(par2) type i.

PRIVATE SECTION.
  data: attribute1 type i.

ENDCLASS.

in the implementation you define the behavior of the methods you've declared in definition (the ABAP code)

CLASS myClass IMPLEMENTATION.
METHOD method1.
  if par1 = 'A'.
    attribute1 = 1.
  else.
    attribute1 = 2.
  endif.
ENDMETHOD.

METHOD method2.
  par2 = attribute1.
ENDMETHOD.

ENDCLASS.

You can now use the class myClass declaring an object of type myClass:

DATA: myObject TYPE REF TO myClass.
DATA: value type i.

start-of-selection.

create object myObject.
call method myObject->method1( 'A' ).

value = myObject->method2( ).
write value.

call method myObject->method1( 'B' ).
value = myObject->method2( ).
write value.

You can find more informations about OO ABAP in ABAP Online Help or in [help.sap.com|http://help.sap.com/saphelp_nw70/helpdata/EN/ce/b518b6513611d194a50000e8353423/frameset.htm]

Please remember to reward points for useful answers.

Best regards,

Manuel

Former Member
0 Kudos

Have a look at below link and go to page 1291. It will give you good info abt OO ABAP.

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf

Also have a look at below links:

http://help.sap.com/saphelp_nw2004s/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm

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

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

http://esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf

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

http://esnips.com/doc/448e8302-68b1-4046-9fef-8fa8808caee0/abap-objects-by-helen.pdf

http://esnips.com/doc/39fdc647-1aed-4b40-a476-4d3042b6ec28/class_builder.ppt

Please do check transaction ABAPDOCU to learn more about ABAP OO. There are lots of examples and explanations there. Also, do check sapgenie.com for more examples(under their ABAP OO link).

A very good option would be "ABAP Objects" written by Horst Keller.

I hope it helps.

Thanks,

Vibha

Please mark all the useful answers

Former Member
0 Kudos

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.

Regards

Kiran Sure