cancel
Showing results for 
Search instead for 
Did you mean: 

When is it best to use Local Classes..?

nishanthbhandar
Contributor
0 Kudos

Hi All,

We all know that a global class creation is very helpful wherein the class can be reused by multiple programs.In contrast when is it best to use a local class within the program...?

Can anyone please share the sample scenarios where we need to make use of a local class...?

Cheers

Nishanth

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Nishanth,

I make the analogy between local classes and global classes and subroutines (forms) and function modules (not perfect, but it builds a picture in your mind).

Local classes are useful when you want to code using the object oriented paradigm, but the classes that you require are only of local relevance.

Having said, that, I am not a big user of local classes, as my feeling is that the overhead in developing them is not justified by any substantial benefits. Although, perhaps this view could be challenged now with new object specific functionality such as TRY/ENDTRY and so on.

It would be interesting to hear other people's opinion on this topic.

Cheers,

Brad

nishanthbhandar
Contributor
0 Kudos

Thanks for the viewpoints Brad..As quoted by you and as faced in practical applications i still haven't been able to figure out the competency of local classes against sub-routines.I wrote the same program in both the classical way and then by using only object-oriented approach.Neither do i see any significant performance difference nor any weighted reason of using local classes.That's why i was looking for possible practical applications or samples which justify it's use.

Cheers

Nishanth

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Nishanth,

First of all, there will be a few cases when creating a local class in your program is mandatory. For example,

if you're using an ALV Grid on your screen using the OO Approach, then you <b>must</b> declare a class locally in

your program if you want to handle the events. You cannot use a subroutine in this case.

Secondly, if you are looking for an explanation that is more introductory in nature, then the ABAP Programming

help has got some good documentation. Here are the links which explain the concepts with an example as a

transition from function groups to classes -

http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm

Regards,

Anand Mandalika.

nishanthbhandar
Contributor
0 Kudos

Thanks Anand..But I have already gone through the documentation..what i am looking for is not explicit areas of application like the ALV but more generic application areas of local classes..

Cheers

Nishanth

Former Member
0 Kudos

Hi Nishanth,

well I think you will not be very satisfied with my answer, but I use local classes always for

a) event handling of standard classes like ALV, SPLITTER, DOCKING-Container ... As Anand mentioned there is no other way to do it and

b) in case I am developing a more or less unique abap for which in the past (about 5 years ago) i would have used form routines. And in case of form routines I am using the methods of my local class. This keeps me trained on abap objects as my 'normal' business is BW consulting and not abap programming.

regards

Siggi