Overriding attributes in ABAP objects

Hello,
I currently want know if it is possible to override attributes in ABAP objects. i know it is possible with methods. I have extend a previous class functionality and want to change the refrence type of an attribute from the parent class, but only on the child. Is this possible in ABAP object or even in normal object oriented techniques.
Thanks
Brendan

Hi,
ususally you can achive this with other technics. You can e.g. use the class hierarchy for this:
The attribute is of type REF_SUPERCLASS. Within the superclass it should be working when you set subclasses of REF_SUPERCLASS as attribute.
Another way is to use interfaces as reference type for your attribute.
Please refer to [ABAP Objects|http://help.sap.com/saphelp_nw70/helpdata/EN/ce/b518b6513611d194a50000e8353423/frameset.htm]. Especially the chapters about Inheritance and Interfaces.
Regards Rudi

Similar Messages

  • How to override attributes of one class into another class in OOPS ABAP

    I was trying to override attribute(data memeber) defined in super class into subclass ,
    but I didnt find any solution to that.
    Please tell me ho to do that?
    Ex
    Class ABC definition
          Public section
             data : x type i.
       end class
    Calss XYZ definition inheriting from ABC.
        Publec section.
           data : x type  i.                                            <<----
    here is the problem
    endclass.

    when you define a subclass all the properties of superclass are inherited into class.
    You dont need to define it again.
    data : x type i " delete this line.
    Object of your subclass will be able to recognize x.
    Regards,
    Lalit Mohan Gupta.

  • Is there a table type ATTRIBUTE that can be defined in an ABAP object?

    Hi. Within SE24 on the Attributes tab, is there a way to define an attribute of type TABLE? If you put in STANDARD TABLE as the reference type, it does not allow a generic table type.
    What I want to do is pass in a standard table type to my constructor, and then assign it to a private table attribute in the object.
    I do not want to assign the table to a local variable of the constructor. I want to store the table in a private object attribute. I don't mind if the attribute type is a specific table type (such as KNA1), I just want to be able to assign the constructor's table parameter to some type of private object attribute.
    Thanks.
    Brendan

    Hi Brendan,
      No they are not same. A modelled class or method or an attribute will not have any realtime appliaction. Say for example you want to provide a method or Attribute which may be used in future or expected to be used in future, then you declare that method as Modelled. YOu can execute such a method or access such an attribute.
    Abstract Class is an executable class...but it will have some methods with no implementation. The implementation of such methods will upto the user who is accessing that class.A class defined as ABSTRACT cannot be instantiated, that is, you cannot use CREATE OBJECT with reference to the class. Instead, you can only address the class using its static components or its subclasses. The major purpose of an abstract class is to serve as a template for subclasses.
    If a class contains abstract methods, that is, method declarations with the ABSTRACT addition, the whole class must also be abstract (that is, have the ABSTRACT addition), since a class may not be instantiated if it has unimplemented methods. Equally, if a subclass does not implement all of the abstract methods of its superclasses, it must itself declare them abstract.
    Regards,
    Vara

  • Logical Database in Abap Objects

    Hi to All
    I want do it a program report using a Logical Database.
    Is this possible ??? But when I make a GET <node>, occurs the following error:
             "" Statement "ENDMETHOD" missing.  ""
    I'm doing the following:
    CLASS MONFIN IMPLEMENTATION.
           METHOD TRAER_DATOS.
                   GET VBRK.
           ENDMETHOD.
    ENDCLASS.
    Please, somebody tell me how I use the logical database in Abap Objects.
    Thank you very much
    Regards
    Dario R.

    Hi there
    Logical databases whilst of "some use" are not really part of OO.
    If you want to use a logical database in an abap OO program I would create a special class which just does the get data from your DB and pass this either at record or table level.
    Techniques such as GET XXXX LATE aren't really part of any OO type of application since at Object Instantiation time you should be able to access ALL the attributes of that object.
    As far as OO is concerned Logical databases are a throwback to "Dinosaur Technology".
    Since however modules such as SD and FI are still heavily reliant on relational structures (i.e linked tables etc)  then there is still some limited life in this stuff but for OO try and solve it by another method.
    If you really must use this stuff in OO then do it via a FMOD call and save the data in a table which your method will pass back to your application program.
    You can't issue a GET command directly in a method.
    Cheers
    Jimbo

  • Hook methods in ABAP Objects

    Hello,
    i discovered that method calling in the class-inheritance of ABAP Objects doesn't work similar to other OO languages.
    Example:
    1 Superclass named "Z_CLASS"
    1 Subclass of "Z_CLASS" named "Z_SUB"
    Z_CLASS defines a method "initialize" and has a constructor which calls "initialize".
    Z_SUB redefines the method "initialize" assigning some values to instance-attributes.
    If i instantiate a new "Z_SUB"-object then the contructor of "Z_CLASS" is called which calls ITS OWN "initialize" not the one of the subclass. For comparison: Java would call the initialize of the subclass.
    I have to implement a constructor in every subclass of "Z_CLASS" which calls the super constructor and the own "initialize" after that to solve this problem. This isn't the proper OO way!
    Did i miss something or am i right?
    Thanks in advance,
    Stefan

    Check out this, it might be helpfull...
          INTERFACE I_COUNTER
    INTERFACE i_counter.
      METHODS: initialize.
    ENDINTERFACE.
          CLASS C_COUNTER1 DEFINITION
    CLASS c_counter1 DEFINITION.
      PUBLIC SECTION.
        INTERFACES i_counter.
        METHODS: constructor.
        DATA count TYPE i.
    ENDCLASS.
          CLASS C_COUNTER1 IMPLEMENTATION
    CLASS c_counter1 IMPLEMENTATION.
      METHOD constructor.
        CALL METHOD me->i_counter~initialize.
      ENDMETHOD.
      METHOD i_counter~initialize.
        count = count + 10.
        write:/ 'count from super', count.
      ENDMETHOD.
    ENDCLASS.
          CLASS C_COUNTER2 DEFINITION
    CLASS c_counter2 DEFINITION INHERITING FROM c_counter1.
      PUBLIC SECTION.
        METHODS: constructor,
                 initialize.
        DATA count1 TYPE i.
    ENDCLASS.
          CLASS C_COUNTER2 IMPLEMENTATION
    CLASS c_counter2 IMPLEMENTATION.
      METHOD constructor.
        CALL METHOD super->constructor.
        CALL METHOD me->initialize.
      ENDMETHOD.
      METHOD initialize.
        count = ( count / 10 ).
        write:/ 'count from sub', count.
      ENDMETHOD.
    ENDCLASS.
    DATA: count TYPE REF TO c_counter2.
    START-OF-SELECTION.
    CREATE OBJECT count TYPE c_counter2.

  • How to use LDB PNP with ABAP objects in a program

    Hello,
    I am wondering if anybody has used the HR logical database(LDB) PNP with user defined ABAP objects in a program? I am using the FM- <b>LDB_PROCESS</b> but its not working. Also assigning PNP in the attributes section of the program -- so that I can use predefined fields from the LDB and then invoking the FM doesn't work -- throwing 'Logical database already active' error.
    I suppose even with the ABAP objects and the new FM -- I should still be able to utilize the pre-defined fields of the PNP database -- and also the built in authorizations. I cannot use GET PERNR and REJECT as they give errors. I understand that the use of HR-macros (RP-PROVIDE-FROM-LAST and et al.) are not allowed as they use the table work area -- which is not allowed in ABAP-OOPS.
    I would really appreciate if anyone could show me some insight regarding this. Thank you.
    Kshitij R. Devre

    Hi Kshitij
    It would be really good if we could use both together. But as I know, it is not possible. "GET pernr." is an event-like loop statement and so cannot be used in OO context. And I guess, the same restriction holds for the "LDB_PROCESS" since it uses LDB-specific processing.
    What I suggest you is to use standard and BAPI functions.
    Sorry for giving bad news...
    *--Serdar

  • Use of 'ME' keyword in ABAP Objects?

    Hi all,
       Can any one please  use of 'ME' keyword in ABAP Objects?
    Thanks,
    Vijay.
    Moderator message: next time, please search for available information before asking.
    Edited by: Thomas Zloch on Sep 16, 2010 5:33 PM

    Hi,
    Please find the description about the ME keyword as per the SAP documentation and help.sap.com.
    Within the implementation of every instance method, an implicitly created local reference variable called me is available, which points to the instance in which the method is currently being executed. The static type of me is the class in which the instance method is implemented.
    Each class implicitly contains the reference variable me. In objects, the reference variable mealways contains a reference to the respective object itself and is therefore also referred to as the self-reference. Within a class, you can use the self-reference me to access the individual class components:
    -To access an attribute attr of your class: me->attr
    -To call a method meth of your class: CALL METHOD me->meth
    When you work with attributes of your own class in methods, you do not need to specify a reference variable. The self-reference me is implicitly set by the system. Self-references allow an object to give other objects a reference to it. You can also access attributes in methods from within an object even if they are obscured by local attributes of the method.
    Regards,
    Sagar

  • ABAP reports to ABAP Objects

    Hi all,
    What are the steps to be taken while converting a normal ABAP report program to ABAP objects? Also, How do we write a module(of a module pool program) in ABAP objects?
    Thanks in Advance,
    Aswin

    Use methods of a class instead of subrouties wherever possible.
    Declare the global variables in the attributes section of a class.
    Make sure that your design itself is more data centric than process centric.
    Regards,
    Ravi

  • Remote-Enabled Method (wrt ABAP Objects)

    Hi All,
    Adhering to ABAP Objects, in my project, i am creating instance methods or static methods instead of Function modules.
    now i have a requirement, where some functionality needs to be invoked on another server using an RFC destination.
    if i create a function module,
    1)i can tick the radio button "Remote-Enabled Module" under the Attributes of function module and
    2)i can invoke it as
    CALL FUNCTION 'ZMY_FM' DESTINATION 'RFCDESTNAME'
         EXPORTING
         IMPORTING
    in such cases is it mandatorily required to create an FM like above, or can i avoid it by writing an equivalent instance method or static method
    if we replace the FM with a method, then
    1)how can i make the method rfc enabled, and
    2)what is the syntax of providing the rfc destination name while invoking method.
    Is there any other concept provided in ABAP Objects, that is recommended instead of "Remote-Enabled Function Modules"
    thanks in advance,
    Madhu_1980

    Hello Madhu
    If you look at the properties of any global class you will find that the DropDown list for "Category" contains item:
    30 = Proxy Class for Remote Interface
    For me this sounds like that there might be something in the pipeline of SAP to provide RFC-enabled methods. However, if and when this becomes true is probably unknown.
    Regards
      Uwe

  • How to synchronize concurrent access to static data in ABAP Objects

    Hi,
    1) First of all I mwould like to know the scope of static (class-data) data of an ABAP Objects Class: If changing a static data variable is that change visible to all concurrent processes in the same Application Server?
    2) If that is the case. How can concurrent access to such data (that can be shared between many processes) be controlled. In C one could use semaphores and in Java Synchronized methods and the monitor concept. But what controls are available in ABAP for controlling concurrent access to in-memory data?
    Many thanks for your help!
    Regards,
    Christian

    Hello Christian
    Here is an example that shows that the static attributes of a class are not shared between two reports that are linked via SUBMIT statement.
    *& Report  ZUS_SDN_OO_STATIC_ATTRIBUTES
    REPORT  zus_sdn_oo_static_attributes.
    DATA:
      gt_list        TYPE STANDARD TABLE OF abaplist,
      go_static      TYPE REF TO zcl_sdn_static_attributes.
    <i>* CONSTRUCTOR method of class ZCL_SDN_STATIC_ATTRIBUTES:
    **METHOD constructor.
    *** define local data
    **  DATA:
    **    ld_msg    TYPE bapi_msg.
    **  ADD id_count TO md_count.
    **ENDMETHOD.
    * Static public attribute MD_COUNT (type i), initial value = 1</i>
    PARAMETERS:
      p_called(1)  TYPE c  DEFAULT ' ' NO-DISPLAY.
    START-OF-SELECTION.
    <b>* Initial state of static attribute:
    *    zcl_sdn_static_attributes=>md_count = 0</b>
      syst-index = 0.
      WRITE: / syst-index, '. object: static counter=',
               zcl_sdn_static_attributes=>md_count.
      DO 5 TIMES.
    <b>*   Every time sy-index is added to md_count</b>
        CREATE OBJECT go_static
          EXPORTING
            id_count = syst-index.
        WRITE: / syst-index, '. object: static counter=',
                 zcl_sdn_static_attributes=>md_count.
    <b>*   After the 3rd round we start the report again (via SUBMIT)
    *   and return the result via list memory.
    *   If the value of the static attribute is not reset we would
    *   start with initial value of md_count = 7 (1+1+2+3).</b>
        IF ( p_called = ' '  AND
             syst-index = 3 ).
          SUBMIT zus_sdn_oo_static_attributes EXPORTING LIST TO MEMORY
            WITH p_called = 'X'
          AND RETURN.
          CALL FUNCTION 'LIST_FROM_MEMORY'
            TABLES
              listobject = gt_list
            EXCEPTIONS
              not_found  = 1
              OTHERS     = 2.
          IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          CALL FUNCTION 'DISPLAY_LIST'
    *       EXPORTING
    *         FULLSCREEN                  =
    *         CALLER_HANDLES_EVENTS       =
    *         STARTING_X                  = 10
    *         STARTING_Y                  = 10
    *         ENDING_X                    = 60
    *         ENDING_Y                    = 20
    *       IMPORTING
    *         USER_COMMAND                =
            TABLES
              listobject                  = gt_list
            EXCEPTIONS
              empty_list                  = 1
              OTHERS                      = 2.
          IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
        ENDIF.
      ENDDO.
    <b>* Result: in the 2nd run of the report (via SUBMIT) we get
    *         the same values for the static counter.</b>
    END-OF-SELECTION.
    Regards
      Uwe

  • ABAP Objects with Workflows / Classes and Instances

    Hello,
    I am currently designing a workflow using an ABAP-Objects. So far I have been been able to get my Workflow to run with my class, but I have a couple of problems:
    - I am using the Function 'SAP_WAPI_START_WORKFLOW' to start other subflows, which enables me to decide which subflow to start at runtime. All of the subflows have standart importing-parameters in their containers, such as the key of my class. In each workflow I instantiate my class using a self-written method, which checks the table T_INSTANCES in my object, and then either returns the object reference to an existing instance or creates a new one. Obviously all of the subflows that I call from my main workflow should be able to find the instance. As far as I can see in their protocolls, this happens without any problems. The problem starts when I make changes to the instance. For example the changing of attributes (with setter methods) seems not to work. After the subflows are finished, in my main workflow, I do not see (with getter methods) any changes that has been made to the object. Is local persistence really limited to one workflow ?
    - My second problem is basically about the workflow container in workflow protocoll. In the same workflow, I can change the attributes of my object. Nevertheless, the protocoll always show the initial attribute, even though, my task with the getter-method returns the new value of the attribute.
    I appreciate any help and thanks a lot in advance.

    Hello Pauls,
    Thank you for your answer. I think we are misunderstanding each other. The problem occurs (I think) because my class is not a singleton class. Or am I mistaken ?
    When I directly start a subflow from my main workflow, then the instance that I have created in my main workflow is also visible to the subflow. As well as the static table which actually keeps track of the instances. So, in this case the subflows finds the instance and then can use the object as is.
    When I start a subflow from my main workflow using the function I mentioned above, then even though the same object key is used, there is a new instance. And the static table (I assume that you mean a static variable from type table, when you say "class table") is completely empty. In this case, my "new" instance is created which overwrites every attribute that I have set in the main workflow, before I started the subflow. More interestingly, my main workflow instantiates another new object, as soon as the subflow has finished. (I am using an event to wait for the subflow to finish.)
    On the other hand, I am not quite sure that I understood your approach with refresh and how it could help me. This method is not well documented anywhere, and all of the examples that I have found are about "leave it empty"
    As far as I understood, this method is called by the workflow between the steps, when an object is used. I slowly start to think that I need advanced information about Workflows and Memory Management.
    Thanks a lot again. Apparently, I am the only person who came across such a problem
    Greetz
    G.Fendoglu

  • Undesratsnding abap objects

    hi
    can any one provide basic material for underatanding object oriented in abap...with many sample programs(preferably)....u can also provide me links....
    thank you,
    Ginni

    Methods in ABAP Objects - Example
    The following example shows how to declare, implement, and use methods in ABAP Objects.
    Overview
    This example uses three classes called C_TEAM, C_BIKER, and C_BICYCLE. A user (a program) can create objects of the class C_TEAM. On a selection screen, the class C_TEAM asks for the number of members of each team.
    Each object in the class C_TEAM can create as many instances of the class C_BIKER as there are members in the team. Each instance of the class C_BIKER creates an instances of the class C_BICYCLE.
    Each instance of the class C_TEAM can communicate with the program user through an interactive list. The program user can choose individual team members for actions. The instances of the class C_BIKER allow the program user to choose the action on a further selection screen.
    Constraints
    The ABAP statements used for list processing are not yet fully available in ABAP Objects. However, to produce a simple test output, you can use the following statements:
    WRITE [AT] /<offset>(<length>) <f>
    ULINE
    SKIP
    NEW-LINE
    Note: The behavior of formatting and interactive list functions in their current state are not guaranteed. Incompatible changes could occur in a future release.
    Declarations
    This example is implemented using local classes, since selection screens belong to an ABAP program, and cannot be defined or called in global classes. Below are the definitions of the two selection screens and three classes:
    Global Selection Screens
    SELECTION-SCREEN BEGIN OF: SCREEN 100 TITLE TIT1, LINE.
      PARAMETERS MEMBERS TYPE I DEFAULT 10.
    SELECTION-SCREEN END OF: LINE, SCREEN 100.
    SELECTION-SCREEN BEGIN OF SCREEN 200 TITLE TIT2.
      PARAMETERS: DRIVE    RADIOBUTTON GROUP ACTN,
                  STOP     RADIOBUTTON GROUP ACTN,
                  GEARUP   RADIOBUTTON GROUP ACTN,
                  GEARDOWN RADIOBUTTON GROUP ACTN.
    SELECTION-SCREEN END OF SCREEN 200.
    Class Definitions
    CLASS: C_BIKER DEFINITION DEFERRED,
           C_BICYCLE DEFINITION DEFERRED.
    CLASS C_TEAM DEFINITION.
      PUBLIC SECTION.
      TYPES: BIKER_REF TYPE REF TO C_BIKER,
             BIKER_REF_TAB TYPE STANDARD TABLE OF BIKER_REF
                                               WITH DEFAULT KEY,
             BEGIN OF STATUS_LINE_TYPE,
               FLAG(1)  TYPE C,
               TEXT1(5) TYPE C,
               ID       TYPE I,
               TEXT2(7) TYPE C,
               TEXT3(6) TYPE C,
               GEAR     TYPE I,
               TEXT4(7) TYPE C,
               SPEED    TYPE I,
             END OF STATUS_LINE_TYPE.
      CLASS-METHODS: CLASS_CONSTRUCTOR.
      METHODS: CONSTRUCTOR,
               CREATE_TEAM,
               SELECTION,
               EXECUTION.
      PRIVATE SECTION.
      CLASS-DATA: TEAM_MEMBERS TYPE I,
                  COUNTER TYPE I.
      DATA: ID TYPE I,
            STATUS_LINE TYPE STATUS_LINE_TYPE,
            STATUS_LIST TYPE SORTED TABLE OF STATUS_LINE_TYPE
                                          WITH UNIQUE KEY ID,
            BIKER_TAB TYPE BIKER_REF_TAB,
            BIKER_SELECTION LIKE BIKER_TAB,
            BIKER LIKE LINE OF BIKER_TAB.
      METHODS: WRITE_LIST.
    ENDCLASS.
    CLASS C_BIKER DEFINITION.
      PUBLIC SECTION.
      METHODS: CONSTRUCTOR IMPORTING TEAM_ID TYPE I MEMBERS TYPE I,
               SELECT_ACTION,
               STATUS_LINE EXPORTING LINE
                           TYPE C_TEAM=>STATUS_LINE_TYPE.
      PRIVATE SECTION.
      CLASS-DATA COUNTER TYPE I.
      DATA: ID TYPE I,
            BIKE TYPE REF TO C_BICYCLE,
            GEAR_STATUS  TYPE I VALUE 1,
            SPEED_STATUS TYPE I VALUE 0.
      METHODS BIKER_ACTION IMPORTING ACTION TYPE I.
    ENDCLASS.
    CLASS C_BICYCLE DEFINITION.
      PUBLIC SECTION.
      METHODS: DRIVE EXPORTING VELOCITY TYPE I,
               STOP  EXPORTING VELOCITY TYPE I,
               CHANGE_GEAR IMPORTING CHANGE TYPE I
                           RETURNING VALUE(GEAR) TYPE I
                           EXCEPTIONS GEAR_MIN GEAR_MAX.
      PRIVATE SECTION.
      DATA: SPEED TYPE I,
            GEAR  TYPE I VALUE 1.
      CONSTANTS: MAX_GEAR TYPE I VALUE 18,
                 MIN_GEAR TYPE I VALUE 1.
    ENDCLASS.
    Note that none of the three classes has any public attributes. The states of the classes can only be changed by their methods. The class C_TEAM contains a static constructor CLASS_CONSTRUCTOR. C_TEAM and C_BIKER both contain instance constructors.
    Implementations
    The implementation parts of the classes contain the implementations of all of the methods declared in the corresponding declaration parts. The interfaces of the methods have already been defined in the declarations. In the implementations, the interface parameters behave like local data.
    Methods of Class C_TEAM
    The following methods are implemented in the section
    CLASS C_TEAM IMPLEMENTATION.
    ENDCLASS.
    CLASS_CONSTRUCTOR
      METHOD CLASS_CONSTRUCTOR.
        TIT1 = 'Team members ?'.
        CALL SELECTION-SCREEN 100 STARTING AT 5 3.
        IF SY-SUBRC NE 0.
          LEAVE PROGRAM.
        ELSE.
          TEAM_MEMBERS = MEMBERS.
        ENDIF.
      ENDMETHOD.
    The static constructor is executed before the class C_TEAM is used for the first time in a program. It calls the selection screen 100 and sets the static attribute TEAM_MEMBERS to the value entered by the program user. This attribute has the same value for all instances of the class C_TEAM.
    CONSTRUCTOR
      METHOD CONSTRUCTOR.
        COUNTER = COUNTER + 1.
        ID = COUNTER.
      ENDMETHOD.
    The instance constructor is executed directly after each instance of the class C_TEAM is created. It is used to count the number of instance of C_TEAM in the static attribute COUNTER, and assigns the corresponding number to the instance attribute ID of each instance of the class.
    CREATE_TEAM
      METHOD CREATE_TEAM.
        DO TEAM_MEMBERS TIMES.
          CREATE OBJECT BIKER EXPORTING TEAM_ID = ID
                                        MEMBERS = TEAM_MEMBERS.
          APPEND BIKER TO BIKER_TAB.
          CALL METHOD BIKER->STATUS_LINE IMPORTING LINE = STATUS_LINE.
          APPEND STATUS_LINE TO STATUS_LIST.
        ENDDO.
      ENDMETHOD.
    The public instance method CREATE_TEAM can be called by any user of the class containing a reference variable with a reference to an instance of the class. It is used to create instances of the class C_BIKER, using the private reference variable BIKER in the class C_TEAM. You must pass both input parameters for the instance constructor of class C_BIKER in the CREATE OBJECT statement. The references to the newly-created instances are inserted into the private internal table BIKER_TAB. After the method has been executed, each line of the internal table contains a reference to an instance of the class C_BIKER. These references are only visible within the class C_TEAM. External users cannot address the objects of class C_BIKER.
    CREATE_TEAM also calls the method STATUS_LINE for each newly-created object, and uses the work area STATUS_LINE to append its output parameter LINE to the private internal table STATUS_LIST.
    SELECTION
      METHOD SELECTION.
        CLEAR BIKER_SELECTION.
        DO.
          READ LINE SY-INDEX.
          IF SY-SUBRC <> 0. EXIT. ENDIF.
          IF SY-LISEL+0(1) = 'X'.
            READ TABLE BIKER_TAB INTO BIKER INDEX SY-INDEX.
            APPEND BIKER TO BIKER_SELECTION.
          ENDIF.
        ENDDO.
        CALL METHOD WRITE_LIST.
      ENDMETHOD.
    The public instance method SELECTION can be called by any user of the class containing a reference variable with a reference to an instance of the class. It selects all of the lines in the current list in which the checkbox in the first column is selected. For these lines, the system copies the corresponding reference variables from the table BIKER_TAB into an additional private internal table BIKER_SELECTION. SELECTION then calls the private method WRITE_LIST, which displays the list.
    EXECUTION
      METHOD EXECUTION.
        CHECK NOT BIKER_SELECTION IS INITIAL.
        LOOP AT BIKER_SELECTION INTO BIKER.
          CALL METHOD BIKER->SELECT_ACTION.
          CALL METHOD BIKER->STATUS_LINE IMPORTING LINE = STATUS_LINE.
          MODIFY TABLE STATUS_LIST FROM STATUS_LINE.
        ENDLOOP.
        CALL METHOD WRITE_LIST.
      ENDMETHOD.
    The public instance method EXECUTION can be called by any user of the class containing a reference variable with a reference to an instance of the class. The method calls the two methods SELECT_ACTION and STATUS_LINE for each instance of the class C_BIKER for which there is a reference in the table BIKER_SELECTION. The line of the table STATUS_LIST with the same key as the component ID in the work area STATUS_LINE is overwritten and displayed by the private method WRITE_LIST.
    WRITE_LIST
      METHOD WRITE_LIST.
        SET TITLEBAR 'TIT'.
        SY-LSIND = 0.
        SKIP TO LINE 1.
        POSITION 1.
        LOOP AT STATUS_LIST INTO STATUS_LINE.
          WRITE: / STATUS_LINE-FLAG AS CHECKBOX,
                   STATUS_LINE-TEXT1,
                   STATUS_LINE-ID,
                   STATUS_LINE-TEXT2,
                   STATUS_LINE-TEXT3,
                   STATUS_LINE-GEAR,
                   STATUS_LINE-TEXT4,
                   STATUS_LINE-SPEED.
        ENDLOOP.
      ENDMETHOD.
    The private instance method WRITE_LIST can only be called from the methods of the class C_TEAM. It is used to display the private internal table STATUS_LIST on the basic list (SY-LSIND = 0) of the program.
    Methods of Class C_BIKER
    The following methods are implemented in the section
    CLASS C_BIKER IMPLEMENTATION.
    ENDCLASS.
    CONSTRUCTOR
      METHOD CONSTRUCTOR.
        COUNTER = COUNTER + 1.
        ID = COUNTER - MEMBERS * ( TEAM_ID - 1).
        CREATE OBJECT BIKE.
      ENDMETHOD.
    The instance constructor is executed directly after each instance of the class C_BIKER is created. It is used to count the number of instance of C_BIKER in the static attribute COUNTER, and assigns the corresponding number to the instance attribute ID of each instance of the class. The constructor has two input parameters - TEAM_ID and MEMBERS - which you must pass in the CREATE OBJECT statement when you create an instance of C_BIKER.
    The instance constructor also creates an instance of the class C_BICYCLE for each new instance of the class C_BIKER. The reference in the private reference variable BIKE of each instance of C_BIKER points to a corresponding instance of the class C_BICYCLE. No external user can address these instances of the class C_BICYCLE.
    SELECT_ACTION
      METHOD SELECT_ACTION.
        DATA ACTIVITY TYPE I.
        TIT2 = 'Select action for BIKE'.
        TIT2+24(3) = ID.
        CALL SELECTION-SCREEN 200 STARTING AT 5 15.
        CHECK NOT SY-SUBRC GT 0.
        IF GEARUP = 'X' OR GEARDOWN = 'X'.
          IF GEARUP = 'X'.
            ACTIVITY = 1.
          ELSEIF GEARDOWN = 'X'.
            ACTIVITY = -1.
          ENDIF.
        ELSEIF DRIVE = 'X'.
          ACTIVITY = 2.
        ELSEIF STOP = 'X'.
          ACTIVITY = 3.
        ENDIF.
        CALL METHOD BIKER_ACTION( ACTIVITY).
      ENDMETHOD.
    The public instance method SELECT_ACTION can be called by any user of the class containing a reference variable with a reference to an instance of the class. The method calls the selection screen 200 and analyzes the user input. After this, it calls the private method BIKER_ACTION of the same class. The method call uses the shortened form to pass the actual parameter ACTIVITY to the formal parameter ACTION.
    BIKER_ACTION
      METHOD BIKER_ACTION.
        CASE ACTION.
          WHEN -1 OR 1.
            CALL METHOD BIKE->CHANGE_GEAR
                              EXPORTING CHANGE = ACTION
                              RECEIVING GEAR = GEAR_STATUS
                              EXCEPTIONS GEAR_MAX = 1
                                         GEAR_MIN = 2.
            CASE SY-SUBRC.
              WHEN 1.
                MESSAGE I315(AT) WITH 'BIKE' ID
                                      ' is already at maximal gear!'.
              WHEN 2.
                MESSAGE I315(AT) WITH 'BIKE' ID
                                      ' is already at minimal gear!'.
            ENDCASE.
          WHEN 2.
            CALL METHOD BIKE->DRIVE IMPORTING VELOCITY = SPEED_STATUS.
          WHEN 3.
            CALL METHOD BIKE->STOP IMPORTING VELOCITY = SPEED_STATUS.
        ENDCASE.
      ENDMETHOD.
    The private instance method BIKER_ACTION can only be called from the methods of the class C_BIKER. The method calls other methods in the instance of the class C_BICYCLE to which the reference in the reference variable BIKE is pointing, depending on the value in the input parameter ACTION.
    STATUS_LINE
      METHOD STATUS_LINE.
        LINE-FLAG = SPACE.
        LINE-TEXT1 = 'Biker'.
        LINE-ID = ID.
        LINE-TEXT2 = 'Status:'.
        LINE-TEXT3 = 'Gear = '.
        LINE-GEAR  = GEAR_STATUS.
        LINE-TEXT4 = 'Speed = '.
        LINE-SPEED = SPEED_STATUS.
      ENDMETHOD.
    The public instance method STATUS_LINE can be called by any user of the class containing a reference variable with a reference to an instance of the class. It fills the structured output parameter LINE with the current attribute values of the corresponding instance.
    Methods of Class C_BICYCLE
    The following methods are implemented in the section
    CLASS C_BICYCLE IMPLEMENTATION.
    ENDCLASS.
    DRIVE
      METHOD DRIVE.
        SPEED = SPEED  + GEAR * 10.
        VELOCITY = SPEED.
      ENDMETHOD.
    The public instance method DRIVE can be called by any user of the class containing a reference variable with a reference to an instance of the class. The method changes the value of the private attribute SPEED and passes it to the caller using the output parameter VELOCITY.
    STOP
      METHOD STOP.
        SPEED = 0.
        VELOCITY = SPEED.
      ENDMETHOD.
    The public instance method STOP can be called by any user of the class containing a reference variable with a reference to an instance of the class. The method changes the value of the private attribute SPEED and passes it to the caller using the output parameter VELOCITY.
    CHANGE_GEAR
      METHOD CHANGE_GEAR.
        GEAR = ME->GEAR.
        GEAR = GEAR + CHANGE.
        IF GEAR GT MAX_GEAR.
          GEAR = MAX_GEAR.
          RAISE GEAR_MAX.
        ELSEIF GEAR LT MIN_GEAR.
          GEAR = MIN_GEAR.
          RAISE GEAR_MIN.
        ENDIF.
        ME->GEAR = GEAR.
      ENDMETHOD.
    The public instance method CHANGE_GEAR can be called by any user of the class containing a reference variable with a reference to an instance of the class. The method changes the value of the private attribute GEAR. Since the formal parameter with the same name obscures the attribute in the method, the attribute has to be addressed using the self-reference ME->GEAR.
    Using the Classes in a Program
    The following program shows how the above classes can be used in a program. The declarations of the selection screens and local classes, and the implementations of the methods must also be a part of the program.
    REPORT OO_METHODS_DEMO NO STANDARD PAGE HEADING.
    Declarations and Implementations
    Global Program Data
    TYPES TEAM TYPE REF TO C_TEAM.
    DATA: TEAM_BLUE  TYPE TEAM,
          TEAM_GREEN TYPE TEAM,
          TEAM_RED   TYPE TEAM.
    DATA  COLOR(5).
    Program events
    START-OF-SELECTION.
      CREATE OBJECT: TEAM_BLUE,
                     TEAM_GREEN,
                     TEAM_RED.
       CALL METHOD: TEAM_BLUE->CREATE_TEAM,
                   TEAM_GREEN->CREATE_TEAM,
                   TEAM_RED->CREATE_TEAM.
      SET PF-STATUS 'TEAMLIST'.
      WRITE '                   Select a team!             ' COLOR = 2.
    AT USER-COMMAND.
      CASE SY-UCOMM.
        WHEN 'TEAM_BLUE'.
          COLOR = 'BLUE '.
          FORMAT COLOR = 1 INTENSIFIED ON INVERSE ON.
           CALL METHOD TEAM_BLUE->SELECTION.
        WHEN 'TEAM_GREEN'.
          COLOR = 'GREEN'.
          FORMAT COLOR = 5 INTENSIFIED ON INVERSE ON.
           CALL METHOD TEAM_GREEN->SELECTION.
        WHEN 'TEAM_RED'.
          COLOR = 'RED '.
          FORMAT COLOR = 6 INTENSIFIED ON INVERSE ON.
           CALL METHOD TEAM_RED->SELECTION.
        WHEN 'EXECUTION'.
          CASE COLOR.
            WHEN 'BLUE '.
              FORMAT COLOR = 1 INTENSIFIED ON INVERSE ON.
               CALL METHOD TEAM_BLUE->SELECTION.
              CALL METHOD TEAM_BLUE->EXECUTION.
            WHEN 'GREEN'.
              FORMAT COLOR = 5 INTENSIFIED ON INVERSE ON.
               CALL METHOD TEAM_GREEN->SELECTION.
              CALL METHOD TEAM_GREEN->EXECUTION.
            WHEN 'RED '.
              FORMAT COLOR = 6 INTENSIFIED ON INVERSE ON.
               CALL METHOD TEAM_RED->SELECTION.
              CALL METHOD TEAM_RED->EXECUTION.
          ENDCASE.
      ENDCASE.
    The program contains three class reference variables that refer to the class C_TEAM. It creates three objects from the class, to which the references in the reference variables then point. In each object, it calls the method CREATE_TEAM. The method CLASS_CONSTRUCTOR of class C_TEAM is executed before the first of the objects is created. The status TEAMLIST for the basic list allows the user to choose one of four functions:
    When the user chooses a function, the event AT USER-COMMAND is triggered and public methods are called in one of the three instances of C_TEAM, depending on the user’s choice. The user can change the state of an object by selecting the corresponding line in the status list.

  • Abap Objects doubts.

    Hi Experts.
    Plz give me some details for the following questions.
    1. what is abstract class.
    2. give me some example program using inheritance.
    3. Some sample programs using events.
    4. Narrow casting & wide casting.. And describe the use of it.
    5. How to declare internal table in ABAP OOPS.
    6. What is the use of table type.?
    7. What is instance.?
    8. Explain friend class.
    Thank in advance.
    Points will be given for the answers.
    regards,
    J.Joe

    HI
    <b>1. what is abstract class.</b>
    Abstract classes are normally used as an incomplete blueprint for concrete (that is, non-abstract) subclasses, for example to define a uniform interface.
    Classes with at least one abstract method are themselves abstract.
    Static methods and constructors cannot be abstract.
    You can specify the class of the instance to be created explicitly: CREATE OBJECT <RefToAbstractClass> TYPE <NonAbstractSubclassName>.
    Abstarct classes themselves can’t be instantiated ( althrough their subclasses can)
    Reference to abstract classes can refer to instance of subclass
    Abstract (instance) methods are difined in the class , but not implemented
    They must be redefined in subclasses
    CLASS LC1 DEFINAITION ABSTARCT
    PUBLIC SECTION
    METHODS ESTIMATE ABSTARCT IMPORTING…
    ENDCLASS.
    <b>2. give me some example program using inheritance.</b>
    The following simple example shows the principle of inheritance within ABAP Objects. It is based on the Simple Introduction to Classes. A new class counter_ten inherits from the existing class counter.
    REPORT demo_inheritance.
    CLASS counter DEFINITION.
      PUBLIC SECTION.
        METHODS: set IMPORTING value(set_value) TYPE i,
                 increment,
                 get EXPORTING value(get_value) TYPE i.
       PROTECTED SECTION .
        DATA count TYPE i.
    ENDCLASS.
    CLASS counter IMPLEMENTATION.
      METHOD set.
        count = set_value.
      ENDMETHOD.
      METHOD increment.
        ADD 1 TO count.
      ENDMETHOD.
      METHOD get.
        get_value = count.
      ENDMETHOD.
    ENDCLASS.
    CLASS counter_ten DEFINITION INHERITING FROM counter.
      PUBLIC SECTION.
        METHODS increment REDEFINITION .
        DATA count_ten.
    ENDCLASS.
    CLASS counter_ten IMPLEMENTATION.
      METHOD increment.
        DATA modulo TYPE I.
         CALL METHOD super->increment .
        write / count.
        modulo = count mod 10.
        IF modulo = 0.
          count_ten = count_ten + 1.
          write count_ten.
        ENDIF.
      ENDMETHOD.
    ENDCLASS.
    DATA: count TYPE REF TO counter,
          number TYPE i VALUE 5.
    START-OF-SELECTION.
       CREATE OBJECT count TYPE counter_ten .
      CALL METHOD count->set EXPORTING set_value = number.
      DO 20 TIMES.
        CALL METHOD count->increment.
      ENDDO.
    The class COUNTER_TEN is derived from COUNTER. It redefines the method INCREMENT. To do this, you must change the visibility of the COUNT attribute from PRIVATE to PROTECTED. The redefined method calls the obscured method of the superclass using the pseudoreference SUPER->. The redefined method is a specialization of the inherited method.
    The example instantiates the subclass. The reference variable pointing to it has the type of the superclass. When the INCREMENT method is called using the superclass reference, the system executes the redefined method from the subclass.
    <b>3. Some sample programs using events.</b>
    Events in ABAP Objects - Example
    The following example shows how to declare, call, and handle events in ABAP Objects.
    Overview
    This object works with the interactive list displayed below. Each user interaction triggers an event in ABAP Objects. The list and its data is created in the class C_LIST. There is a class STATUS for processing user actions. It triggers an event BUTTON_CLICKED in the AT USER-COMMAND event. The event is handled in the class C_LIST. It contains an object of the class C_SHIP or C_TRUCK for each line of the list. Both of these classes implement the interface I_VEHICLE. Whenever the speed of one of these objects changes, the event SPEED_CHANGE is triggered. The class C_LIST reacts to this and updates the list.
    Constraints
    The ABAP statements used for list processing are not yet fully available in ABAP Objects. However, to produce a simple test output, you can use the following statements:
    WRITE [AT] /<offset>(<length>) <f>
    ULINE
    SKIP
    NEW-LINE
    Note: The behavior of formatting and interactive list functions in their current state are not guaranteed. Incompatible changes could occur in a future release.
    Declarations
    This example is implemented using local interfaces and classes. Below are the declarations of the interfaces and classes:
    Interface and Class declarations
    INTERFACE I_VEHICLE.
      DATA     MAX_SPEED TYPE I.
      EVENTS SPEED_CHANGE EXPORTING VALUE(NEW_SPEED) TYPE I.
      METHODS: DRIVE,
               STOP.
    ENDINTERFACE.
    CLASS C_SHIP DEFINITION.
      PUBLIC SECTION.
      METHODS CONSTRUCTOR.
      INTERFACES I_VEHICLE.
      PRIVATE SECTION.
      ALIASES MAX FOR I_VEHICLE~MAX_SPEED.
      DATA SHIP_SPEED TYPE I.
    ENDCLASS.
    CLASS C_TRUCK DEFINITION.
      PUBLIC SECTION.
      METHODS CONSTRUCTOR.
      INTERFACES I_VEHICLE.
      PRIVATE SECTION.
      ALIASES MAX FOR I_VEHICLE~MAX_SPEED.
      DATA TRUCK_SPEED TYPE I.
    ENDCLASS.
    CLASS STATUS DEFINITION.
      PUBLIC SECTION.
       CLASS-EVENTS BUTTON_CLICKED EXPORTING VALUE(FCODE) LIKE SY-UCOMM.
      CLASS-METHODS: CLASS_CONSTRUCTOR,
                    USER_ACTION.
    ENDCLASS.
    CLASS C_LIST DEFINITION.
      PUBLIC SECTION.
      METHODS: FCODE_HANDLER FOR EVENT BUTTON_CLICKED OF STATUS
                                 IMPORTING FCODE,
               LIST_CHANGE   FOR EVENT SPEED_CHANGE OF I_VEHICLE
                                 IMPORTING NEW_SPEED,
               LIST_OUTPUT.
      PRIVATE SECTION.
      DATA: ID TYPE I,
            REF_SHIP  TYPE REF TO C_SHIP,
            REF_TRUCK TYPE REF TO C_TRUCK,
            BEGIN OF LINE,
              ID TYPE I,
              FLAG,
              IREF  TYPE REF TO I_VEHICLE,
              SPEED TYPE I,
            END OF LINE,
            LIST LIKE SORTED TABLE OF LINE WITH UNIQUE KEY ID.
    ENDCLASS.
    The following events are declared in the example:
    The instance event SPEED_CHANGE in the interface I_VEHICLE
    The static event BUTTON_CLICKED in the class STATUS.
    The class C_LIST contains event handler methods for both events.
    Note that the class STATUS does not have any attributes, and therefore only works with static methods and events.
    Implementations
    Below are the implementations of the methods of the above classes:
    Implementations
    CLASS C_SHIP IMPLEMENTATION.
      METHOD CONSTRUCTOR.
        MAX = 30.
      ENDMETHOD.
      METHOD I_VEHICLE~DRIVE.
        CHECK SHIP_SPEED < MAX.
        SHIP_SPEED = SHIP_SPEED + 10.
        RAISE EVENT I_VEHICLE~SPEED_CHANGE
                    EXPORTING NEW_SPEED = SHIP_SPEED.
      ENDMETHOD.
      METHOD I_VEHICLE~STOP.
        CHECK SHIP_SPEED > 0.
        SHIP_SPEED = 0.
        RAISE EVENT I_VEHICLE~SPEED_CHANGE
                    EXPORTING NEW_SPEED = SHIP_SPEED.
      ENDMETHOD.
    ENDCLASS.
    CLASS C_TRUCK IMPLEMENTATION.
      METHOD CONSTRUCTOR.
        MAX = 150.
      ENDMETHOD.
      METHOD I_VEHICLE~DRIVE.
        CHECK TRUCK_SPEED < MAX.
        TRUCK_SPEED = TRUCK_SPEED + 50.
        RAISE EVENT I_VEHICLE~SPEED_CHANGE
                    EXPORTING NEW_SPEED = TRUCK_SPEED.
      ENDMETHOD.
      METHOD I_VEHICLE~STOP.
        CHECK TRUCK_SPEED > 0.
        TRUCK_SPEED = 0.
        RAISE EVENT I_VEHICLE~SPEED_CHANGE
                    EXPORTING NEW_SPEED = TRUCK_SPEED.
      ENDMETHOD.
    ENDCLASS.
    CLASS STATUS IMPLEMENTATION.
      METHOD CLASS_CONSTRUCTOR.
        SET PF-STATUS 'VEHICLE'.
        WRITE 'Click a button!'.
      ENDMETHOD.
      METHOD USER_ACTION.
        RAISE EVENT BUTTON_CLICKED EXPORTING FCODE = SY-UCOMM.
      ENDMETHOD.
    ENDCLASS.
    CLASS C_LIST IMPLEMENTATION.
      METHOD FCODE_HANDLER .
        CLEAR LINE.
        CASE FCODE.
          WHEN 'CREA_SHIP'.
            ID = ID + 1.
            CREATE OBJECT REF_SHIP.
            LINE-ID = ID.
            LINE-FLAG = 'C'.
            LINE-IREF = REF_SHIP.
            APPEND LINE TO LIST.
          WHEN 'CREA_TRUCK'.
            ID = ID + 1.
            CREATE OBJECT REF_TRUCK.
            LINE-ID = ID.
            LINE-FLAG = 'T'.
            LINE-IREF = REF_TRUCK.
            APPEND LINE TO LIST.
          WHEN 'DRIVE'.
            CHECK SY-LILLI > 0.
            READ TABLE LIST INDEX SY-LILLI INTO LINE.
            CALL METHOD LINE-IREF->DRIVE.
          WHEN 'STOP'.
            LOOP AT LIST INTO LINE.
              CALL METHOD LINE-IREF->STOP.
            ENDLOOP.
          WHEN 'CANCEL'.
            LEAVE PROGRAM.
        ENDCASE.
        CALL METHOD LIST_OUTPUT.
      ENDMETHOD.
      METHOD LIST_CHANGE .
        LINE-SPEED = NEW_SPEED.
        MODIFY TABLE LIST FROM LINE.
      ENDMETHOD.
      METHOD LIST_OUTPUT.
        SY-LSIND = 0.
        SET TITLEBAR 'TIT'.
        LOOP AT LIST INTO LINE.
          IF LINE-FLAG = 'C'.
            WRITE / ICON_WS_SHIP AS ICON.
          ELSEIF LINE-FLAG = 'T'.
            WRITE / ICON_WS_TRUCK AS ICON.
          ENDIF.
          WRITE: 'Speed = ', LINE-SPEED.
        ENDLOOP.
      ENDMETHOD.
    ENDCLASS.
    The static method USER_ACTION of the class STATUS triggers the static event BUTTON_CLICKED. The instance methods I_VEHICLEDRIVE and I_VEHICLESTOP trigger the instance event I_VEHICLE~SPEED_CHANGE in the classes C_SHIP and C_TRUCK.
    Using the Classes in a Program
    The following program uses the above classes:
    REPORT OO_EVENTS_DEMO NO STANDARD PAGE HEADING.
    Global data of program
    DATA LIST TYPE REF TO C_LIST.
    Program events
    START-OF-SELECTION.
      CREATE OBJECT LIST.
      SET HANDLER: LIST->FCODE_HANDLER,
                  LIST->LIST_CHANGE FOR ALL INSTANCES.
    AT USER-COMMAND.
      CALL METHOD STATUS=>USER_ACTION.
    The program creates an object of the class C_LIST and registers the event handler method FCODE_HANDLER of the object for the class event BUTTON_CLICKED, and the event handler method LIST_CHANGE for the event SPEED_CHANGE of all instances that implement the interface I_VEHICLE.
    <b>4. Narrow casting & wide casting.. And describe the use of it.</b>
    <b>Narrowing Cast</b>
    The assignment of a subclass instance to a reference variable of the type "reference to superclass" is described as a narrowing cast, because you are switching from a more detailed view to a one with less detail.
    Description up-cast is also used.
    <b>use</b>
    A user who is not interested in the finer points of cars, trucks, and busses (but only, for example, in the fuel consumption and tank gauge) does not need to know about them. This user only wants and needs to work with (references to) the lcl_vehicle class. However, in order to allow the user to work with cars, busses, or trucks, you generally need a narrowing cast.
    <b>Widening cast</b>
    The widening cast logically represents the opposite of the narrowing cast. The widening cast cannot be checked statically, only at runtime. The Cast Operator ?= (or the equivalent MOVE ... ?TO … ) must be used to make this visible.
    It changes from a less detailed view to one with more detail.
    <b>use</b>
    The client, the car rental company  wants to execute a function for specific vehicles form the list (vehicle_list).  For example, the client wants to ascertain the truck with the largest cargo capacity.  However, not all vehicles are in the trucks list, it also includes references to cars and busses.
    <b>5. How to declare internal table in ABAP OOPS.</b>
    BEGIN OF LINE,
              ID TYPE I,
              FLAG,
              IREF  TYPE REF TO I_VEHICLE,
              SPEED TYPE I,
            END OF LINE,
    <b>6. What is the use of table type.?</b>
    Please check the SAP help , as all these things are provided in detail in it .
    In case you find it difficult to find it or search for it here is the link
    http://help.sap.com/saphelp_nw04/helpdata/en/90/8d7304b1af11d194f600a0c929b3c3/frameset.htm
    <b>7. What is instance.?</b>
    Instance methods are called using CALL METHOD <reference>-><instance_method>.
    Static methods (also referred to as class methods) are called using CALL METHOD <classname>=><class_method>.
    If you are calling a static method from within the class, you can omit the class name.
    You access instance attributes using <instance>-><instance_attribute>
    <b>8. Explain friend class.</b>
    In rare cases, classes have to work together so closely that they need access to their protected and private components. To avoid making these components available to all users, there is the concept of friendship between classes.
    To do this you use the FRIENDS additions to the CLASS statement, in which all classes and interfaces that are to be provided friendship are listed
    In principle, providing friendship is one-sided: A class providing friendship is not automatically a friend of its friends. If a class providing friendship wants to access the non-public components of a friend, this friend has to explicitly provide friendship to it.
    Classes that inherit from friends and interfaces that contain a friend as a component interface also become friends. However, providing friendship, unlike the attribute of being a friend, is not inherited. A friend of a superclass is therefore not automatically a friend of its subclasses.
    <b>Reward if usefull</b>

  • ABAP Objects and Web Dynpro

    Hello everyone,
    I would like to know if it is possible to have instances of a class as a part of a controller context. You know, like if you added a service call to a BAPI or a function group, but with method calls to an object instead.
    I have a feeling, that it is uncommon to bring Web Dynpro and the object orientation of ABAP Objects together.
    For example, i don't want the event handling code of my controllers to call function groups, which in turn make calls to my object oriented model. Is there a way to skip that nasty imperative step?
    Sorry for asking questions which may sound vague or naive, I'm kind of a beginner regarding Web Dynpro and ABAP.
    cheers,
    Jens Barthel

    There's no need at all to have function modules in the way.
    You can have either controller attributes or context attributes defined as object references, and then call methods from those objects instead...
    In both cases, you just have to use TYPE REF TO instead of TYPE when defining the attributes.
    Furthermore, if you have a central class through which you interact with your OO model, you can define it as Assistance class and then you'll have an instance automatically in all the controllers...the drawback / advantage is that you do not control its instantiation which is done by the framework.
    Regards
    Edited by: Alejandro Bindi on Oct 14, 2008 6:23 PM

  • How to detect modifications in an ABAP Object?

    Hi all,
    I was wondering if there's a simple way of detecting modifications in an ABAP Object.
    Imagine an ABAP entity object which holds several attributes and you need to know if this object has been modified. Instead of having to check attribute by attribute to compare it's previous value with the new one I came with the idea of calculating a HASH code for the object before the execution of the application which can change the object attributes and comparing it with the HASH calculated for the same object after the execution.
    That way, checking only two hashes simplifies a lot the code. So.... is there any way of calculating a HASH for any object instance? if not... any other approach?
    Thanks in advance.

    Sorry Hüseyin Dereli, but I'm not talking about source version control, but how to detect attribute modifications of an ABAP Object Instance.
    for example, suppose you have a program which reads data from DataBase and stores temporally that data into an ABAP Object like this:
    ABAP Object AAAA{
       private attr1
       private attr2
    and passes this ABAP Object into a screen for user interaction, or even a FunctionModule or Method or anything else...
    data: myObject type ref to AAAA.
    myObject-attr1 = 1
    myObject-attr2 = 2.
    CallFunction AnyFunction Changing data = myObject
    After the execution of AnyFunction I would like to know if myObject has been changed but I'm trying not to check attribute by attribute because if myObject has a lot of attributes (not in this example but in the real source code)
    It would be great if we could do something like this:
    data: myObject type ref to AAAA,
              oldHash type hash,
               newHash type hash.
    myObject-attr1 = 1
    myObject-attr2 = 2.
    oldHash = myObject->get_hash()
    CallFunction AnyFunction Changing data = myObject
    newHash = myObject->get_hash()
    if oldHash NE newHash.
    * MyObject has been modified
    endif.

Maybe you are looking for