Abstraction and Encapsulation i.e basic oops concepts gist and their unders

I have gone to many sites and everywhere got some difference in defintion of abstraction and encapsulation.
Below i tried to summarize the findings of both and have some questions which are inline with understanding.
Encapsulation:-
Hiding internal state and requiring all interaction to be performed through an object's methods is known
as data encapsulation — a fundamental principle of object-oriented programming.
Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. For this reason, encapsulation is also referred to as data hiding.
Question1:- Agreed that we are hiding the instance variable details but again we do expose them with getter and setter
methods. Is it not the violation of encapsulation? What advantage it provides exposing the internal state thru methods
(like getter and setter) but not declaring stae with public modifier.?
Question2:- If class does not have any state variable and has some just simple methods printing hello world.
Can we still say it is encapsulation?
Abstraction:-Abstraction in Java allows the user to hide non-essential details relevant to user.
Question1:- so we can say Encapsulation is also a feature of abstraction because in ecapsulation also we hide data(state) of object. Right?
Question2:-Say a class has 10 methods . Out of these 10 , only two are exposed for outside world with public modifier.Can we say this is the example of abstraction?
Question3:- Can we say interface/abstract class are the baset examples of abstraction as they just expose the masic details i.e signature of method to outside world?

JavaFunda wrote:
Hi jverd whats your take on original post?Question1:- Agreed that we are hiding the instance variable details but again we do expose them with getter and setter
methods. Is it not the violation of encapsulation? What advantage it provides exposing the internal state thru methods
(like getter and setter) but not declaring stae with public modifier.?
>
I don't think you can say whether an individual get/set "violates encapsulation" without more context. If you're just blindly providing direct get/set for every member variable, then it's likely you don't understand encapsulation. There's still some encapsulation there, however, because the caller can't directly see or modify the state.
Sure, a programmer familiar with coding conventions and possessing some common sense could infer that those get/set methods correspond directly to member variables of the same names, but so what? He still has to go through the methods to see or modify the state, and there could be other stuff going on there. The fact that going through the method makes it a black box to him is why I say there's some level of encapsulation. There's a continuum of how "direct" the access to the internal state is, and I don't think there's a clear delineation between "encapsulated" and "not encapsulated."
For example:
As direct as can be: setX() is simply this.x = x and getX() is simply return x.
Somewhat less direct: getFullName() returns firstname + " " + lastName. There's no member variable called "fullName", and the result is composed by operating on multiple pieces of the object's state.
Still less direct: ArrayList's toString() is "[", followed by the results of each of its elements' toString() methods, separated by commas, followed by "]"
Very indirect: Map.put(). We know that it modifies the state of the Map by adding the key/value pair we specify, and we can infer some things about how it's implemented based on the type of Map. But that abstraction is so far separated from the specific state that represents it, that we would probably say that there's a high level of encapsulation there.
And of course there are other scenarios in between these, and further toward the "encapsulated" end of the spectrum than the Map example. Where do you draw the line between "not encapsulated" and "encapsulated"?
I think a reasonable criterion to use is whether the exposed stated has been exposed because it's a natural part of the behavior of the class.
For instance, Colleciton.size(). It makes sense that as part of a Colleciton's behavior, you'd want it to be able to tell you how many items it holds. In an ArrayList, you would probably have a size variable that gets updated each time an element is added or removed. However, in a ConcurrentSkipListSet, there is no size variable. You have to traverse the Set and count the elements. So is size encapsulated here? Is it in one but not the other? Why? I would say it is in both cases, because part of the natural behavior of a Collection is to tell us its size, so the fact that in some collections that can be done simply be returning the value of a member variable doesn't "violate" encapsulation.
But, after having said all that, my real answer is: I don't care. The answer to "Do get/set violate encapsulation?" doesn't matter to me in the least in how I write my code.
>
Question2:- If class does not have any state variable and has some just simple methods printing hello world.
Can we still say it is encapsulation?
>
I would say no, since there's no state to be encapsulated. However, I supposed one could say that the behavior is encapsulated. It could be implemented any number of different ways, some of which would involve state and some wouldn't, and all we'd see is the public interface and the behavior it provides. I don't know that anybody actual does view it that way though.
And, again, this sort of nitpickery is not actually relevant to anything, IMHO.
>
Question1:- so we can say Encapsulation is also a feature of abstraction because in ecapsulation also we hide data(state) of object. Right?
>
More silly semantics. I wouldn't say that encapsulation is a "feature" of abstraction. I think the two often work together, and there's some overlap in their definitions, or at least in how they're realized in code. (Which can be seen in my long-winded answer to the first quetsion.)
>
Question2:-Say a class has 10 methods . Out of these 10 , only two are exposed for outside world with public modifier.Can we say this is the example of abstraction?
>
Don't know, don't care.
>
Question3:- Can we say interface/abstract class are the baset examples of abstraction as they just expose the masic details i.e signature of method to outside world?
>
No idea what you're saying here, but I expect my answer will again be: "don't know, don't care".
Edited by: jverd on Aug 3, 2011 10:22 AM
Edited by: jverd on Aug 3, 2011 10:22 AM

