Policy regarding creating global or local classes?

Hi!
What policy do you have regarding creating local or global classes in your company? We have decided to mostly use local classes since there is a risk of reusing global classes (when changing something in the global class after it has been used by several programs etc.) . But on the other side it is much easier to use transaction SE24 than creating all the includes by hand.  Have anyone else made thoughts about this issue?
Regards, Tine

Hi,
The policy is
<b>Create global class</b> if you want the class to be <b>reused</b>.
And<b> to avoid problems</b> when you change the class, make sure you change class in such a way that it does not effect the existing user's of the class.
Like <b>use OPTIONAL parameters</b> when you change method signature, <b>avoid changing method names</b>, <b>instead add new methods</b>.
You should use local classes only when you are sure that the code there is needed only by your program and nobody else.
If you keep creating local class's and <b>if two programs need the same class it is redundant to create local class's</b> and if you want a change in the class you have to change in all the places.
I hope it is clear.
Regards,
Sesh

Similar Messages

  • Create Global Class Definition using Local Class Source Code

    I would like to be able to automate the creation of global class definitions using source code that is defined in a text file (one example: convert a local class def to a global class def).
    Does SAP deliver this functionality?  (I'm already aware of the various classes that can be used to create global classes and how those classes can be implemented in a program to generate new classes.  I'm hoping to avoid having to create a custom solution.)
    Thanks in advance!

    We have a winner!
    Thanks Rich!
    It's not a 100% solution - I was hoping to be able to generate global classes/interfaces using source code alone, without requiring user intervention.
    It <i>is</i> however, a 90-95% solution because debugging SE24 reveals that by using a combination of the FM's SCAN_ABAP_OBJECTS_CLASSES & SEO_CLIF_MULTI_IMPORT, I should be able to <u>quickly</u> put together that custom application that I was trying to avoid.
    I knew about the existance of SEO_CLIF_MULTI_IMPORT but I did not know about SCAN_ABAP_OBJECTS_CLASSES.  I'm very happy to learn that I'm not going to have to write a parser!

  • What is meant by Local Class and how we can create local classes in abap?

    Hi Friends
    what is meant by Local Class and how we can create local classes in abap?
    Regards,
    Sree

    Hi
    Local classes are the classes which we declare and use using the SE38 ABAP editor
    Global classes are the classes which we find in SE24 and call the methods of them into our program.
    see the sample code
    REPORT zs_class.
    SELECTION SCREEN
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
    PARAMETERS:p_var TYPE i,
    p_var1 TYPE i.
    SELECTION-SCREEN END OF BLOCK b1.
    CLASS d_class DEFINITION
    CLASS d_class DEFINITION.
    PUBLIC SECTION.
    METHODS:
    add,
    sub.
    PROTECTED SECTION.
    DATA : var2 TYPE i.
    ENDCLASS. "d_class DEFINITION
    CLASS d_class IMPLEMENTATION
    CLASS d_class IMPLEMENTATION.
    METHOD add.
    var2 = p_var + p_var1.
    WRITE:/ var2.
    ENDMETHOD. "add
    METHOD sub.
    var2 = p_var - p_var1.
    WRITE:/ var2.
    ENDMETHOD. "sub
    ENDCLASS. "d_class IMPLEMENTATION
    START-OF-SELECTION
    START-OF-SELECTION.
    DATA: obj TYPE REF TO d_class.
    CREATE OBJECT: obj .
    CALL METHOD: obj->add,
    Regards
    Anji

  • How to export local class to global class in abap ?

    is there any report that can export local class to a global class ?
    thanks !

    Hi,
      you can go to  SE24  and  there you can create a new class with reference to the class already created and your new class will have the same properties as  your local class.

  • Local class - global class

    Hi Friends,
      Can a local class make friend with global class???
      for example i have a local class in se38 editor and this local class should access the private attribute of global class which is there in se24.
    Deepak

    HI Deepak
       Yo can define your ABAP Unit test class as a friend of the global class to be tested in the local class definition include of your global class. So, you have to add a line of code like
    CLASS <name of global class to be tested> DEFINITION LOCAL FRIENDS <name of local ABAP Unit class> in the include where the definition of local ABAP Unit Class is in. Then you can call the private methods of your global class in the local abap unit class methods.
    just refer these links
    http://help.sap.com/saphelp_nw2004s/helpdata/en/ec/d9ab291b0b11d295400000e8353423/content.htm
    local class -> global class
    Regards Rk

  • Local class as a friend of a global class

    Hi guys,
    I'm just wondering if I could make a local class which is defined in the local section of a global class to its friend. I need this to check private attriutes and methods with abap unit.
    Regards Christian

    Hi Christian,
    Yo can define your ABAP Unit test class as a friend of the global class to be tested in the local class definition include of your global class. So, you have to add a line of code like
    CLASS  in the include where the definition of local ABAP Unit Class is in. Then you can call the private methods of your global class in the local abap unit class methods.
    Regards,
    Sükrü

  • Is there a way to create a structure or a local class inside of another?

    In VB you can create a private type I believe in C++ it's called a struct I was wondering is there a way with Java to create a local class or structure to store variables in a group inside of another class. I'd rather have them in an structure for readability.

    you can do something like this.
    public class MyStruct {
    public String name;
    public int number;
    public double value;
    public class Test {
    private MyStruct struct = new MyStruct();
    private void setValue() {
    struct.name = "my name";
    struct.number = 1;
    struct.value = 20.0;
    public void setStruct(MyStruct newStruct)
    struct = newStruct;
    };

  • Import local class to global

    Hi,
    i try to import local classes to global classes and i have error ,
    in the program in se 80 (lcocal) i declare global declaration
    like:
    TYPE-POOLS icon.
    TYPES: ty_fuel TYPE p DECIMALS 2,ty_cargo TYPE p DECIMALS 2.
    and after that i declare the local class in includes .. and/// start of selection
    where i put it ?
    Regards

    Hi,
    i don't build another program the declaration is in the local progarm,
    and i have method that have to use icon ,
    where i put this declaration  i try in local types but i have error .
    Explicit length specifications are necessary with types C, P, X, N, and
    W in the OO context.
    Regards

  • How do you create a new local zone w/o all the global zone packages

    I have serveral servers with hundreds of packages added w/o the pkgadd -G option. Everytime I create a new local zone, the local zone inherits all the global zone packages. Is there a way to modify maybe the packaging DB to stop the automatic inhertitance of packages to create new empty local zone ?
    Edited by: cslew on Feb 4, 2008 8:02 PM

    Not really.
    If we're talking about sparse zones, they share the root partition with the global zone anyway, so regardless of whether the packages were 'registered' with the zones, they would get the software anyway.
    Of course, not registering the packages would speed up the patching process as it wouldnt have to futz around updating all the local package repositories.
    So it would be an advantage in some respects.
    If we're talking about a full root zone, then it ought to be possible in theory.
    But I'm not aware of a way to do it in practice.

  • Urgent !!!!!!!!!!!! regarding CREATE JAVA CLASS USING BFILE

    We have Oracle 8.1.7 spatial database. We got to load some java classes into the database. We would like to make it as the java programs to be loaded from a client system into the oracle server. I am using CREATE DIRECTORY command to create a directory object (say suppose \\prav\loadjavaclasses\. Then using the CREATE OR REPLACE JAVA CLASS USING BFILE (object_name, 'CLASSNAME.CLASS'). This .class file is in the network identified by prav which in turn has a shared directory (full privileges) loadjavaclasses folder. Can you please help in this regard.
    Please mail me to [email protected]
    thanks in advance
    SudhaSrikanthan
    null

    use loadjava

  • Create Global Object Policy

    Setting this policy on Server 2008 (not R2) domain controllers has no effect on users that are not domain admins.  We have set this policy in the domain controller default policy.  A user that is not a domain admin cannot create a global object,
    specifically a page file backed file mapping.  We have been performing this operation on previous operating systems without issues.  On a Server 2008 system that is not a domain controller this policy performs as expected.  Is there an additional
    policy affecting this privelege?  Is there a known issue on 2008 domain controllers?

    Hi,
    Thank you for your post here.
    First of all, could you please double check whether the users have the
    seCreateGlobalPrivilege
    from the Create Global Object policy? You may count on
    Showpriv.exe tool to enumerate the
    privilege. What will happen if you disable UAC?
    CreateFileMapping Function
    http://msdn.microsoft.com/en-us/library/aa366537(v=VS.85).aspx
    Since this is a issue related to Windows function/API, you would like to also post it on the MSDN
    forum to get helps from Dev folks.

  • Problem with local class, static private attribute and public method

    Hello SDN,
    Consider the following situation:
    1) I have defined a LOCAL class airplane.
    2) This class has a private static attribute "type table of ref to" airplane (array of airplanes)
    3) A public method should return the private static table attribute
    Problems:
    a) The table cannot be given as an EXPORTING parameter in the method because TYPE TABLE OF... is not supported and I get syntax errors. I also cannot define a dictionary table type because it is a local class.
    b) The table cannot be given as a TABLES parameter in the method because TABLES is not supported in the OO context.
    c) The table cannot be given as an EXPORTING parameter in the method defined as LIKE myStaticAttribute because my method is PUBLIC and my attribute is PRIVATE. ABAP syntax requires that all PUBLIC statements are defined before PRIVATE ones, therefore it cannot find the attribute to reference to with LIKE.
    I see only 2 solutions:
    a) Never ever use local classes and always use global classes so that I might define a dictionary table type of my class which I can then use in my class.
    b) Make the attribute public, but this goes against OO principles, and isn't really an option.
    Am I missing anything here, or is this simply overlooked so far?

    Hello Niels
    Since your class is local and, thus, only know to the "surrounding" application is does not really make sense to make it public to any other application.
    However, if you require to store instances of your local classes in internal tables simply use the most generic reference type possible, i.e. <b>OBJECT</b>.
    The following sample report shows how to do that. Furthermore, I believe it also shows that there are <u><b>no </b></u>serious inconsistency in the ABAP language.
    *& Report  ZUS_SDN_LOCAL_CLASS
    REPORT  zus_sdn_local_class.
    " NOTE: SWF_UTL_OBJECT_TAB is a table type having reference type OBJECT
    *       CLASS lcl_airplane DEFINITION
    CLASS lcl_airplane DEFINITION.
      PUBLIC SECTION.
        DATA:    md_counter(3)             TYPE n.
        METHODS: constructor,
                 get_instances
                   RETURNING
                     value(rt_instances)   TYPE swf_utl_object_tab.
      PRIVATE SECTION.
        CLASS-DATA: mt_instances    TYPE swf_utl_object_tab.
    ENDCLASS.                    "lcl_airplane DEFINITION
    *       CLASS lcl_airplane IMPLEMENTATION
    CLASS lcl_airplane IMPLEMENTATION.
      METHOD constructor.
        APPEND me TO mt_instances.
        DESCRIBE TABLE mt_instances.
        md_counter = syst-tfill.
      ENDMETHOD.                    "constructor
      METHOD get_instances.
        rt_instances = mt_instances.
      ENDMETHOD.                    "get_instance
    ENDCLASS.                    "lcl_airplane IMPLEMENTATION
    DATA:
      gt_instances      TYPE swf_utl_object_tab,
      go_object         TYPE REF TO object,
      go_airplane       TYPE REF TO lcl_airplane.
    START-OF-SELECTION.
      " Create a few airplane instance
      DO 5 TIMES.
        CREATE OBJECT go_airplane.
      ENDDO.
      gt_instances = go_airplane->get_instances( ).
      CLEAR: go_airplane.
      LOOP AT gt_instances INTO go_object.
        go_airplane ?= go_object.
        WRITE: / 'Airplane =', go_airplane->md_counter.
      ENDLOOP.
    END-OF-SELECTION.
    Regards
      Uwe<u></u>

  • 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

    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.

  • Getting cl_abap_structdescr for method parameters of LOCAL classes?

    Hi guys
    I have a bit of a of a problem with getting an instance of the cl_abap_structdescr class for a method parameter type of a local class. The RTTI structure abap_parmdescr can only be used to diffrentiate between the basic built-in ABAP types and whether types are structures, tables or references. The question now arrives that once you have diffentiated that the parameter is a structure how do you determine the actual structure TYPE name for local classes to create an instance of the cl_abap_structdescr to continue your run-time analysis. For dictionary classes the parameter type name can be retrieved from the seosubcodf table, to me it looks as if one would have to resort to scanning the source code of local classes to arrive at the actual  structure type name, but before I go to THAT kind of trouble I was wondering whether somebody out there might have a better solution for me. Your help would be grreatly appreciated and rewarded ;).
    Kind regards
    Ettienne Hugo

    Hello Uwe
    Thanks for your reply, I checked out the CL_OO_LOCAL_CLASSES class, unfortunately the class actually operates on the local classes declared for a dictionary class. I think to clarify my question I should point out that the parameters I'm trying to process are parameters that belong to classes that are defined and implemented using include programs, these include programs would then typically be used in Function Groups to construct applications so the classes that I refer to are actually not in any way related to dictionary classes. The cl_abap_classdescr class works fine on these types of classes when you refer to them using the "\PROGRAM=my_program\CLASS=my_class" format with the describe_by_name method, unfortunately the class just does not provide sufficient information for structure type parameters to actually construct them during run-time...
    Stay well
    Ettienne

  • Local Class Transaction Code Problem

    Hi friends,
            I have created report program using local class. I have also used selection screen to get input from user. I have created oops transaction code (using se93) for that program.
    Problem is selection screen is not displayed when program is executed using tcode.
    I think logically it not possibel to display the selection screen. Is it true?. OR
    What Should I do?.
    Next Question is, I have also created  global class from my report program. But i cant able to find my class in se24.
    I have done following things.
      1) imported a local class from my report prg. ( In pop up screen that class icon(circle shaped icon) shown in gray colour)
      2) Assigend New class name starting with 'Z'.
      3) Selected overwrite existing class checkbok.
      4) selected import icon.
          'Import Completed Succesfully' message appeared. Still i am not able to find my class.
         Kindly provide answers.
    Thanks In Advance,
    S.Senthil

    Hi senthil kumar ,
    u can display the selection screen and secondly try to create your report in module pool type,
    and when also check if the class is activated or not and then check in se24,
    if still the issue remains
    let me know...
    thanks
    ravi

Maybe you are looking for

  • Opening Balance and closing balance

    Dear All,              Can i create a calculated field for ledger opening balance and closing balance. we are using  epicor. I dont know the exact table which captures opening balance and closing balance, where as i got credit balances and debit bala

  • "Error Code is -50"

    "Error code is -50" keeps popping up on certain files. I keep getting synchronization errors for my clients whose home directories are stored on the server and we are using Portable Accounts. The error is mainly related to items on the desktop, howev

  • Increasing character count in SMS??

    I currently have a registry editor on my 700w, and was wondering how i can make my text messages longer than 160 characters, or at least split them up automatically into multiple messages. Does anyone know how to do this? Thanks for all help!! Post r

  • Photoshop vs. Photoshop Extended and FCE

    Due to a variety of reasons, I need to move up (way up) from Photoshop Elements to the full Photoshop program. I'm reading all about the neato video-related features that the PS "Extended" version has for users. It all sounds pretty sweet, but I'm wo

  • Overscroll Always...  For Windows?

    There is an optional plug-in for Mac that supposedly opens up overscrolling - the ability to pan a window within the work area even if it fits entirely. On this page, it's listed under the heading, "Plug-ins available via web download - supported in