Abap Class - Friend

Hello Forum,
What is the 'Friend' defined in a Class?
What is its role and how is it used together with Methods?
Any easy to understand materials on Abap class would be greatly appreciated.
Thanks!
Best regards,
S.Patel

Hi
Classes
LIKE-Zusatz
Classes are templates for objects. Conversely, you can say that the type of an object is the same as its class. A class is an abstract description of an object. You could say that it is a set of instructions for building an object. The attributes of objects are defined by the components of the class, which describe the state and behavior of objects.
Local and Global Classes
Classes in ABAP Objects can be declared either globally or locally. You define global classes and interfaces in the Class Builder (Transaction SE24) in the ABAP Workbench. They are stored centrally in class pools in the class library in the R/3 Repository. All of the ABAP programs in an R/3 System can access the global classes. Local classes are defined within an ABAP program. Local classes and interfaces can only be used in the program in which they are defined. When you use a class in an ABAP program, the system first searches for a local class with the specified name. If it does not find one, it then looks for a global class. Apart from the visibility question, there is no difference between using a global class and using a local class.
There is, however, a significant difference in the way that local and global classes are designed. If you are defining a local class that is only used in a single program, it is usually sufficient to define the outwardly visible components so that it fits into that program. Global classes, on the other hand, must be able to be used anywhere. This means that certain restrictions apply when you define the interface of a global class, since the system must be able to guarantee that any program using an object of a global class can recognize the data type of each interface parameter.
The following sections describe how to define local classes and interfaces in an ABAP program. For information about how to define local classes and interfaces, refer to the  Class Builder section of the ABAP Workbench Tools documentation.
Defining Local Classes
Local classes consist of ABAP source code, enclosed in the ABAP statements CLASS ... ENDCLASS. A complete class definition consists of a declaration part and, if required, an implementation part. The declaration part of a class <class> is a statement block:
CLASS <class> DEFINITION.
ENDCLASS.
It contains the declaration for all components (attributes, methods, events) of the class. When you define local classes, the declaration part belongs to the global program data. You should therefore place it at the beginning of the program.
If you declare methods in the declaration part of a class, you must also write an implementation part for it. This consists of a further statement block:
CLASS <class> IMPLEMENTATION.
ENDCLASS.
The implementation part of a class contains the implementation of all methods of the class. The implementation part of a local class is a processing block. Subsequent coding that is not itself part of a processing block is therefore not accessible.
Structure of a Class
The following statements define the structure of a class:
A class contains components
Each component is assigned to a visibility section
Classes implement methods
The following sections describe the structure of classes in more detail.
Class Components
The components of a class make up its contents. All components are declared in the declaration part of the class. The components define the attributes of the objects in a class. When you define the class, each component is assigned to one of the three visibility sections, which define the external interface of the class. All of the components of a class are visible within the class. All components are in the same namespace. This means that all components of the class must have names that are unique within the class.
There are two kinds of components in a class - those that exist separately for each object in the class, and those that exist only once for the whole class, regardless of the number of instances. Instance-specific components are known as instance components. Components that are not instance-specific are called static components.
In ABAP Objects, classes can define the following components. Since all components that you can declare in classes can also be declared in interfaces, the following descriptions apply equally to interfaces.
Attributes
Attributes are internal data fields within a class that can have any ABAP data type. The state of an object is determined by the contents of its attributes. One kind of attribute is the reference variable. Reference variables allow you to create and address objects. Reference variables can be defined in classes, allowing you to access objects from within a class.
Instance Attributes
The contents of instance attributes define the instance-specific state of an object. You declare them using the DATA statement.
Static Attributes
The contents of static attributes define the state of the class that is valid for all instances of the class. Static attributes exist once for each class. You declare them using the CLASS-DATA statement. They are accessible for the entire runtime of the class.
All of the objects in a class can access its static attributes. If you change a static attribute in an object, the change is visible in all other objects in the class.
Methods
Methods are internal procedures in a class that define the behavior of an object. They can access all of the attributes of a class. This allows them to change the data content of an object. They also have a parameter interface, with which users can supply them with values when calling them, and receive values back from them The private attributes of a class can only be changed by methods in the same class.
The definition and parameter interface of a method is similar to that of function modules. You define a method <met> in the definition part of a class and implement it in the implementation part using the following processing block:
METHOD <meth>.
ENDMETHOD.
You can declare local data types and objects in methods in the same way as in other ABAP procedures (subroutines and function modules). You call methods using the CALL METHOD statement.
Instance Methods
You declare instance methods using the METHODS statement. They can access all of the attributes of a class, and can trigger all of the events of the class.
Static Methods
You declare static methods using the CLASS-METHODS statement. They can only access static attributes and trigger static events.
Special Methods
As well as normal methods, which you call using CALL METHOD, there are two special methods called CONSTRUCTOR and CLASS_CONSTRUCTOR, which are automatically called when you create an object (CONSTRUCTOR) or when you first access the components of a class (CLASS_CONSTRUCTOR).
Events
Objects or classes can use events to trigger event handler methods in other objects or classes. In a normal method call, one method can be called by any number of users. When an event is triggered, any number of event handler methods can be called. The link between the trigger and the handler is not established until runtime. In a normal method call, the calling program determines the methods that it wants to call. These methods must exist. With events, the handler determines the events to which it wants to react. There does not have to be a handler method registered for every event.
The events of a class can be triggered in the methods of the same class using the RAISE EVENT statement. You can declare a method of the same or a different class as an event handler method for the event <evt> of class <class> using the addition FOR EVENT <evt> OF <class>.
Events have a similar parameter interface to methods, but only have output parameters. These parameters are passed by the trigger (RAISE EVENT statement) to the event handler method, which receives them as input parameters.
The link between trigger and handler is established dynamically in a program using the SET HANDLER statement. The trigger and handlers can be objects or classes, depending on whether you have instance or static events and event handler methods. When an event is triggered, the corresponding event handler methods are executed in all registered handling classes.
Instance Events
You declare instance events using the EVENTS statement. An instance event can only be triggered in an instance method.
Static Events
You declare static events using the CLASS-EVENTS statement. All methods (instance and static methods) can trigger static events. Static events are the only type of event that can be triggered in a static method.
See also Triggering and Handling Events.
Types
You can define your own ABAP data types within a class using the TYPES statement. Types are not instance-specific, and exist once only for all of the objects in a class.
Constants
Constants are special static attributes. You set their values when you declare them, and they can then no longer be changed. You declare them using the CONSTANTS statement. Constants are not instance-specific, and exist once only for all of the objects in a class.
Visibility Sections
You can divide the declaration part of a class into up to three visibility areas:
CLASS <class> DEFINITION.
  PUBLIC SECTION.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.