Similar Messages

  • What is difference between abstraction and encapsulation ?

    Hi,
    I am trying to figure out the difference between abstraction and encapsulation but confused.
    Both are used for data hiding then what is the exact difference ?
    Thanks.

    Tushar-Patel wrote:
    I am trying to figure out the difference between abstraction and encapsulation but confused.
    Both are used for data hiding then what is the exact difference ?This is the picture I have:
    When you encapsulate something you get an inside and an outside. The outside is the abstraction. It describes how the encapsulated entity behaves viewed from the outside. This is also called the type. Hidden inside is the implementation. It holds detail information about how the type's behaviour is accomplished.
    It's a very simplified picture but I think it's quite accurate and it works for me.

  • Concept of Abstraction and Polymorphism

    Hi friends,
    I'm just new to Java.I studied a little bit of C, I'm currently studing VB and Java.
    There are one or two concepts in Java that are very hard to grasp for me.
    The first is abstraction and the second is polymorphism.
    Can anybody outline to me in simple words(use simple example if needed)what those 2 concepts are all about?
    Thanks a lot
    Marco

    In your example, you could make Vehicle an abstract
    class. You can't simply have a vehicle, but you can
    have a car which IS a vehicle. In your abstract class
    Vehicle, you might define an abstract method public
    int getSeats() (you want it to be abstract because it
    changes from one type of vehicle to the next). So the
    class Car extends Vehicle, overrides the method
    getSeats() and returns 5. The class Ute extends
    Vehicle, overrides the method getSeats() and returns 2
    (you might make a SuperCabUte that extends Ute and
    returns 5, or whatever).Radish is right,
    Think of it as modelling of real life. You would generalise the description of your car as a Vehicle (abstraction, which can be implemented as an interface in Java) where in fact you own a car
    Similarly you can have an inteface called RealEstate where in fact you own a TwoStoreyHouse ( a class that implements the RealEstate interface)
    the interface can describe the general 'characterstics' of real estate properties ie land size, council rates etc.
    HTH...hey....

  • Basic HTML concepts and how they relate to eachother

    I am a grad student working on a project to visualize how the HTML markup is translated into a webpage in a browser. I am not a programmer, and thus am confused by how all the following concepts relate to one another. The goal lis to list them in a logical order and describe how one concept leads to the next in a sequential manner.
    I’d like to create a hierarchal list of all these terms and their definitions as a start. Here’s what I have so far.
    Tried to start with the most basic, and work my way up Any help would be appreciated. Any errors?
    SPECIFICATIONS
    WC3 / WHTWG Specification
    Defines the semantics, structure, syntax, and rendering of HTML code
    elements in HTML5 (tags)
    any element in the HTML namespace (as per the doctype declaration) - refers to all tags and their attributes - these tags are used to describe the meaning of the content they contain
        content model types     (tags can fit in one ore more of these categories of model types) 
            metadata - content that sets up the presentation or behavior of the rest of the content
            flow - elements that would be included in the normal flow of the document (fits in the HTML body tag)
            sectioning - defines the scope of heading and footers - create new sections in document
            heading - defines the header of a section, which can either be explicitly marked up with sectioning elements or implied by the heading content itself
            phrasing (similar to inline in HTML 4) - the text of the document, as well as elements used to mark up the text within paragraph level structures
            embedded - any content that imports other resources into the document
            interactive - any content that is specifically interacted for user interaction
    Outline Algorithm  (definition)
        Definition in the HTML5 spec of the rules that user agents should use when parsing code in order creating an outline of section content elements in an HTML     document
                    he outline (based on their ranking)
    AUTHOR
    HMTL5 Document - the document contenting HTML elements and authored content
    Document Semantics - the meaning associated with each HTML element Tag
        the collection of tags with meaning form the semantic structure of the HTML document
    Document Structure (combination of ordered semantic elements) - the order and nesting of tags, and the associations associated with the levels of nesting (ranking) create the document structure
        understanding the W3C outline Algorithm helps the author decide how and when to chose which elements to properly structure content
            understanding the process that HTML5 uses to outline documents will help in this decision
    USER AGENT (BROWSER)
    User Agent (browser)-
        the browser (application that user operates to interact with HTML documents
        parsing algorithm (executed) - the rules the browser uses to parses (walks through) the elements in order to establish its structure and add to the outline using     a parsing engine
            examples: webkit (safari) and gecko (firefox)
                body is established as the outline root (beginning)
        the result of the parsing is a Document object Model (DOM) and the Document Ouline
    Document outline - the nested,  hierarchical outline created by the browser parsing the html document’s structure and content
        each part of the outline is considered a node
            (relationships in the node are described with family tree terms like parent, child, and sibling.)
        sectioning and heading elements are used to define the outline
        sectioning elements are containers - so any elements contented within a a section is nested as a child in the parent’s section
    DOM -
        The DOM is the structure created by the DOM API in which  CSS and Javascript interact with and modify the HTML
        based on an object structure that closely resembles the structure of the documents it models.
        structure similar to that of a tree - in which every element is a node   
        similar to the document outline, but instead of a hierarchical list, the DOM is a tree diagram
    OUTPUT
    Final webpage

    As a rule of thumb, avoid all swing components (just use awt) because they are only available in 1.2. You can use all enhancements and bug fixes to awt components that are available in 1.4 (even 1.5).
    ;o)
    V.V.

  • OOP concept in pl/sql

    Hi!,
    I am new to pl/sql , i want to understand the oop concept please anybody guide me.... where it is used in real environment?
    any ebook which i have to prefer for basics... please contribute your ideas about it.
    Edited by: user12077151 on Feb 7, 2010 11:29 AM
    Edited by: user12077151 on Feb 7, 2010 11:30 AM

    user12077151 wrote:
    I am new to pl/sql , i want to understand the oop concept please anybody guide me.... where it is used in real environment?PL/SQL supports a number of OOP concepts - such as abstract classes, inheritance, polymorphism and so on. I did a basic example of customised data types in {message:id=2352848} - here I've explored using custom data types for dealing with 1000's of variant data attributes (called MIBs) from hardware devices (instead of using varchar2 for all values).
    What I do not consider a good idea though is mixing OOP with actual database design. Relational design is by far simpler, and provides easier use and better performance.
    The same consideration needs to be given for PL/SQL. PL/SQL is usually used as a database interface layer - instead of the Java/.Net/etc client having to know the db structures and use SQL, this is abstracted and presented via a PL/SQL interface. In such a case, using OOP in PL/SQL will not be of much benefit as using custom SQL data types on the client side is not the norm. (it is supported by the Oracle client driver, but requires a more complex approach than simply using standard SQL types already supported by the client language).
    Within PL/SQL itself, OOP can be beneficial. It can be used to make something complex (e.g. like DBMS_SQL cursors) into a much simpler and more flexible OO interface instead.
    Using OOP in PL/SQL is no different than using any other programming technique - in that you need to make sure that it is the better option for doing the job. That it makes writing code easier. Makes maintenance easier. Makes the code more robust. Enables the code to perform well. Etc.

  • OOPs Concept ! - Why Static Methods can't be redefined in its subclass ?

    Dear Experts ,
    I had searched the SDN , but unable to find out the satisfactorily answers ..
    Can anybody let me know the reason for the following Confusion in Oops Concept
    Question 1: As we know , We can Inherit the Static Methods in the Sub Class , But we can't redefine it in the base class  or       Sub Class  ?
    Question 2 : Why can't Static Method be Abstract ?
    Question 3 : Can a Class be Abstract or Final Both, If yes, then why ?
    Thanks in Advance
    Saurabh Goel

    As per the above discussion two of your doubts have already been clarified  so I am taking only third one.
    A class cannot never be Abstract and final both coz Abstract signifies that the implementation of the class has not been defined completelyi.e. may be some methods have been defined but few methods are still missing implementation. 'Final' is used for those classes/methods which cannot be redefined  means the complete implementation of the method has been defined no one can implement further logic under the same method.
    If you are saying your method is Final then it cannot be overridden and Abstract implies that method implementation is yet to be defined which can only be implemented if that class/method is not 'Final'. So both the terms are contradictory.
    Hope it clarifies!!!
    Thanks,
    Vishesh

  • OOPS concepts in Oracle Objects

    Dear All,
    Can you one explain me the aspects of Object Oriented Programming in Oracle. How to use oops concepts in Oracle Procedures, functions, packages, etc.
    Thanks,
    Moorthy.GS

    Packages are not objects. They are relational, not least because they only contain behaviour (the data is in tables). Packages do not support inheritance or polymorphism. However they do support encapsulation, arguably rather better than Oracle's SQL Types do; if you're interested in finding out more about Types you may be interested in reading a two-part article I wrote on my blog: part one and part two.
    Cheers, APC

  • Obtaining subtotals based on 2 fields.(ALV using oops concept)

    Need help on how to apply sort on 2 fields and obtain subtotals.For example if I have some records for similar tax code and some more records  for a similar tax jurisdiction (under which all tax codes come).I need to calculate subtotals for same tax code as well as same tax jurisdiction code.Currently I am able to generate subtotals by sorting on 1 field only ,using OOPs concept.How do I apply for both the fields? This is what is being done currently with regard to sorting and subtotaling : 
    METHOD set_sorts.
    lr_sorts = gr_alv_data->get_sorts( ).
    TRY.
            lr_sorts->add_sort( 'TXJCD' ). ---sorting based on tax jurisdiction
          CATCH: cx_salv_not_found,
                cx_salv_existing,
                cx_salv_data_error.
        ENDTRY.
        TRY.
            lr_sorts->add_sort( columnname = 'MSKWZ'
                                        subtotal = if_salv_c_bool_sap=>true ).
          CATCH cx_salv_data_error cx_salv_not_found
                cx_salv_existing.                          
        ENDTRY.
      ENDMETHOD.                    "set_sorts
    Thanks & Regards,
    Savitha

    Hi Savitha,
    Use the other paramenters like POSITION, SEQUENCE, SUBTOTAL for both fields like as follows. Then it will work fine.
    TRY.
    lr_sorts->add_sort( columnname = 'TXJCD'
    sequence = 1
    Position = 1
    subtotal = if_salv_c_bool_sap=>true ).
    CATCH cx_salv_data_error cx_salv_not_found
    cx_salv_existing.
    ENDTRY.
    TRY.
    lr_sorts->add_sort( columnname = 'MSKWZ'
    sequence = 2
    Position = 1
    subtotal = if_salv_c_bool_sap=>true ).
    CATCH cx_salv_data_error cx_salv_not_found
    cx_salv_existing.
    ENDTRY.

  • Which is better to use in alv functions or oops concept

    hi,
    actually some people are using function modules
    and some are using oops concept
    which one is better
    could anybody suggest
    thanks,
    kalyan

    I assume you've found TLFTextField in Flash Pro (I can't remember if Flash Builder made a TLFTextField class or not). Anyway, if you're considering using Flash Pro, here's some background on the TLFTextField class:
    This class was created primarily for backwards compatibility with Classic Text coding. If you used Flash Pro CS 4 or earlier versions, and you wrote ActionScript for your text objects, you were using TextField objects. So, when you upgraded to CS 5, and you decided to convert all your old Classic text objects to the new TLF objects, all your code would have broken were it not for TLFTextField class. TLFTextField implements the TextField API so that your existing TextField code can be used in the TLF environment.
    So, if you're an ActionScript programmer who is already comfortable programming using the TextField API, it certainly makes sense to continue doing so but using TLFTextField objects. However, if you want to take advantage of the new TLF features, the old API doesn't really give you the ability to do that. So, the TLFTextField provided a new API:
    function get textFlow():TextFlow;
    The TextFlow class is the top level class of the TLF model objects. Using that object, you can then set attributes on your text just as if you were working with TextFlow in Flash Builder. So, in essence, TLFTextField provides backwards compatibility, continued use of the familiar API set, and access to the TextFlow model class.
    Another nuance to be aware of is that if you choose to embed fonts, TLF requires the newer "DF4" (for DefineFont4, based on the SWF Tag name) vs. the older "DF3" fonts that TextField requires. For text on the stage, Flash Pro will do all the tricky work for deciding when to embed DF3 and when to embed DF4 fonts, but just be aware that mixing Classic text and TLF text when using embedded fonts can cause a "double tax" on your SWF size because it may embed the same font both as DF3 and DF4.
    Good Luck!
    Rusty

  • Need Description of OOPS Concept in LABVIEW

    Hi Every one.
    Good Morning to all.
    I want to learn the OOPS concepts in LabVIEW.
    Please can any one suggest me the links or provide me the necessary documents (like PDFs).
    Thanks in advance..
    Regards
    Naresh G

    Naresh,
    I think this will help you
    Also check for this
    =========================================
    Please remember to accept a solutions and show your appreciation by giving Kudos to helpful messages...
    Mangesh D.
    CLAD | Project Engineer
    ==
    VIPM, LabVIEW 8.2, 2009, 2011SP1, 2012, 2012SP1, 2013, cRIO,cDAQ, PXI, ELVIS, Multisim, Smart Camera....

  • ALV Report Development using OOPs concept

    complete details of " ALV Report Development using OOPs concept".
    Thanks in advance ...

    hi Sudharshan,
    please use these sample codes to understand about OOALV
    BC_ALV_GRID_CONTROL
    BC_ALVHIERGRID1_D100
    BC_ALVHIERGRID1_D210
    BC_ALVHIERGRID1_HIER
    BC_ALV_DEMO_HTML_D0100
    BC_ALV_GRID_CONTROL
    BC_ALVEXCEL
    BC_ALVEXCEL_D100
    BC_ALVEXCEL_D210
    BC_ALVEXCEL_HIER
    BC_ALVEXCEL_SAP_TEMPL
    BC_ALVEXCEL_SAP_TEMPL_F01
    BC_ALVEXCEL_SAP_TEMPL_TOP
    BC_ALVEXCELTOP
    BC_ALVHIERGRID1_D100
    BC_ALVHIERGRID1_D210
    BC_ALVHIERGRID1_HIER
    BC_ALVHIERTOP
    For learning OOPS-ALV in every SAP their is transaction named ZALV
    or try the following links:
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf
    The ALV object Grid methods allow the same functionality as ALV grid report function modules but are displayed within
    a screen (dialog program). SAP has provided a suit of programs which demonstrate how to For examples see standard SAP
    programs as detailed below:
    BCALV_EDIT_01 This report illustrates the simplest case of using an editable/noneditable ALV Grid Control.
    BCALV_EDIT_02 This report illustrates how to set chosen cells of an ALV Grid Control editable.
    BCALV_EDIT_03 In this example the user may change values of fields SEATSOCC (occupied seats) and/or PLANETYPE.
    The report checks the input value(s) semantically and provides protocol messages in case of error
    BCALV_EDIT_04 This report illustrates how to add and remove lines to a table using the ALV Grid Control and how to
    implement the saving of the new data.
    BCALV_EDIT_05 This example shows how to use checkboxes within an ALV Grid Control. You learn:
    (1) how to define a column for editable checkboxes for an attribute of your list
    (2) how to evaluate the checked checkboxes
    (3) how to switch between editable and non-editable checkboxes
    BCALV_EDIT_06 This example shows how to define a dropdown listbox for all cells of one column in an editable ALV
    Grid Control.
    BCALV_EDIT_07 This example shows how to define dropdown listboxes for particular cells of your output table.
    BCALV_EDIT_08 This report implements an ALV Grid Control with an application specific F4 help. The following aspects
    are dealt with:
    (1) how to replace the standard f4 help
    (2) how to pass the selected value to the ALV Grid Control
    (3) how to build an f4 help, whose value range depend on a value of another cell.

  • Regarding ALV using OOPS Concept

    Hi Experts,
    Can abody explain to me how can i disable some settings in the tool bar of ALV Grid using oops concept??

    Hi Alex,
    You can perform this step, before you call set_table_for_first_display and pass that to this call.
    **Exculude all unnecessary standard function in ALV
      PERFORM exclude_tb_functions CHANGING lt_exclude.
    CALL METHOD g_grid->set_table_for_first_display
        EXPORTING
      is_layout            = gs_layout
          is_variant           = l_variant
          i_save               = 'A'
          it_toolbar_excluding = lt_exclude
        CHANGING
          it_fieldcatalog      = gt_fieldcat
          it_sort              = gt_sort[]
          it_outtab            = it_final[].
    You can exclude all unwanted function in the subroutine.
    FORM exclude_tb_functions  CHANGING pt_exclude TYPE ui_functions.
      DATA ls_exclude TYPE ui_func.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
      APPEND ls_exclude TO pt_exclude.
    ENDFORM.                    " exclude_tb_functions
    This will give you complete the solution for your query.
    Thanks
    Lakshmi

  • ALV report using OOPS concept.

    Hi,
    Please help me in writing ALV report using OOPS concept as i have never used this concept before.Please post a clear picture for this.
    Thanks in advance.

    Hi
    Refer this code:
    REPORT zcls_alv_oops MESSAGE-ID z1.
    TABLES : mara.
    Types Declaration..\
    TYPES :
    BEGIN OF t_mara,
    matnr TYPE matnr,
    mtart TYPE mtart,
    maktx TYPE maktx,
    END OF t_mara,
    BEGIN OF t_marc,
    matnr TYPE matnr,
    werks TYPE werks_d,
    mtart TYPE mtart,
    maktx TYPE maktx,
    END OF t_marc.
    Internal Tables Declaration..\
    DATA :
    i_mara TYPE TABLE OF t_mara,
    i_marc TYPE TABLE OF t_marc,
    i_fcat1 TYPE lvc_t_fcat,
    i_fcat2 TYPE lvc_t_fcat.
    Constants Declaration..\
    CONSTANTS :
    c_cont1 TYPE scrfname VALUE 'CONT1',
    c_cont2 TYPE scrfname VALUE 'CONT2'.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
    SELECT-OPTIONS:
    s_matnr FOR mara-matnr NO INTERVALS.
    SELECTION-SCREEN SKIP 1.
    PARAMETERS :
    p_hotspt RADIOBUTTON GROUP r1 DEFAULT 'X',
    p_bttn RADIOBUTTON GROUP r1.
    SELECTION-SCREEN END OF BLOCK b1.
    \* Class forward referncing.
    CLASS lcl_rcvr_class DEFINITION DEFERRED.
    \* Pointers Declaration..
    DATA :
    lp_rcvr TYPE REF TO lcl_rcvr_class,
    lp_cont1 TYPE REF TO cl_gui_custom_container,
    lp_cont2 TYPE REF TO cl_gui_custom_container,
    lp_grid1 TYPE REF TO cl_gui_alv_grid,
    lp_grid2 TYPE REF TO cl_gui_alv_grid.
    \* Local Class Definiton.
    CLASS lcl_rcvr_class DEFINITION.
    PUBLIC SECTION.
    METHODS :
    hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
    IMPORTING e_row_id e_column_id es_row_no,
    handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
    IMPORTING e_row e_column.
    ENDCLASS.
    \* Local Class Implementation.
    CLASS lcl_rcvr_class IMPLEMENTATION.
    METHOD hotspot_click.
    DATA :
    wa_mara TYPE t_mara,
    wa_marc TYPE t_marc.
    DATA :
    l_index TYPE sy-tabix.
    READ TABLE i_mara INTO wa_mara INDEX e_row_id-index.
    IF sy-subrc EQ 0.
    REFRESH i_marc.
    SELECT matnr
    werks
    INTO TABLE i_marc
    FROM marc
    WHERE matnr EQ wa_mara-matnr.
    IF sy-subrc EQ 0.
    LOOP AT i_marc INTO wa_marc.
    l_index = sy-tabix.
    wa_marc-mtart = wa_mara-mtart.
    wa_marc-maktx = wa_mara-maktx.
    MODIFY i_marc FROM wa_marc INDEX l_index
    TRANSPORTING mtart maktx.
    ENDLOOP.
    CALL SCREEN 200.
    ELSE.
    MESSAGE e121 WITH text-005 wa_mara-matnr.
    ENDIF.
    ENDIF.
    ENDMETHOD.
    METHOD handle_double_click.
    DATA :
    wa_mara TYPE t_mara,
    wa_marc TYPE t_marc.
    DATA :
    l_index TYPE sy-tabix.
    READ TABLE i_mara INTO wa_mara INDEX e_row-index.
    IF sy-subrc EQ 0.
    REFRESH i_marc.
    SELECT matnr
    werks
    INTO TABLE i_marc
    FROM marc
    WHERE matnr EQ wa_mara-matnr.
    IF sy-subrc EQ 0.
    LOOP AT i_marc INTO wa_marc.
    l_index = sy-tabix.
    wa_marc-mtart = wa_mara-mtart.
    wa_marc-maktx = wa_mara-maktx.
    MODIFY i_marc FROM wa_marc INDEX l_index
    TRANSPORTING mtart maktx.
    ENDLOOP.
    CALL SCREEN 200.
    ELSE.
    MESSAGE e121 WITH text-005 wa_mara-matnr.
    ENDIF.
    ENDIF.
    ENDMETHOD.
    ENDCLASS.
    \* Start of Selection
    START-OF-SELECTION.
    \* Extract the Material Master data for the Input Material.
    SELECT a~matnr
    a~mtart
    b~maktx
    INTO TABLE i_mara
    FROM mara AS a
    INNER JOIN makt AS b
    ON a~matnr EQ b~matnr
    WHERE a~matnr IN s_matnr
    AND b~spras EQ sy-langu.
    END-OF-SELECTION.
    IF NOT i_mara\[\] IS INITIAL.
    \* Call Screen to display the Material Master data.
    CALL SCREEN 100.
    ELSE.
    MESSAGE s121 WITH text-006.
    ENDIF.
    \*& Module DISP_GRID OUTPUT
    \* text
    MODULE disp_grid OUTPUT.
    \* Build the Field catelog for Material Master data.
    PERFORM build_fcat.
    \* Display the Material Master data using ALV.
    PERFORM disp_alv.
    ENDMODULE. " DISP_GRID OUTPUT
    \*& Module USER_COMMAND_0100 INPUT
    \* text
    MODULE user_command_0100 INPUT.
    \*when exit or cancel is clicked program has to come out
    CASE sy-ucomm.
    WHEN 'EXIT' OR 'CANC'.
    LEAVE PROGRAM.
    WHEN 'BACK'.
    LEAVE TO SCREEN 0.
    ENDCASE.
    ENDMODULE. " USER_COMMAND_0100 INPUT
    \*& Form build_fcat
    \* text
    \* \--> p1 text
    \* <-\- p2 text
    FORM build_fcat.
    DATA : ws_fcat TYPE lvc_s_fcat.
    ws_fcat-fieldname = 'MATNR'.
    ws_fcat-scrtext_m = text-001.
    ws_fcat-tabname = 'I_MARA'.
    IF p_hotspt EQ 'X'.
    ws_fcat-hotspot = 'X'.
    ENDIF.
    APPEND ws_fcat TO i_fcat1.
    CLEAR ws_fcat.
    ws_fcat-fieldname = 'MTART'.
    ws_fcat-scrtext_m = text-002.
    ws_fcat-tabname = 'I_MARA'.
    APPEND ws_fcat TO i_fcat1.
    CLEAR ws_fcat.
    ws_fcat-fieldname = 'MAKTX'.
    ws_fcat-scrtext_m = text-003.
    ws_fcat-tabname = 'I_MARA'.
    APPEND ws_fcat TO i_fcat1.
    CLEAR ws_fcat.
    ENDFORM. " build_fcat
    \*& Form disp_alv
    \* text
    \* \--> p1 text
    \* <-\- p2 text
    FORM disp_alv.
    IF lp_cont1 IS INITIAL.
    \* Create the Container Object of Material Master.
    CREATE OBJECT lp_cont1
    EXPORTING
    container_name = c_cont1
    EXCEPTIONS
    cntl_error = 1
    cntl_system_error = 2
    create_error = 3
    lifetime_error = 4
    lifetime_dynpro_dynpro_link = 5
    others = 6 .
    IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE.
    \* Create the Object for Grid of Material Master.
    CREATE OBJECT lp_grid1
    EXPORTING
    i_parent = lp_cont1
    EXCEPTIONS
    error_cntl_create = 1
    error_cntl_init = 2
    error_cntl_link = 3
    error_dp_create = 4
    others = 5.
    IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE.
    \* Dipslay Material Master data by calling method.
    CALL METHOD lp_grid1->set_table_for_first_display
    CHANGING
    it_outtab = i_mara
    it_fieldcatalog = i_fcat1
    EXCEPTIONS
    invalid_parameter_combination = 1
    program_error = 2
    too_many_lines = 3
    OTHERS = 4.
    IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE.
    \* Set Handler for the Hot Spot Event.
    CREATE OBJECT lp_rcvr.
    IF p_hotspt EQ 'X'.
    SET HANDLER lp_rcvr->hotspot_click FOR lp_grid1.
    ELSE.
    SET HANDLER lp_rcvr->handle_double_click FOR lp_grid1.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDFORM. " disp_alv
    \*& Module STATUS_0100 OUTPUT
    \* text
    MODULE status_0100 OUTPUT.
    SET PF-STATUS 'MAIN_STAT'.
    SET TITLEBAR 'T_100'.
    ENDMODULE. " STATUS_0100 OUTPUT
    \*& Module STATUS_0200 OUTPUT
    \* text
    MODULE status_0200 OUTPUT.
    SET PF-STATUS 'PLANT_STAT'.
    SET TITLEBAR 'T_200'.
    ENDMODULE. " STATUS_0200 OUTPUT
    \*& Module DISP_GRID_plant OUTPUT
    \* text
    MODULE disp_grid_plant OUTPUT.
    \* Build the Field catelog for Material Plant data.
    PERFORM build_fcat_plant.
    \* Display the Material Master Plant data using ALV.
    PERFORM disp_alv_plant.
    ENDMODULE. " DISP_GRID_plant OUTPUT
    \*& Module USER_COMMAND_0200 INPUT
    \* text
    MODULE user_command_0200 INPUT.
    \*when exit or cancel is clicked program has to come out
    CASE sy-ucomm.
    WHEN 'EXIT' OR 'CANC'.
    LEAVE PROGRAM.
    WHEN 'BACK'.
    LEAVE TO SCREEN 0.
    ENDCASE.
    ENDMODULE. " USER_COMMAND_0200 INPUT
    \*& Form build_fcat_plant
    \* text
    \* \--> p1 text
    \* <-\- p2 text
    FORM build_fcat_plant.
    DATA : ws_fcat TYPE lvc_s_fcat.
    ws_fcat-fieldname = 'MATNR'.
    ws_fcat-scrtext_m = text-001.
    ws_fcat-tabname = 'I_MARC'.
    APPEND ws_fcat TO i_fcat2.
    CLEAR ws_fcat.
    ws_fcat-fieldname = 'WERKS'.
    ws_fcat-scrtext_m = text-004.
    ws_fcat-tabname = 'I_MARC'.
    APPEND ws_fcat TO i_fcat2.
    CLEAR ws_fcat.
    ws_fcat-fieldname = 'MTART'.
    ws_fcat-scrtext_m = text-002.
    ws_fcat-tabname = 'I_MARC'.
    APPEND ws_fcat TO i_fcat2.
    CLEAR ws_fcat.
    ws_fcat-fieldname = 'MAKTX'.
    ws_fcat-scrtext_m = text-003.
    ws_fcat-tabname = 'I_MARC'.
    APPEND ws_fcat TO i_fcat2.
    CLEAR ws_fcat.
    ENDFORM. " build_fcat_plant
    \*& Form disp_alv_plant
    \* text
    \* \--> p1 text
    \* <-\- p2 text
    FORM disp_alv_plant.
    IF lp_cont2 IS INITIAL.
    \* Create the Container Object of Material Plant data.
    CREATE OBJECT lp_cont2
    EXPORTING
    container_name = c_cont2
    EXCEPTIONS
    cntl_error = 1
    cntl_system_error = 2
    create_error = 3
    lifetime_error = 4
    lifetime_dynpro_dynpro_link = 5
    others = 6.
    IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE.
    \* Create the Object for Grid of Material Plant data.
    CREATE OBJECT lp_grid2
    EXPORTING
    i_parent = lp_cont2
    EXCEPTIONS
    error_cntl_create = 1
    error_cntl_init = 2
    error_cntl_link = 3
    error_dp_create = 4
    others = 5.
    IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE.
    \* Dipslay Material Plant data by calling method.
    CALL METHOD lp_grid2->set_table_for_first_display
    CHANGING
    it_outtab = i_marc
    it_fieldcatalog = i_fcat2
    EXCEPTIONS
    invalid_parameter_combination = 1
    program_error = 2
    too_many_lines = 3
    OTHERS = 4.
    IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    ENDIF.
    ENDIF.
    ELSE.
    \* Call method 'REFRESH_TABLE_DISPLAY' to refresh the grid data.
    CALL METHOD lp_grid2->refresh_table_display.
    ENDIF.
    ENDFORM. " disp_alv_plant
    Thanks
    Vasudha

  • HI   ALV USING OOPS CONCEPT

    hi
    i would like to have coding for total and subtotal in alv using oops concept and (not using function module).
    also i would like to have coding for cell color and heading and footer.
    thanx in adv
    rocky

    Hi Rocky,
    please check this link
    http://www.****************/Tutorials/ALV/Total/text.htm
    While modifying field catalog , try the following.
    Field-symbols: <lfs_fieldcat> TYPE lvc_s_fcat.
    LOOP AT i_fieldcat ASSIGNING <lfs_fieldcat>.
    CASE <lfs_fieldcat>-fieldname.
    WHEN 'LOSGR'.
    <lfs_fieldcat>-coltext = text-007.
    <lfs_fieldcat>-do_sum = c_x.
    ENDCASE.
    ENDLOOP.
    Or if you want to use field symbols.
    data: total type ref to data,
    subtotal1 type ref to data.
    field-symbols <total> like gt_sflight.
    field-symbols <subtotal1> like gt_sflight.
    call method grid1->get_subtotals
    importing
    ep_collect00 = total
    ep_collect01 = subtotal1.
    assign total->* to <total>.
    assign subtotal1->* to <subtotal1>.
    Best regards,
    raam

  • SC creation using oops concept

    Hi we are writing code in SRM7.o using oops concept, based on FM BBP_SC_APP_EVENT_DISPATCHER events which triggers while creating SC from portal.
    am using the class /SAPSRM/CL_PDO_BO_SC_ADV and using the methods of following class which suitable for the events.
    if any one created same SC or any related to this code, please share with me.
    Thanks in advance.

    Hi There,
    SRM 7.0 already uses object oriented programming, i.e. ABAP Objects. Why not just use what is already provided?
    Regards,
    Jason

Maybe you are looking for

  • Supplier Sites open interface

    Hi, I got a problem in Supplier Sites open interface in 12,After importing it to Interface we are running concurrent program Supplier Sites open interface in this it was not picking the records, in the output file it was showing , Zero records import

  • Input data into dynamic calc in Planning forms

    Hi guys, Have someone tried to combine these two requirements: 1.     to have upper level members dynamic calc 2.     to give users the ability to input data into those upper level members through Planning forms. I need to do that in order to pass in

  • Oracle 11gr2 RAC installation

    Hi Gurus, In new project we have proposed to have 2 nodes single site RAC database Oracle 11gR2 64 Bit . We are going to have OEL 5.4 64 Bit Linux as OS and IBM as machine . We are migrating standalone 10g R2 database to 11r2 Rac and from HP-UX to OE

  • How to get ipad 2 to recognize printer

    I can get to a print dialog but no printer is available.  I have an HP Pro P1102w.  It should work.

  • SQL Update Statement

    Hi All, I've a table with 5 columns, Col1, Col2, Col3, Col4 and Col5. The business requirement is that all the four columns Col1 through Col4 should be populated or none of the four columns should be populated. Any row which doesnt satisfy the above