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ü

Similar Messages

  • 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

  • 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 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.

  • 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!

  • 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

  • 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

  • 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

  • Is it possible to make a local class accessible in SE24 subclasses?

    G'Day,
    The scenario is simple: I have a global class created in SE24 with a local helper class defined in the local definitions/implementations sections. The issue is anything declared here is private; however I would like my local class to be available in the subclasses of the global class as well. In other words I want a protected local class.
    ZCL_SUPER  --> contains local utility class LCL_HELPER
        |
        V
    ZCL_SUB    --> needs to make use of LCL_HELPER's methods.
    I've messed about with different definitions and FRIENDS but no joy.
    I can think of two alternatives:
    1. Write a protected wrapper method in zcl_super to expose each lcl_helper method to the subclasses. Annoying, cumbersome, defeats the object of using a local class in first place.
    2. Define LCL_HELPER in an include which is added to all subclasses. This effectively makes it public as I no longer control where LCL_HELPER is used. (Unless I do funky stuff with packages which we don't do on this project).
    Any better suggestions/ideas/workarounds?
    Cheers,
    Mike

    Hi Naimesh,
    Thanks for the input. Interesting idea about interfaces, I need to play around with this a little.
    I don't agree what I'm trying to do would violate encapsulation. I'm after the same visibility level as other class component type. i.e. methods can be private, protected or public. Classes can be local or global - a protected class visible to subclasses would fit the principles quite well.
    Consider a global class GADGET which has a protected attribute WIDGET, type ref to a local class. The widget's methods and attributes should really be separate because it is it's own entity, but at the same time it has no business in the wider SAP system. ==> Perfectly sensible use of a local class.
    Now, this widget can turn, open, close, light up. So in a GADGET method I can say WIDGET->TURN( ). Create a subclass of GADGET and boom, all such code working with WIDGETs is broken. In some ways it makes local classes a little un-future-proof.
    The bothersome thing about the workarounds is that they de-object-orient the two objects by forcing us to create protected methods TURN_WIDGET LIGHT_WIDGET OPEN_WIDGET etc. on the GADGET class. Which goes back to my original point that there's little benefit of creating a local class if we need to do this....
    Or am I missing something?
    Cheers,
    Mike

  • 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.

  • Define local classes in function groups

    Hi,
    I have seen in few code examples that programmers defined their classes as follows:
    1. Interfaces are defined globally i.e. under package->class library->interfaces.
    2. implementing classes are defined locally under: package->function group (as public local class in the function group).
    My question is What is the advantage/disadvantage of it?
    (beside encapsulation).
    I heard that the class loader is working better in that way, is that right?
    thanks,
    Yaron

    Hi
    excuse me I miserunderstood.
    Perhaps it's true I don't know.
    I think the different is the SE24 is a library, so it's the tool arranged to analyze all class components you can need.
    I don't think it's easier to analyze an include (function group) where the class is defined and implemented.
    You shuold measure the time in order to load the class for both case, but probably the different isn't meaningful.
    You should consider that ABAP wasn't OO language, but it was adapted for OO, and so the most ABAP developer weren't used to use OO.
    I think you should define a class as local class if it's your own class.
    Max
    Message was edited by: max bianchi

  • 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;
    };

  • Oracle.jbo.domain.Number; local class incompatible

    Hi Forum,
    Development Tool     : Jdeveloper 9.0.4 (part of Oracle 10g Suite)
    Target Application Summary:
    A simple application which displays the content of a database table and allows it to be modified both through a web interface as well as a Swing standalone client.
    A Workspace having three projects:
    1) A Business layer defined by using BC4J(Business Components For Java) provided with Jdeveloper 10g.
    2) A Swing/JClient application for BC4J which accesses the BCJ4 layer using a Business component client data model.
    3)A JSP application using JSP for business components which accesses the BC4j layer
    Target Deployment:
    1) Light-weight swing interface at machine 1
    2) Business components and JSP part in an application server on Machine 2
    3) Oracle DB on Machine3
    Problem Statement
    We deployed the BC4J Middle tier on OC4J standalone as a session bean. Then the client jar was deployed as a remote application(using Swing/JClient for business componments), the following error comes:
    (oracle.jbo.PiggybackException) JBO-28300: Piggyback read error
    ----- LEVEL 1: DETAIL 0 -----
    (java.io.InvalidClassException) oracle.jbo.domain.Number; local class incompatible: stream classdesc serialVersionUID = -6507359405709672486, local class serialVersionUID = -592084144037230518
    Can the forum help me with the problem (i am using the library BC4JOracleDomains which has oracle.jbo.domain.Number class)
    Thanking you in advance.

    Firstly, good job on describing your problem/situation. Some people just don't bother to be verbose.
    Secondly, I have to note that I don't do any development in this way so I have no 1st hand experience with this excpetion. But, it appears as though you are using different versions of the jar files (which in turn contain different versions of the classes). Maybe you should take a look at that?

  • 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

Maybe you are looking for