These areas define the external visibility of the class components, that is, the interface between the class and its users. Each component of a class must be assigned to one of the visibility sections.
Public Section
All of the components declared in the public section are accessible to all users of the class, and to the methods of the class and any classes that inherit from it. The public components of the class form the interface between the class and its users.
Protected Section
All of the components declared in the protected section are accessible to all methods of the class and of classes that inherit from it. Protected components form a special interface between a class and its subclasses. Since inheritance is not active in Release 4.5B, the protected section currently has the same effect as the private section.
Private Section
Components that you declare in the private section are only visible in the methods of the same class. The private components are not part of the external interface of the class.
Encapsulation
The three visibility areas are the basis for one of the important features of object orientation - encapsulation. When you define a class, you should take great care in designing the public components, and try to declare as few public components as possible. The public components of global classes may not be changed once you have released the class.
For example, public attributes are visible externally, and form a part of the interface between an object and its users. If you want to encapsulate the state of an object fully, you cannot declare any public attributes. As well as defining the visibility of an attribute, you can also protect it from changes using the READ-ONLY addition.
Refer the following link
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5c54f411d194a60000e8353423/frameset.htm

Similar Messages

  • File to Proxy Scenario using ABAP Class and DB Multi Connect

    Hello Friends,
    I have a scenario below and a proposed solution. I would like some input as to whether i am headed the right way.
    Scenario: Thousands of records come in from the legacy accounting system. The fields of these records need to be mapped to SAP fields using cross-reference tables stored in DB2. Finally, summarize the records by deleting a few fields and feed to R/3.
    Solution i proposed:
    (1) File Adapter is used to send the file
    (2) Although JDBC adapter comes first to mind but since i need to access the DB2 tables multiple times for each record i propose to use an ABAP class for the mapping. Within the ABAP class the intent is to open an database connection to DB2, read the relevant cross tables using native SQL and finally generate the output XML.
    (3) Reciever is Proxy which feeds this generated XML to SAP for creating posting via BAPI_ACC_DOCUMENT_POST
    Question: Is the above solution correct or is there a better method to implement this scenario?
    Please let me know.
    Thanks,
    Minhaj.

    Looks fine. Few observations -
    1. Whether it is ABAP class or Mapping in RFC lookup, you are making multiple trips to the database.
    2. It looks like PI is being used only for reading the file and converting it to XML.
    3. If using PI is not mandatory, then a complete ABAP class on ECC it self would be faster than swtching between PI Java, PI ABAP then round trips to DB2 finally data push to ECC.
    If you could look at something like fetching all the required RFC look up data in one go and then map the fields according, might save u on processor and network resources.
    VJ

  • BAPI diff Method in ABAP class

    Dear friends
    Coul any1 tel me hw BAPI differed frm a method whic used in an ABAP class , BAPI is also a method of a BOR.
    And is it possible to replace a BAPI using a method of an ABAP class..
    cheers
    sakthi

    Hello Sakthi
    The concept of BOR methods is purely semantic and has nothing to do with ABAP-OO.
    The so-called method of business objects are implemented by BAPIs.
    The cannot be replaced by ABAP class methods. In particular, BAPIs are RFC-enabled whereas class methods cannot (yet) be called remotely.
    Regards,
       Uwe

  • ABAP class mapping in PI (7.0)

    I just switched from XI (3.0) to PI (7.0).
    I tried to move one of my interfaces, but in Interface Mapping there is no "ABAP-class" option. How to use ABAP mapping in PI?

    Hi Mariuszu
    you need to enable it as described here
    in the exchange profile
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/e3ead790-0201-0010-64bb-9e4d67a466b4
    or you can ask us directly via mail
    Regards,
    michal

  • Shooping cart creation in SRM 7.0 using web dynpro ABAP classes.

    Hi,
    We have recently upgraded to SRM 7.0 from SRM 4.0. We are using customized portal application for the creation of the shopping cart.I am planning to create custom FM which will use the standard Web dynpro ABAP classes to create the shopping cart.
    Could you please guide with the classes that are need to be implemented and the sequence of the classes used in the shopping cart creation.
    I think these are the classes that are used in the standard web dynpro ABAP component.
    CL_FPM_EVENT ->                  Creates an instance of this class based on an event ID.
    CL_BADI_FLT_DATA_TRANS_AND_DB -> Data Handling: Transport and Database.
    CL_EXITHANDLER ->               Class for Ext. Services Within Framework of Exit Technique.
    CL_EX_BBP_DOC_CHANGE_BADI ->     BAdI Class CL_EX_BBP_DOC_CHANGE_BADI.
    CL_BBP_OBJECTS_ACCESS ->         Access Functions for Object Types.
    /SAPSRM/CL_PDO_BO_SC ->          Shopping Cart BO.
    Your expert comments will be appreciated...
    Regards,
    Naresh

    Dear Poster,
    As no response has been provided to the thread in some time I must assume the issue is resolved, if the question is still valid please create a new thread rephrasing the query and providing as much data as possible to promote response from the community.
    Best Regards,
    SDN SRM Moderation Team

  • ABAP Class not displaying in operation mapping.

    HI,
    I have created abap class using se24 for throwing exception message in sxmb_moni, this abap class needs to be called in operation mapping, even though i have activated this abap class in PI environtment, i couldnt see the abap class option in the operation mapping.
    Could any one please let me know any change profiles requirements are required,
    Thanks,
    --Sai

    Hi Sai,
    Yes, you do have to register ABAP Class Mapping in the Exchange Profile to see this option in the Operation Mapping. Follow these step-by-step configuration guidelines:
    http://www.riyaz.net/sap/xipi-how-to-register-abap-mapping-in-exchange-profile/624/
    Hope this helps,
    Greg

  • Calling Portal event from ABAP class

    Hi Experts,
    I need a following clarificatrion, Please help,
    1. Is it possible to call a webdynpro method from a normal ABAP class?
    2. If no, we need a functionality of a class 'CL_WDR_HTTP_EXT_MIME_HANDLER' having method 'DO_DOMAIN_RELAX_HTML'.
    Is there any alternative method which can be used in ABAP having the same functionality.
    3. Is there any ways with which we can call portal event from ABAP class?
    Thanks,
    Shabir

    >1. Is it possible to call a webdynpro method from a normal ABAP class?
    I wouldn't necessarily recommend this approach. You shouldn't try to trigger events or any of the standard WDDO* methods from outside the WD Component itself.  That said, you can pass the object reference (like the WD_COMP_CONTROLLER object reference or the View Object Reference) into methods of normal classes.  Be careful if you are finding yourself calling a lot of your added methods from outside WD.  This is probably a sign that these methods should be in the Assistance Class or some other Class functioning as a Model Object.
    >2. If no, we need a functionality of a class 'CL_WDR_HTTP_EXT_MIME_HANDLER' having method 'DO_DOMAIN_RELAX_HTML'.
    Is there any alternative method which can be used in ABAP having the same functionality.
    What exactly do you want to do here?  Do you just want to get the relaxation script?  For what purpose?  You should never need to inject the relaxation script into WDA. 
    >3. Is there any ways with which we can call portal event from ABAP class?
    To what purpose.  Do you just want to delegate the triggering of the event that is inside WD Component to be called from a class?  If so you can pass the portal API object reference into a class from the WD Component.  However this only works while running within WD.
    How is this class used?  Are you running in WD?  Are you trying to generate some HTML code that runs in the portal independent of WD?

  • TYPES statement in abap class to include structure

    hi ,
    i have declared following in a abap class...
    TYPES:
          zts_alv_line TYPE zmat_pr_costest_alv.
         TYPES:BEGIN OF ts_alv_line,
                include type zts_alv_line,
                matkl type mara-matkl,
                t023t type t023t-wgbez,
                lvorm type mara-lvorm,
                end of ts_alv_line.
         TYPES: tt_alv_data TYPE STANDARD TABLE OF ts_alv_line WITH DEFAULT KEY.
         DATA:
          alv_data TYPE tt_alv_data.
    now while refering to alv_data-matnr the sap is giving error that this component does not have matnr.
    please help.
    Edited by: Suhas Saha on Feb 3, 2012 1:11 PM

    TYPES: zts_alv_line TYPE zmat_pr_costest_alv.
    TYPES:BEGIN OF ts_alv_line,
                include type zts_alv_line,
                matkl type mara-matkl,
                t023t type t023t-wgbez,
                lvorm type mara-lvorm,
                end of ts_alv_line.
    Actually by defining this you've defined include as field of ts_alv_line. Actually ts_alv_line is a nested structure.
    I think you need to re-define the structure definition as:
    TYPES:BEGIN OF ts_alv_line.
          INCLUDE TYPE zts_alv_line.
    TYPES: matkl TYPE mara-matkl,
           t023t TYPE t023t-wgbez,
           lvorm TYPE mara-lvorm.
    TYPES: END OF ts_alv_line.
    BR,
    Suhas

  • Error handling in Abap Class for SAP Workflow

    Hi Experts,
    I would like to know if we have an option in abap classes used in workflows to send errors to the workflow log. We can achieve this in BOR Object methods by using the EXIT_RETURN <CODE> var 1 var 2 to send the errors back to the workflow, but how is this achieved through methods from classes  used in workflows.
    Appreciate your quick responses,
    Chaitanya

    Just raise exceptions in the normal OO way. Any exception that is a subclass of CX_BO_ERROR should be automatically available in workflow. Use subclasses of CX_BO_TEMPORARY for temporary errors.

  • How to Handle Business Object event in ABAP class

    Hello Everybody,
    I wanted to know if it was possible to reference BOR objects in ABAP class and handle BOR events in ABAP Objects.
    Thanks in advance.

    Hi,
    Catch the et_VALIDATE event, when InnerEvent = False and ItemChanged = True.
                If pVal.EventType = BoEventTypes.et_VALIDATE Then
                    If pVal.InnerEvent = False And pVal.ItemChanged Then
                        'TODO Your code here...
                    End If
                End If
    Regards,
    Vítor Vieira

  • In Abap Class, Rage declaration

    Hi,
    How to declare field range in Abap Class and select statement of inner join
    Thanks and Regards,
    Prabhakar Dharmala

    Try this way
    class lcl_range definition.
      public section.
        types:
          t_matnr  type range of dmatnr.
        class-methods:
          r_matnr  importing v_matnr  type t_matnr,
    endclass.

  • ABAP CLASSES - XI don't create the Target File..

    Hallo,
    I have a problema in XI when I use an ABAP Class.
    This is My FLOW:
    1) R/3 SEND an IDOC DEBMAS to XI un idoc DEBMAS(Customer data)
    2) XI have this Interface Mapping: Interface_Mapping_Anagrafica_Cliente.
    It si composed on:
    - Input: IDOC (DEBMAS)
    - 1° Mapping      ==> named: Message_Mapping_Anagrafica_Cliente
       This mapping, from IDOC DEBMAS, create the message type Message_Type_Anagrafica_Cliente.
    - 2° Mapping      ==> Classe ABAP
       This mapping, from Message_Type_Anagrafica_Cliente create the message type Message_Type_Click.
    - Output: Message_Type_Click
    3) I want that this Message_Type_Click will be in the file.
    But, if I execute the transaction SXMB_MONI in XI, I can see the IDOC OK .. but if I make double click on it, I don't see the Payload for the target file. Infact the target file is not be created by XI...
    I have made debug after my class and I found a Problem in the Trace with type E with message: CL_MAPPING_XMS_PLSRV3-ENTER_PLSRV.
    What is this?
    Can you help me?
    Thanks.
    Monia

    Hi Monia,
    first put your trace to 3: SXMB_ADM, Integration Engine Configuaration, Specific Configuration, Runtime/Trace Level
    Second delete your abap mapping from your interface mapping and look in the monitoring for the output. Is it what you expect? Is it the datatype the abap mapping can work with?
    Copy the result as source for the next test. Now you put the ABAP mapping inside and delete the message mapping from your interface mapping. Test with transaction SXI_MAPPING_TEST. Look to the weblog <a href="/people/sameer.shadab/blog/2005/09/29/testing-abap-mapping ABAP Mapping</a> how to test an ABAP mapping.
    The problem with more than one mapping program in one interface mapping is that you see only the result of both!
    Regards,
    Udo

  • Message Mapping of type ABAP Class not being shown

    Hi all,
    I have been trying to follow the given blog:
    /people/ravikumar.allampallam/blog/2005/02/10/different-types-of-mapping-in-xi
    Even after doing the changes mentioned in the blog, i do not see the ABAP Class in the list of Message Mapping types.
    Do i need to do anyother configuration. Pls guide.
    Regards
    Neetu

    Hi Neetu,
    You will have to enable your ABAP mapping first.
    Do the following steps, pay carefull attention to the values you enter,
    In
    IntegrationBuilder ->IntegrationBuilder.Repository -> com.sap.aii.repository.mapping.additionaltypes
    enter the value of
    R3_ABAP|Abapclass;R3_XSLT|XSL (ABAP Engine)
    If the above doesnt work, try Abap-class instead of Abapclass in the above line.
    And then follow the remaining steps, make sure that the above value is correct. Your ABAP mapping should appear in your Integration Repository.'
    I suggest you go through these links:
    https://websmp101.sap-ag.de/~sapdownload/011000358700003082332004E/HowToABAPMapping.pdf
    /people/ravikumar.allampallam/blog/2005/02/10/different-types-of-mapping-in-xi
    ABAP Mapping Vs Java Mapping.
    Refer to following SDN Demo which explains the need and how to do the ABAP mapping.
    https://www.sdn.sap.com/irj/sdn/docs?rid=/webcontent/uuid/110ff05d-0501-0010-a19d-958247c9f798#jdi [original link is broken]
    This document will help you to create ABAP Mapping.
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/xi/3.0/how%20to%20use%20abap-mapping%20in%20xi%203.0.pdf
    Regards,
    Abhy

  • How to use ABAP Class to modify Web Query Result ??

    Hi all !
    We are using Web Templates to display our Query.
    What I would like to do ( and seems a really important issue for our users! ) is to have a "PAGE BREAK" everytime the value of a charateristics change in the report
    For Example :
    -Page 1-
    Division     Project
       A               1
                        2
                        3
    -Page 2-
    Division     Project
       B               1
                        2
                        3
    and so on....
    I read threads about using ABAP CLASS but no example what so ever...
    We are presently under BW 3.1 but are considering upgrading to 7.0 by the end of the year so if there is a solution to my problem on either version i'd like to know.
    If anyone has any information about how I can do this it would be most appreciated
    Thx
    JB.

    Hi Yong,
    Ravi is right, first check the blogs by Jocelyn, and if you still have specific questions you can ask them. I have used ABAP classes in workflow and I know Mike Pokraka tries to use classes exclusively.
    Regards,
    Martin

  • ABAP Class in WAD 7.0 - what's missing?

    Guys,
    I need some help in calling an ABAP Class from the Web Application Designer 7.0. I've read all documentation about inserting my class and it looks like I'm still missing something.
    First I checked the class in a Test Query in 3.5. Put it in the WAD 3.5 and it works fine, I am replacing a field (characteristic in my query) with a longtext field which is being fetched from a table. I see the results in my 3.5 report.
    Now I'm building this in 7.0 WAD. So the following steps:
    1. My class is ok, it works in 3.5. Interface IF_BICS_CONS_WEBITEM_CUST_EXIT has been added according to the How To.
    2. I've inserted a Customer Exit Item in my WAD
    3. I've assigned the query as a source for my Customer Exit Item
    4. Navigational State Access is on, Result Set Access is on.
    5. The parameters of the Customer Exit item are set with the ABAP Class name. The Properties list there shows the Name 'Default'. The Value is 'Default' as well. Don't know what I have to fill in there.
    Have any of you any idea of what I'm missing here?
    Thanks!
    Cheers,
    Joost

    Just to Clarify I am passing value as l_s_values-value = '<a href=u201Dhttp://www.yahoo.comu201D>yahoo</a>'
    and the IE is interpreting it as l_s_values-value = '&lt;a href=u201Dhttp://www.yahoo.comu201D>yahoo</a>'.

Maybe you are looking for

  • I am going to ****.

    Well I managed to break my roommates macbook pro screen. We're studying abroad in the netherlands currently, we live in a small room. I tripped over my chair and in an attempt not to fall attempted to grab onto something... I grabbed onto his macbook

  • Threads and blocking i/o

    background i am building a multi-cliented server based on the model of one thread per client. client threads wait on a BufferedReader in the run() method for data over the network and take the appropriate action based on the input. problem a client t

  • Have a problem with Discover command mode

    Hi, I have build BA (conatins folder,Joins,item classes) and a workbook using Disco10g. Done the export using : dis51adm.exe /connect DEVUSR/DEVPWD@DEVHOST /export "Business area.eex" /"Business area" /[b]all /log export.log Imported using on TST env

  • Difference - Predictive Work Bench & Predictive Analysis

    Hi all, Pls help by providing information difference between Predictive Work Bench & Predictive Analysis

  • Question on Installing 2 cert on CSS

    Hi All, May i know if there is any limitation on the CSS not being able to install the server and root cert in 2 different files ? If yes let me know the procedure please? Thanks in advance.