Skip to Content
author's profile photo Former Member
Former Member

When is it best to use Local Classes..?

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 10, 2005 at 10:34 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Jun 10, 2005 at 10:48 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.