Generic class attributes / methods

Hi,
Is it possible to access class attributes / methods generic in JavaFX?
Like:
function myFunc(attributeName:String) {
      myClass.<attributeName>
}Thanks in advance.
Edited by: toxiccrack on Aug 14, 2009 6:09 AM

Hi
I think you could take a look at the JavaFX Reflection API (javafx.reflect package). You can also visit this blog http://blogs.sun.com/girishr/entry/reflection_in_javafx
Cheers

Similar Messages

  • Generic CLASS parameters

    Hi,
    I have a function module with a  TABLE  parameter with generic type TABLE.
    I have to pass these table parameter to a method in the class, then what should be the type of the corresponding parameter inside my class.
    Regards,
    Anoop

    Ah, you can't create a generic class attribute.  But you <b>can</b> create a data reference to a generic object.
    Instead of creating an attribute "mytab", create an attribute that is a reference to data,e.g. <b>ref_mytab</b>, of type REF TO DATA.
    In your method, where you've received the table through the parameters (e.g. it_mytab TYPE STANDARD TABLE ), do this:
    GET REFERENCE OF it_mytab INTO ref_mytab.
    Whenever you need to do something with the table, do this:
    FIELD-SYMBOLS: <mytab> TYPE STANDARD TABLE.
    ASSIGN ref_mytab->* TO <mytab>.
    matt

  • Access to class attributs by coding in its mother class method definition

    Hi all,
    How can I retrieve information about a class attributs by coding?
    And is it possible to access to the attributs of the Child class from the Mother class?
    REPORT  ztest_method.
    ******      CLASS mother DEFINITION
    CLASS mother DEFINITION.
      PUBLIC SECTION.
        METHODS: get_data.
    ENDCLASS.                    "mother DEFINITION
    ******      CLASS child DEFINITION
    CLASS child DEFINITION inheriting from mother.
    ENDCLASS.                    "child DEFINITION
    *******      CLASS mother IMPLEMENTATION
    CLASS mother IMPLEMENTATION.
      METHOD get_data.
    ***Can I access to child class attributs here?
      ENDMETHOD.                    "get_data
    ENDCLASS.                    "mother IMPLEMENTATION
    DATA oref TYPE REF TO CHILD.
    DATA: method TYPE string.
    DATA: cla_name(20).
    START-OF-SELECTION.
      CREATE OBJECT oref .
      CALL METHOD oref->method).  "Here I want to access to this class's attribut without redefine it

    Hi,
    a very easy way is to define an attribute TYPE REF TO DATA in the super class and write generic access methods which work with it by dereferencing it and assigning a field symbol. This might even save you the effort of creating a class hierarchy, because one class may be able to handle all the data objects whose types are only known at run-time.
    In the below example, the only specific thing about the sub class is the constructor in which the data object is created and typed:
    REPORT  ztesta.
    *       CLASS lcl_mother DEFINITION
    CLASS lcl_mother DEFINITION.
      PUBLIC SECTION.
        METHODS get_data EXPORTING es_data TYPE any.
        METHODS set_data IMPORTING is_data TYPE any.
      PROTECTED SECTION.
        DATA mr_data TYPE REF TO data.
    ENDCLASS.                    "lcl_mother DEFINITION
    *       CLASS lcl_child1 DEFINITION
    CLASS lcl_child1 DEFINITION INHERITING FROM lcl_mother.
      PUBLIC SECTION.
        METHODS constructor.
    ENDCLASS.                    "lcl_child1 DEFINITION
    DATA:
      lr_child      TYPE REF TO lcl_mother,
      ls_but000_in  TYPE        but000,
      ls_but000_out type        but000.
    START-OF-SELECTION.
      CREATE OBJECT lr_child TYPE lcl_child1.
      ls_but000_in-partner = '0000004711'.
      lr_child->set_data( ls_but000_in ).
      lr_child->get_data( IMPORTING es_data = ls_but000_out ).
      write: / ls_but000_out-partner.
    *       CLASS lcl_mother IMPLEMENTATION
    CLASS lcl_mother IMPLEMENTATION.
      METHOD get_data.
        FIELD-SYMBOLS:
          <fs_data> TYPE ANY.
        ASSIGN mr_data->* TO <fs_data>.
        MOVE-CORRESPONDING <fs_data> TO es_data.
      ENDMETHOD.                    "get_data
      METHOD set_data.
        FIELD-SYMBOLS:
          <fs_data> TYPE ANY.
        ASSIGN mr_data->* TO <fs_data>.
        MOVE-CORRESPONDING is_data TO <fs_data>.
      ENDMETHOD.                    "set_data
    ENDCLASS.                    "lcl_mother IMPLEMENTATION
    *       CLASS lcl_child1 IMPLEMENTATION
    CLASS lcl_child1 IMPLEMENTATION.
      METHOD constructor.
        super->constructor( ).
        CREATE DATA mr_data TYPE but000.
      ENDMETHOD.                    "constructor
    ENDCLASS.                    "lcl_child1 IMPLEMENTATION
    Another variant would be to define an attribute MV_DATA which is typed individually in each sub class and program dynamically against it in the super class using field symbols.
    *& Report  ZTESTA
    REPORT  ztesta.
    *       CLASS lcl_mother DEFINITION
    CLASS lcl_mother DEFINITION.
      PUBLIC SECTION.
        METHODS get_data EXPORTING es_data TYPE any.
        METHODS set_data IMPORTING is_data TYPE any.
    ENDCLASS.                    "lcl_mother DEFINITION
    *       CLASS lcl_child1 DEFINITION
    CLASS lcl_child1 DEFINITION INHERITING FROM lcl_mother.
      PUBLIC SECTION.
        DATA: ms_data TYPE but000.
        METHODS constructor.
    ENDCLASS.                    "lcl_child1 DEFINITION
    *       CLASS lcl_child2 DEFINITION
    CLASS lcl_child2 DEFINITION INHERITING FROM lcl_mother.
      PUBLIC SECTION.
        DATA: ms_data TYPE t000.
        METHODS constructor.
    ENDCLASS.                    "lcl_child1 DEFINITION
    DATA:
      lr_child1     TYPE REF TO lcl_mother,
      lr_child2     TYPE REF TO lcl_mother,
      ls_but000     TYPE        but000,
      ls_t000       TYPE        t000.
    START-OF-SELECTION.
      CREATE OBJECT lr_child1 TYPE lcl_child1.
      lr_child1->get_data( IMPORTING es_data = ls_but000 ).
      WRITE: / ls_but000-partner.
      CREATE OBJECT lr_child2 TYPE lcl_child2.
      lr_child2->get_data( IMPORTING es_data = ls_t000 ).
      WRITE: / ls_t000-mwaer.
    *       CLASS lcl_mother IMPLEMENTATION
    CLASS lcl_mother IMPLEMENTATION.
      METHOD get_data.
        FIELD-SYMBOLS:
          <fs_data> TYPE ANY.
        ASSIGN ('MS_DATA') TO <fs_data>.
        es_data = <fs_data>.
      ENDMETHOD.                    "get_data
      METHOD set_data.
        FIELD-SYMBOLS:
          <fs_data> TYPE ANY.
        ASSIGN ('MS_DATA') TO <fs_data>.
        <fs_data> = is_data.
      ENDMETHOD.                    "set_data
    ENDCLASS.                    "lcl_mother IMPLEMENTATION
    *       CLASS lcl_child1 IMPLEMENTATION
    CLASS lcl_child1 IMPLEMENTATION.
      METHOD constructor.
        super->constructor( ).
        SELECT SINGLE * FROM but000 INTO ms_data.
      ENDMETHOD.                    "constructor
    ENDCLASS.                    "lcl_child1 IMPLEMENTATION
    *       CLASS lcl_child2 IMPLEMENTATION
    CLASS lcl_child2 IMPLEMENTATION.
      METHOD constructor.
        super->constructor( ).
        SELECT SINGLE * FROM t000 INTO ms_data.
      ENDMETHOD.                    "constructor
    ENDCLASS.                    "lcl_child2 IMPLEMENTATION
    I hope this helps!
    Regards,
    Thorsten

  • Using static .values() method of Enum in Generic Class

    Hi *,
    I tried to do the following:
    public class AClass<E extends Enum<E> >  {
         public AClass() {
              E[] values = E.values(); // this DOESN'T work
              for (E e : values) { /* do something */ }
    }This is not possible. But how can I access all Enum constants if I use
    an Enum type parameter in a Generic class?
    Thanks for your help ;-) Stephan

    Here's a possible workaround. The generic class isn't adding much in this case; I originally wrote it as a static method that you simply passed the class to:
    public class Test21
      public static enum TestEnum { A, B, C };
      public static class AClass<E extends Enum<E>>
        private Class<E> clazz;
        public AClass(Class<E> _clazz)
        {  clazz = _clazz;  }
        public Class<E> getClazz()
        {  return clazz;  }
        public void printConstants()
          for (E e : clazz.getEnumConstants())
            System.out.println(e.toString());
      public static void main(String[] argv)
        AClass<TestEnum> a = new AClass<TestEnum>(TestEnum.class);
        a.printConstants();
    }

  • 'ResourceDictionary' root element is a generic type and requires a x:Class attribute to support the x:TypeArguments attribute sp

    Error : 'ResourceDictionary' root element is a generic type and requires a x:Class attribute to support the x:TypeArguments attribute specified on the root element tag.
    Hi,
    I get this error when i include some namespaces in my ResourceDictionary to specify a Style for a custom control.
    Can anyone help me?
    Thx
    Stardusty

    Hi,
    That's the whole point. I don't want to use x:TypeArguments on a ResourceDictionary but the compiler says it needs it.
    And i don't know why.
    This code give no error:
    <ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespaceystem;assembly=mscorlib">  
    </ResourceDictionary>
    And by adding 3 namespaces it gives that weard error:
    <ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:MyTime.View.Controls"
    xmlns:converters="clr-namespace:MyTime.View.Converters"
    xmlns:validationrules="clr-namespace:MyTime.View.ValidationRules"
    xmlns:sys="clr-namespaceystem;assembly=mscorlib">  
    </ResourceDictionary>

  • Generically calling a method on an object

    Hello,
    I am trying to write a small utility method to generically call a method on an object.
    This is what I have.
        public static void doCall(Object o, String methodName, Object ... args){
            Class[] types = new Class[args.length];
            int i = 0;
            for(Object arg : args){
                types[i] = arg.getClass();
            try {
                Method m = o.getClass().getMethod(methodName, types);
                m.invoke(o, args);
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("Error dynamically calling method " + methodName + " on " + o.toString());
        }It doesn't work because it can't find the method. If I hard code the parameter types as "new Object[] {Double.TYPE}" it works fine (on methods that take a double).
    So, my question is, how can I generically set up the parameter types based on the types of the arguments?
    Thanks,
    ~Eric

    The problem is not on calling agr.getClass(), your primitive double is already autoboxed to a Double object. It is the doCall(...) method who expects an object, not a primitive. So when giving it a primitive value, java autoboxes it to the corresponding object type.
    This means your attempt will only work if the methods to call do not have any primitives as parameters.
    Test this code:
    public class GenericMethodCaller {
         public static void doCall(Object o, String methodName, Object ... args){
            Class[] types = new Class[args.length];
            int i = 0;
            for(Object arg : args){
                types[i++] = arg.getClass();
            try {
                Method m = o.getClass().getMethod(methodName, types);
                m.invoke(o, args);
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("Error dynamically calling method " + methodName + " on " + o.toString());
         public static void main(String[] args) {
              Callable callee = new Callable();
              callee.callabelMethod(10d);          
              GenericMethodCaller.doCall( callee, "callabelMethod", 10d ); // 10d gets autoboxed to a Double object.
    class Callable {
         public void callabelMethod(Double o) {
              System.out.println("callabelMethod(Double o) called");
         public void callabelMethod(double o) {
              System.out.println("callabelMethod(double o) called");
    }The output will be:
    callabelMethod(double o) called
    callabelMethod(Double o) called
    - Roy

  • Problem in generic value copier class / reflection and generic classes

    Hello experts,
    I try to archive the following and am struggling for quite some time now. Can someone please give an assessment if this is possible:
    I am trying to write a generic data copy method. It searches for all (parameterless) getter methods in the source object that have a corresponding setter method (with same name but prefixed by "set" instead of "get" and with exactly one parameter) in the destination object.
    For each pair I found I do the following: If the param of the setter type (T2) is assignable from the return type of the getter (T1), I just assign the value. If the types are not compatible, I want to instantiate a new instance of T2, assign it via the setter, and invoke copyData recursively on the object I get from the getter (as source) and the newly created instance (as destination). The assumption is here, that the occurring source and destination objects are incompatible but have matching getter and setter names and at the leaves of the object tree, the types of the getters and setters are compatible so that the recursion ends.
    The core of the problem I am struggling with is the step where I instantiate the new destination object. If T2 is a non-generic type, this is straightforward. However, imagine T1 and T2 are parametrized collections: T1 is List<T3> and T2 is List<T4>. Then I need special handling of the collection. I can easily iterate over the elements of the source List and get the types of the elements, but I can not instantiate only a generic version of the destinatino List. Further I cannot create elements of T4 and add it to the list of T2 and go into recursion, since the information that the inner type of the destination list is T4 is not available at run-time.
    public class Source {
       T1 getA();
       setA(T1 x);
    public class Dest {
       T2 getA();
       setA(T2 x);
    public class BeanDataCopier {
       public static void copyData(Object source, Object destination) {
          for (Method getterMethod : sourceGetterMethods) {
             ... // find matching getter and setter names
             Class sourceParamT = [class of return value of the getter];
             Class destParamT = [class of single param of the setter];
             // special handling for collections -  I could use some help here
             // if types are not compatible
             Object destParam = destination.getClass().newInstance();
             Object sourceParam = source.[invoke getter method];
             copyData(sourceParam, destParam);
    // usage of the method
    Souce s = new Source(); // this is an example, I do not know the type of s at copying time
    Dest d = new Dest(); // the same is true for d
    // initialize s in a complicated way (actually JAX-B does this)
    // copy values of s to d
    BeanDataCopier.copyData(s, d);
    // now d should have copied values from s Can you provide me with any alternative approaches to implement this "duck typing" behaviour on copying properties?
    Best regards,
    Patrik
    PS: You might have guessed my overall use case: I am sending an object tree over a web service. On the server side, the web service operation has a deeply nested object structure as the return type. On the client side, these resulting object tree has instances not of the original classes, but of client classes generated by axis. The original and generated classes are of different types but have the identically named getter and setter methods (which again have incompatible parameter types that however have consistent names). On the client side, I want to simply create an object of the original class and have the values of the client object (including the whole object tree) copied into it.
    Edited by: Patrik_Spiess on Sep 3, 2008 5:09 AM

    As I understand your use case this is already supported by Axis with beanMapping [http://ws.apache.org/axis/java/user-guide.html#EncodingYourBeansTheBeanSerializer]
    - Roy

  • Field-symbols as class attribute

    Hi Fellas,
    Is there a way we can define a field-symbols as a class attribute ? My requirement is that i am dynamically constructing a structure at runtime in my model class and binding the component of this structure to my view fields. I am able to create the structure which is basically ref to cl_abap_structdescr and the problem is when i am binding to the model attribute, i need this to be a structure so that i can address the components as "//model/structure.component".
    Please let me know how we can define a field-symbol as a class attribute.
    Cheers,
    Ram.

    Hi Ram,
    Field-Symbol as class attribute is not possible. Your way to do this by REF TO DATA is the correct way for that.
    By default data binding is only possible like this:
    Simple field attribute
    value=”//<model>/<field name>”
    Structure attribute
    value=”//<model>/<structure name>.<field name>”
    Table attribute
    value=”//<model>/<table name>[<line index].<field name>”
    If you want to bind to your data reference you have to implement your own getter and setter methods. Read this <a href="http://help.sap.com/saphelp_nw70/helpdata/en/fb/fbb84c20df274aa52a0b0833769057/frameset.htm">http://help.sap.com/saphelp_nw70/helpdata/en/fb/fbb84c20df274aa52a0b0833769057/frameset.htm</a> for further information. In addition to that, you have to implement your own GET_M_S_xxx to return metadata of your structure. By doing all this it is possible to implement a completely dynamic data binding. In the view it looks like the regular Structure attribute: value=”//<model>/<data-ref name>.<field name>”
    Regards,
    Thilo

  • What is the use of Generic class in java

    hi everyone,
    i want to know that
    what is the use of Generic class in java ?
    regards,
    dhruvang

    Simplistically...
    A method is a block of code that makes some Objects in the block of code abstract (those abstract Objects are the parameters of the method). This allows us to reuse the method passing in different Objects (arguments) each time.
    In a similar way, Generics allows us to take a Class and make some of the types in the class abstract. (These types are the type parameters of the class). This allows us to reuse the class, passing in different types each time we use it.
    We write type parameters (when we declare) and type arguments (when we use) inside < >.
    For example the List class has a Type Parameter which makes the type of the things in the list become abstract.
    A List<String> is a list of Strings, it has a method "void add(String)" and a method "String get(int)".
    A List<File> is a list of Files, it has a method "void add(File)" and a method "File get(int)".
    List is just one class (interface actually but don't worry about that), but we can specify different type arguments which means the methods use this abstract type rather than a fixed concrete type in their declarations.
    Why?
    You spend a little more effort describing your types (List<String> instead of just List), and as a benefit, you, and anyone else who reads your code, and the compiler (which also reads your code) know more accurately the types of things. Because more detail is known, the compiler is able to tell you when you screw up (as opposed to finding out at runtime). And people understand your code better.
    Once you get used to them, its a bit like the difference between black and white TV, and colour TV. When you see code that doesn't specify the type parameters, you just get the feeling that you are missing out on something. When I see an API with List as a return type or argument type, I think "List of what?". When I see List<String>, I know much more about that parameter or return type.
    Bruce

  • Could you please send me the material Opps concepts Classes and Methods

    Hi Experts,
    I am working on Opps concepts.I am new to this concept.
    Could you please send me the detailed presentation on Abap oops.
    Thanks inadvance,
    Regards,
    Rekha.

    Hi this will help u.
    OOPs ABAP uses Classes and Interfaces which uses Methods and events.
    If you have Java skills it is advantage for you.
    There are Local classes as well as Global Classes.
    Local classes we can work in SE38 straight away.
    But mostly it is better to use the Global classes.
    Global Classes or Interfaces are to be created in SE24.
    SAP already given some predefined classes and Interfaces.
    This OOPS concepts very useful for writing BADI's also.
    So first create a class in SE 24.
    Define attributes, Methods for that class.
    Define parameters for that Method.
    You can define event handlers also to handle the messages.
    After creation in each method write the code.
    Methods are similar to ABAP PERFORM -FORM statements.
    After the creation of CLass and methods come to SE38 and create the program.
    In the program create a object type ref to that class and with the help of that Object call the methods of that Class and display the data.
    Example:
    REPORT sapmz_hf_alv_grid .
    Type pool for icons - used in the toolbar
    TYPE-POOLS: icon.
    TABLES: zsflight.
    To allow the declaration of o_event_receiver before the
    lcl_event_receiver class is defined, decale it as deferred in the
    start of the program
    CLASS lcl_event_receiver DEFINITION DEFERRED.
    G L O B A L I N T E R N A L T A B L E S
    *DATA: gi_sflight TYPE STANDARD TABLE OF sflight.
    To include a traffic light and/or color a line the structure of the
    table must include fields for the traffic light and/or the color
    TYPES: BEGIN OF st_sflight.
    INCLUDE STRUCTURE zsflight.
    Field for traffic light
    TYPES: traffic_light TYPE c.
    Field for line color
    types: line_color(4) type c.
    TYPES: END OF st_sflight.
    TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
    DATA: gi_sflight TYPE tt_sflight.
    G L O B A L D A T A
    DATA: ok_code LIKE sy-ucomm,
    Work area for internal table
    g_wa_sflight TYPE st_sflight,
    ALV control: Layout structure
    gs_layout TYPE lvc_s_layo.
    Declare reference variables to the ALV grid and the container
    DATA:
    go_grid TYPE REF TO cl_gui_alv_grid,
    go_custom_container TYPE REF TO cl_gui_custom_container,
    o_event_receiver TYPE REF TO lcl_event_receiver.
    DATA:
    Work area for screen 200
    g_screen200 LIKE zsflight.
    Data for storing information about selected rows in the grid
    DATA:
    Internal table
    gi_index_rows TYPE lvc_t_row,
    Information about 1 row
    g_selected_row LIKE lvc_s_row.
    C L A S S E S
    CLASS lcl_event_receiver DEFINITION.
    PUBLIC SECTION.
    METHODS:
    handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
    IMPORTING
    e_object e_interactive,
    handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
    IMPORTING e_ucomm.
    ENDCLASS.
    CLASS lcl_event_receiver IMPLEMENTATION
    CLASS lcl_event_receiver IMPLEMENTATION.
    METHOD handle_toolbar.
    Event handler method for event toolbar.
    CONSTANTS:
    Constants for button type
    c_button_normal TYPE i VALUE 0,
    c_menu_and_default_button TYPE i VALUE 1,
    c_menu TYPE i VALUE 2,
    c_separator TYPE i VALUE 3,
    c_radio_button TYPE i VALUE 4,
    c_checkbox TYPE i VALUE 5,
    c_menu_entry TYPE i VALUE 6.
    DATA:
    ls_toolbar TYPE stb_button.
    Append seperator to the normal toolbar
    CLEAR ls_toolbar.
    MOVE c_separator TO ls_toolbar-butn_type..
    APPEND ls_toolbar TO e_object->mt_toolbar.
    Append a new button that to the toolbar. Use E_OBJECT of
    event toolbar. E_OBJECT is of type CL_ALV_EVENT_TOOLBAR_SET.
    This class has one attribute MT_TOOLBAR which is of table type
    TTB_BUTTON. The structure is STB_BUTTON
    CLEAR ls_toolbar.
    MOVE 'CHANGE' TO ls_toolbar-function.
    MOVE icon_change TO ls_toolbar-icon.
    MOVE 'Change flight' TO ls_toolbar-quickinfo.
    MOVE 'Change' TO ls_toolbar-text.
    MOVE ' ' TO ls_toolbar-disabled.
    APPEND ls_toolbar TO e_object->mt_toolbar.
    ENDMETHOD.
    METHOD handle_user_command.
    Handle own functions defined in the toolbar
    CASE e_ucomm.
    WHEN 'CHANGE'.
    PERFORM change_flight.
    LEAVE TO SCREEN 0.
    ENDCASE.
    ENDMETHOD.
    ENDCLASS.
    S T A R T - O F - S E L E C T I O N.
    START-OF-SELECTION.
    SET SCREEN '100'.
    *& Module USER_COMMAND_0100 INPUT
    MODULE user_command_0100 INPUT.
    CASE ok_code.
    WHEN 'EXIT'.
    LEAVE TO SCREEN 0.
    ENDCASE.
    ENDMODULE. " USER_COMMAND_0100 INPUT
    *& Module STATUS_0100 OUTPUT
    MODULE status_0100 OUTPUT.
    DATA:
    For parameter IS_VARIANT that is sued to set up options for storing
    the grid layout as a variant in method set_table_for_first_display
    l_layout TYPE disvariant,
    Utillity field
    l_lines TYPE i.
    After returning from screen 200 the line that was selected before
    going to screen 200, should be selected again. The table gi_index_rows
    was the output table from the GET_SELECTED_ROWS method in form
    CHANGE_FLIGHT
    DESCRIBE TABLE gi_index_rows LINES l_lines.
    IF l_lines > 0.
    CALL METHOD go_grid->set_selected_rows
    EXPORTING
    it_index_rows = gi_index_rows.
    CALL METHOD cl_gui_cfw=>flush.
    REFRESH gi_index_rows.
    ENDIF.
    Read data and create objects
    IF go_custom_container IS INITIAL.
    Read data from datbase table
    PERFORM get_data.
    Create objects for container and ALV grid
    CREATE OBJECT go_custom_container
    EXPORTING container_name = 'ALV_CONTAINER'.
    CREATE OBJECT go_grid
    EXPORTING
    i_parent = go_custom_container.
    Create object for event_receiver class
    and set handlers
    CREATE OBJECT o_event_receiver.
    SET HANDLER o_event_receiver->handle_user_command FOR go_grid.
    SET HANDLER o_event_receiver->handle_toolbar FOR go_grid.
    Layout (Variant) for ALV grid
    l_layout-report = sy-repid. "Layout fo report
    Setup the grid layout using a variable of structure lvc_s_layo
    Set grid title
    gs_layout-grid_title = 'Flights'.
    Selection mode - Single row without buttons
    (This is the default mode
    gs_layout-sel_mode = 'B'.
    Name of the exception field (Traffic light field) and the color
    field + set the exception and color field of the table
    gs_layout-excp_fname = 'TRAFFIC_LIGHT'.
    gs_layout-info_fname = 'LINE_COLOR'.
    LOOP AT gi_sflight INTO g_wa_sflight.
    IF g_wa_sflight-paymentsum < 100000.
    Value of traffic light field
    g_wa_sflight-traffic_light = '1'.
    Value of color field:
    C = Color, 6=Color 1=Intesified on, 0: Inverse display off
    g_wa_sflight-line_color = 'C610'.
    ELSEIF g_wa_sflight-paymentsum => 100000 AND
    g_wa_sflight-paymentsum < 1000000.
    g_wa_sflight-traffic_light = '2'.
    ELSE.
    g_wa_sflight-traffic_light = '3'.
    ENDIF.
    MODIFY gi_sflight FROM g_wa_sflight.
    ENDLOOP.
    Grid setup for first display
    CALL METHOD go_grid->set_table_for_first_display
    EXPORTING i_structure_name = 'SFLIGHT'
    is_variant = l_layout
    i_save = 'A'
    is_layout = gs_layout
    CHANGING it_outtab = gi_sflight.
    *-- End of grid setup -
    Raise event toolbar to show the modified toolbar
    CALL METHOD go_grid->set_toolbar_interactive.
    Set focus to the grid. This is not necessary in this
    example as there is only one control on the screen
    CALL METHOD cl_gui_control=>set_focus EXPORTING control = go_grid.
    ENDIF.
    ENDMODULE. " STATUS_0100 OUTPUT
    *& Module USER_COMMAND_0200 INPUT
    MODULE user_command_0200 INPUT.
    CASE ok_code.
    WHEN 'EXIT200'.
    LEAVE TO SCREEN 100.
    WHEN'SAVE'.
    PERFORM save_changes.
    ENDCASE.
    ENDMODULE. " USER_COMMAND_0200 INPUT
    *& Form get_data
    FORM get_data.
    Read data from table SFLIGHT
    SELECT *
    FROM zsflight
    INTO TABLE gi_sflight.
    ENDFORM. " load_data_into_grid
    *& Form change_flight
    Reads the contents of the selected row in the grid, ans transfers
    the data to screen 200, where it can be changed and saved.
    FORM change_flight.
    DATA:l_lines TYPE i.
    REFRESH gi_index_rows.
    CLEAR g_selected_row.
    Read index of selected rows
    CALL METHOD go_grid->get_selected_rows
    IMPORTING
    et_index_rows = gi_index_rows.
    Check if any row are selected at all. If not
    table gi_index_rows will be empty
    DESCRIBE TABLE gi_index_rows LINES l_lines.
    IF l_lines = 0.
    CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
    EXPORTING
    textline1 = 'You must choose a line'.
    EXIT.
    ENDIF.
    Read indexes of selected rows. In this example only one
    row can be selected as we are using gs_layout-sel_mode = 'B',
    so it is only ncessary to read the first entry in
    table gi_index_rows
    LOOP AT gi_index_rows INTO g_selected_row.
    IF sy-tabix = 1.
    READ TABLE gi_sflight INDEX g_selected_row-index INTO g_wa_sflight.
    ENDIF.
    ENDLOOP.
    Transfer data from the selected row to screenm 200 and show
    screen 200
    CLEAR g_screen200.
    MOVE-CORRESPONDING g_wa_sflight TO g_screen200.
    LEAVE TO SCREEN '200'.
    ENDFORM. " change_flight
    *& Form save_changes
    Changes made in screen 200 are written to the datbase table
    zsflight, and to the grid table gi_sflight, and the grid is
    updated with method refresh_table_display to display the changes
    FORM save_changes.
    DATA: l_traffic_light TYPE c.
    Update traffic light field
    Update database table
    MODIFY zsflight FROM g_screen200.
    Update grid table , traffic light field and color field.
    Note that it is necessary to use structure g_wa_sflight
    for the update, as the screen structure does not have a
    traffic light field
    MOVE-CORRESPONDING g_screen200 TO g_wa_sflight.
    IF g_wa_sflight-paymentsum < 100000.
    g_wa_sflight-traffic_light = '1'.
    C = Color, 6=Color 1=Intesified on, 0: Inverse display off
    g_wa_sflight-line_color = 'C610'.
    ELSEIF g_wa_sflight-paymentsum => 100000 AND
    g_wa_sflight-paymentsum < 1000000.
    g_wa_sflight-traffic_light = '2'.
    clear g_wa_sflight-line_color.
    ELSE.
    g_wa_sflight-traffic_light = '3'.
    clear g_wa_sflight-line_color.
    ENDIF.
    MODIFY gi_sflight INDEX g_selected_row-index FROM g_wa_sflight.
    Refresh grid
    CALL METHOD go_grid->refresh_table_display.
    CALL METHOD cl_gui_cfw=>flush.
    LEAVE TO SCREEN '100'.
    ENDFORM. " save_changes
    chk this blog
    /people/vijaybabu.dudla/blog/2006/07/21/topofpage-in-alv-using-clguialvgrid
    with regards,
    Hema.
    pls give points if helpful.

  • Class attribute in technical workflow log not updated

    Hi Gurus,
    I built a workflow analogous to the famous demo workflow "demoformabs" but with the demo class: CL_SWF_FORMABSENC instead of the BOR: FORMABSENC.
    In the BOR Formabsenc there is also an attribute for the "Approver" (USR01) in addition to "Creator" (USR01).
    This attribute "Approver" is missing in the class "CL_SWF_FORMABSENC".
    So I added this attribute "Approver" also in the class "CL_SWF_FORMABSENC":
    data APPROVER type SIBFLPORB value CL_SWF_BOR_TYPES=>MC_USR01.
    Finally in the method "approve" I set the value for the attribute "APPROVER".
    me->approver-instid = me->APPROVBY.
    I can see that the value has been successfully set by setting a binding from this class attribute to a workflow container element.
    BUT, in the technical workflow log (container) I can not see the class attribute "Approver" populated.
    Here it´s still displayed as < no instance >.
    What do I need to do, to make this value appear also in this class attribute in the technical workflow log?
    Albeit I know, that it´s working, I am getting confused, that it´s still displayed as empty.
    Cheers,
    Dominik

    Hi Dominik,
    You should not populate attributes in this manner, for the very reason you're experiencing. Attributes are transient and behave like variables, i.e. when the class stops existing they disappear. During binding only the key is transferred, and - if needed - the class is re-instantiated at the other end. If you have implemented some kind of buffering/instance management (not a bad idea), then you may be lucky to have attributes survive if everything happens within the same program context. However once your WF session stops executing, this is lost.
    This is why when you look at the log later, it is re-instantiating a completely new instance - where would it know the approver from?
    The attribute value must be written to the DB somewhere, so that any later object instantiation (e.g. when you look at the log) will read the value and populate the attributes correctly.
    Incidentally this is why OO theory discourages the use of public attributes and suggests GET_ and SET_ methods instead....
    Regards,
    Mike

  • Field symbols as Class Attributes

    Hello Gurus,
    Is anybody able to say to me if it is possible to declare field symbols as class attributes? As I can understand until now, this is not possible and we need to use some attribute with the "TYPE REF TO Data" to get the information we need. Correct?
    Thanks,
    Daniel.

    Ok, let me see if someone can give me some idea on how to improve my method:
    Method: PREPARE_PTOOL_DATA
    Parameters specification:
    Parameter        Type     Typing     Reference Type
    PF_ANALYSIS        Importing     Type     /SYM/SC_PT_ID_ANALYSIS_D
    PF_ANAL_DESC        Importing     Type     /SYM/SC_NM_DESC_ANALYSIS
    PF_LOGIC        Importing     Type     CHAR01
    PF_MATERIAL        Importing     Type     MATNR
    PF_MAKTX        Importing     Type     MAKTX
    PT_DATA_COMPA        Exporting     Type     /SYM/SC_TAB_PT_RESULT_CP
    PT_CALC_ANALY        Exporting     Type     /SYM/SC_TAB_PT_RESULT_CA
    PT_DATA_MATERIAL1 Changing     Type     /SYM/SC_TAB_PROC_ALLERG_RESULT
    PT_DATA_MATERIAL2     Changing     Type     /SYM/SC_TAB_PROC_ALLERG_RESULT
    Source code:
    From the /SYM/SC_CL_PROCESS_ALLERG_GEN class
    Old version (but it is working)
    METHOD prepare_ptool_data.
      DATA: ls_data_material1   TYPE /sym/sc_s_proc_allerg_result,
            ls_data_material2   TYPE /sym/sc_s_proc_allerg_result,
            lf_index_material1  TYPE sy-tabix,
            lf_index_material2  TYPE sy-tabix,
            ls_result_cp        TYPE /sym/sc_pt_result_cp,
            ls_result_ca        TYPE /sym/sc_pt_result_ca.
    Prepare data for Data Comparison step
      IF pt_data_compa IS REQUESTED.
        LOOP AT pt_data_material1 INTO ls_data_material1.
          lf_index_material1 = sy-tabix.
          CLEAR ls_result_cp.
          MOVE pf_analysis   TO ls_result_cp-analysis.
          MOVE pf_anal_desc  TO ls_result_cp-desc_analysis.
          MOVE ls_data_material1-algbe TO ls_result_cp-desc_property.
    If Logic 'A', move the text from ls_data_material1 to original
    material status
          IF pf_logic EQ c_logic_a.
            MOVE ls_data_material1-agsbe TO ls_result_cp-val_orig_matnr.
    If Logic 'B', move the text from ls_data_material1 to "toy"
    material status
          ELSEIF pf_logic EQ c_logic_b.
            MOVE ls_data_material1-agsbe TO ls_result_cp-val_toy_matnr.
          ENDIF.  " IF pf_logic EQ c_logic_a.
    Read the lt_data_toy by the Allergen ID (ALGEN)
          CLEAR ls_data_material2.
          READ TABLE pt_data_material2 INTO ls_data_material2
                WITH KEY algen = ls_data_material1-algen BINARY SEARCH.
          IF sy-subrc EQ 0.
            lf_index_material2 = sy-tabix.
    If Logic 'A', move the text from ls_data_material2 to "toy°
    material status
            IF pf_logic EQ c_logic_a.
              MOVE ls_data_material2-agsbe TO ls_result_cp-val_toy_matnr.
    If Logic 'B', move the text from ls_data_material2 to original
    material status
            ELSEIF pf_logic EQ c_logic_b.
              MOVE ls_data_material2-agsbe TO ls_result_cp-val_orig_matnr.
            ENDIF.  " IF pf_logic EQ c_a.
    Delete record from lt_data_toy, index lf_index_toy
            DELETE pt_data_material2 INDEX lf_index_material2.
          ENDIF.  " IF sy-subrc EQ 0.
          APPEND ls_result_cp TO pt_data_compa.
    Delete record from lt_data_orig, index lf_index_orig
          DELETE pt_data_material1 INDEX lf_index_material1.
        ENDLOOP.  " LOOP AT lt_data_material1 INTO ls_data_material1.
      ENDIF.  " IF pt_data_compa IS REQUESTED.
    Prepare data for Calculation Analysis step
      IF pt_calc_analy IS REQUESTED.
        LOOP AT pt_data_material1 INTO ls_data_material1.
          lf_index_material1 = sy-tabix.
          CLEAR ls_result_ca.
          MOVE pf_material   TO ls_result_ca-matnr.
          MOVE pf_maktx      TO ls_result_ca-maktx.
          MOVE pf_analysis   TO ls_result_ca-analysis.
          MOVE pf_anal_desc  TO ls_result_ca-desc_analysis.
          MOVE ls_data_material1-algbe TO ls_result_ca-desc_property.
    If Logic 'A', move the text from ls_data_material1 to original
    material status
          IF pf_logic EQ c_logic_a.
            MOVE ls_data_material1-agsbe TO ls_result_ca-val_curr_stat.
    If Logic 'B', move the text from ls_data_material1 to "toy"
    material status
          ELSEIF pf_logic EQ c_logic_b.
            MOVE ls_data_material1-agsbe TO ls_result_ca-val_simul_stat.
          ENDIF.  " IF pf_logic EQ c_logic_a.
    Read the lt_data_toy by the Allergen ID (ALGEN)
          CLEAR ls_data_material2.
          READ TABLE pt_data_material2 INTO ls_data_material2
                WITH KEY algen = ls_data_material1-algen BINARY SEARCH.
          IF sy-subrc EQ 0.
            lf_index_material2 = sy-tabix.
    If Logic 'A', move the text from ls_data_material2 to "toy°
    material status
            IF pf_logic EQ c_logic_a.
              MOVE ls_data_material2-agsbe TO ls_result_ca-val_simul_stat.
    If Logic 'B', move the text from ls_data_material2 to original
    material status
            ELSEIF pf_logic EQ c_logic_b.
              MOVE ls_data_material2-agsbe TO ls_result_ca-val_curr_stat.
            ENDIF.  " IF pf_logic EQ c_a.
    Delete record from lt_data_toy, index lf_index_toy
            DELETE pt_data_material2 INDEX lf_index_material2.
          ENDIF.  " IF sy-subrc EQ 0.
          APPEND ls_result_ca TO pt_calc_analy.
    Delete record from lt_data_orig, index lf_index_orig
          DELETE pt_data_material1 INDEX lf_index_material1.
        ENDLOOP.  " LOOP AT lt_data_material1 INTO ls_data_material1.
      ENDIF.  " IF pt_calc_analy IS REQUESTED.
    ENDMETHOD.
    As you can see, I am repeating almost the same code, just changing some items. I am not sure if I can use new parameters (ANY or ANY TABLE) but, my first idea to improve it was to use the field-symbols (and it works ok). The issue is that I have to repeat the assignment lines every same named method of the classes I am changing (I would like to do the assignment into a new method of the superclass). Do you think it is possible or should I give up and proceed with the assignments locally, for each same named method of each class?
    Thanks,
    Daniel.

  • Using Classes and Methods

    Hi Experts,
    I am studying ABAP Objects, before that I need to know How to use the exsiting classes and Methods in our program and how to search for particular class and methods?
    If it explanied with example well and good.
    Thanks
    sai

    Hi Saikar,
    Here i am sending you very useful content for the usage of classes and its methods.
    It helped me a lot.
    If you find it useful then do not forget to award points.
    Table of Contents
    Applies to:......................................................................................................................................1
    Summary........................................................................................................................................1
    Author Bio......................................................................................................................................1
    Main Class – CL_SALV_TABLE......................................................................................................3
    Functions – CL_SALV_FUNCTIONS..............................................................................................4
    Display Settings – CL_SALV_DISPLAY_SETTINGS......................................................................4
    Columns – CL_SALV_COLUMNS_TABLE and CL_SALV_COLUMN_TABLE..............................5
    Sorts – CL_SALV_SORTS..............................................................................................................8
    Aggregations – CL_SALV_AGGREGATIONS..............................................................................10
    Filters – CL_SALV_FILTERS........................................................................................................12
    Layouts – CL_SALV_LAYOUT......................................................................................................14
    Related Content...........................................................................................................................15
    Disclaimer and Liability Notice.......................................................................................................16 
    ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 3
    Main Class – CL_SALV_TABLE
    The main class used to create the simple 2D table is the class CL_SALV_TABLE. Create a reference variable for this class. Create an internal table and fill this internal table with data as show below.
    REPORT ZALVOM_DEMO1. data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. start-of-selection. select * into table ispfli from spfli.
    Next we need to create the ALV object for the 2D table. The FACTORY method allows you to create the ALV object in 3 ways. You can create the ALV Grid, as a classical list display, as a full screen grid, and finally embedded into a screen container. For this example, we will be working with the full screen grid. Create the call to the FACTORY method. We are importing the object reference into GR_TABLE and passing the internal table ISPFLI.
    cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ).
    Next we need to display the grid, for this we use the DISPLAY method . Simply call it.
    gr_table->display( ). 
    ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 4
    Functions – CL_SALV_FUNCTIONS
    Next, add functions to the application toolbar. For this, use the CL_SALV_FUNCTIONS class. Create the object reference variable and receive the object using the GET_FUNCTIONS method of the GR_TABLE object. Call the method SET_ALL to force the ALV grid to show all standard functions.
    report zalvom_demo1. data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions. start-of-selection. select * into table ispfli from spfli. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). gr_functions = gr_table->get_functions( ). gr_functions->set_all( abap_true ). gr_table->display( ).
    The result is now you have the standard buttons on the application toolbar.
    Display Settings – CL_SALV_DISPLAY_SETTINGS
    Next, we can change some display settings using the class CL_SALV_DISPLAY_SETTINGS. Create the object reference variable and receive the object using the GET_DISPLAY_SETTINGS method of the GR_TABLE object. In this example, we are setting the “Striped Pattern” for the ALV Grid rows, and setting the heading in the title bar.
    report zalvom_demo1. 
    ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 5
    ). data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions. data: gr_display type ref to cl_salv_display_settings. start-of-selection. select * into table ispfli from spfli. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). gr_functions = gr_table->get_functions( ). gr_functions->set_all( abap_true ). gr_display = gr_table->get_display_settings( ). gr_display->set_striped_pattern( cl_salv_display_settings=>true ). gr_display->set_list_header( 'This is the heading' gr_table->display( ).
    Columns – CL_SALV_COLUMNS_TABLE and CL_SALV_COLUMN_TABLE
    Next, we can change some of the attributes of a specific column in the ALV grid. In this example we will change the Heading Text of a column as well as the color of a column. Create the object reference variable and receive the object using the GET_COLUMNS method of the GR_TABLE object. This will pass you the object for all columns of the ALV grid. To access just one column, call the method GET_COLUMN from the GR_COLUMNS object. In this example, we are accessing the CITYTO column and the CITYFROM column.
    report zalvom_demo1. data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions. 
    ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 6
    data: gr_display type ref to cl_salv_display_settings. data: gr_columns type ref to cl_salv_columns_table. data: gr_column type ref to cl_salv_column_table.
    data: color type lvc_s_colo.
    start-of-selection. select * into table ispfli from spfli. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). gr_functions = gr_table->get_functions( ). gr_functions->set_all( abap_true ). gr_display = gr_table->get_display_settings( ). gr_display->set_striped_pattern( cl_salv_display_settings=>true ). gr_display->set_list_header( 'This is the heading' ). gr_columns = gr_table->get_columns( ). gr_column ?= gr_columns->get_column( 'CITYTO' ). gr_column->set_long_text( 'This is long text' ). gr_column->set_medium_text( 'This is med text' ).
    gr_column->set_short_text( 'This is sh' ).
    gr_column ?= gr_columns->get_column( 'CITYFROM' ). color-col = '6'. color-int = '1'. color-inv = '0'. gr_column->set_color( color ).
    gr_table->display( ). 
    ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 7 ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 8
    Sorts – CL_SALV_SORTS
    Next, we can add some sorting to the ALV grid. Create the object reference variable and receive the object using the GET_SORTS method of the GR_TABLE object. Next, add the sort by calling the ADD_SORT method of the GR_SORTS object.
    report zalvom_demo1. data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions. data: gr_display type ref to cl_salv_display_settings. data: gr_columns type ref to cl_salv_columns_table. data: gr_column type ref to cl_salv_column_table. data: gr_sorts type ref to cl_salv_sorts.
    data: color type lvc_s_colo.
    start-of-selection. select * into table ispfli from spfli. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). gr_functions = gr_table->get_functions( ). gr_functions->set_all( abap_true ). gr_display = gr_table->get_display_settings( ). gr_display->set_striped_pattern( cl_salv_display_settings=>true ). gr_display->set_list_header( 'This is the heading' ). gr_columns = gr_table->get_columns( ). gr_column ?= gr_columns->get_column( 'CITYTO' ). gr_column->set_long_text( 'This is long text' ). gr_column->set_medium_text( 'This is med text' ). gr_column->set_short_text( 'This is sh' ). gr_column ?= gr_columns->get_column( 'CITYFROM' ). color-col = '6'. color-int = '1'. color-inv = '0'. gr_column->set_color( color ). gr_sorts = gr_table->get_sorts( ). gr_sorts->add_sort 'CITYTO' ). gr_table->display( ). 
    ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 9 ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 10
    Aggregations – CL_SALV_AGGREGATIONS
    Since we sorted by CITYTO, we can add an aggregation to subtotal the DISTANCE by CITYTO. Create the object reference variable and receive the object using the GET_AGGREGATIONS method of the GR_TABLE object. Next, add the aggregation by calling the ADD_AGGREGATION method of the GR_SORTS object. We also need to modify the call to ADD_SORT to set the SUBTOTAL = ABAP_TRUE.
    report zalvom_demo1. data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions. data: gr_display type ref to cl_salv_display_settings. data: gr_columns type ref to cl_salv_columns_table. data: gr_column type ref to cl_salv_column_table. data: gr_sorts type ref to cl_salv_sorts. data: gr_agg type ref to cl_salv_aggregations.
    data: color type lvc_s_colo.
    start-of-selection. select * into table ispfli from spfli. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). gr_functions = gr_table->get_functions( ). gr_functions->set_all( abap_true ). gr_display = gr_table->get_display_settings( ). gr_display->set_striped_pattern( cl_salv_display_settings=>true ). gr_display->set_list_header( 'This is the heading' ). gr_columns = gr_table->get_columns( ). gr_column ?= gr_columns->get_column( 'CITYTO' ). gr_column->set_long_text( 'This is long text' ). gr_column->set_medium_text( 'This is med text' ). gr_column->set_short_text( 'This is sh' ). gr_column ?= gr_columns->get_column( 'CITYFROM' ). color-col = '6'. color-int = '1'. color-inv = '0'. gr_column->set_color( color ). gr_sorts = gr_table->get_sorts( ). gr_sorts->add_sort( columnname = 'CITYTO' subtotal = abap_true ). gr_agg = gr_table->get_aggregations( ). gr_agg->add_aggregation( 'DISTANCE' ). 
    ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 11
    gr_table->display( ). 
    ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 12
    Filters – CL_SALV_FILTERS
    Using the CL_SALV_FILTERS class we can setup some filters for the data in our ALV GRID. Create the object reference variable and receive the object using the GET_FILTERS method of the GR_TABLE object, and then simply called the method ADD_FILTER with the parameters.
    report zalvom_demo1. data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions. data: gr_display type ref to cl_salv_display_settings. data: gr_columns type ref to cl_salv_columns_table. data: gr_column type ref to cl_salv_column_table. data: gr_sorts type ref to cl_salv_sorts. data: gr_agg type ref to cl_salv_aggregations. data: gr_filter type ref to cl_salv_filters.
    data: color type lvc_s_colo.
    start-of-selection. select * into table ispfli from spfli. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). gr_functions = gr_table->get_functions( ). gr_functions->set_all( abap_true ). gr_display = gr_table->get_display_settings( ). gr_display->set_striped_pattern( cl_salv_display_settings=>true ). gr_display->set_list_header( 'This is the heading' ). gr_columns = gr_table->get_columns( ). gr_column ?= gr_columns->get_column( 'CITYTO' ). gr_column->set_long_text( 'This is long text' ). gr_column->set_medium_text( 'This is med text' ). gr_column->set_short_text( 'This is sh' ). gr_column ?= gr_columns->get_column( 'CITYFROM' ). color-col = '6'. color-int = '1'. color-inv = '0'. gr_column->set_color( color ). gr_sorts = gr_table->get_sorts( ). gr_sorts->add_sort( columnname = 'CITYTO' subtotal = abap_true ). gr_agg = gr_table->get_aggregations( ). gr_agg->add_aggregation( 'DISTANCE' ). 
    ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 13
    gr_filter = gr_table->get_filters( ). gr_filter->add_filter( columnname = 'CARRID' low = 'LH' ). gr_table->display( ). 
    ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 14
    Layouts – CL_SALV_LAYOUT
    If you want to allow the user to manage layouts of the ALV grid, you must use the class CL_SALV_LAYOUT. Create the object reference variable and receive the object using the GET_LAYOUT method of the GR_TABLE object. Then simply call the method SET_KEY with the parameters and set the save restriction using the SET_SAVE_RESTRICTION method.
    report zalvom_demo1. data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions. data: gr_display type ref to cl_salv_display_settings. data: gr_columns type ref to cl_salv_columns_table. data: gr_column type ref to cl_salv_column_table. data: gr_sorts type ref to cl_salv_sorts. data: gr_agg type ref to cl_salv_aggregations. data: gr_filter type ref to cl_salv_filters. data: gr_layout type ref to cl_salv_layout. data: color type lvc_s_colo. data: key type salv_s_layout_key. start-of-selection. select * into table ispfli from spfli. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). gr_functions = gr_table->get_functions( ). gr_functions->set_all( abap_true ). gr_display = gr_table->get_display_settings( ). gr_display->set_striped_pattern( cl_salv_display_settings=>true ). gr_display->set_list_header( 'This is the heading' ). gr_columns = gr_table->get_columns( ). gr_column ?= gr_columns->get_column( 'CITYTO' ). gr_column->set_long_text( 'This is long text' ). gr_column->set_medium_text( 'This is med text' ). gr_column->set_short_text( 'This is sh' ). gr_column ?= gr_columns->get_column( 'CITYFROM' ). color-col = '6'. color-int = '1'. color-inv = '0'. gr_column->set_color( color ). gr_sorts = gr_table->get_sorts( ). gr_sorts->add_sort( columnname = 'CITYTO' subtotal = abap_true ). gr_agg = gr_table->get_aggregations( ). 
    ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 15
    gr_filter = gr_table->get_filters( ). gr_layout = gr_table->get_layout( ). gr_layout->set_key( ). gr_table->display( ). gr_agg->add_aggregation( 'DISTANCE' ). gr_filter->add_filter( columnname = 'CARRID' low = 'LH' ). key-report = sy-repid. key gr_layout->set_save_restriction( cl_salv_layout=>restrict_none ).
    Related Content
         • Help - ALV Object Model
         • Utilizing the New ALV Object Model
         • SDN ABAP Forum
    ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 16
    Disclaimer and Liability Notice
    This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.
    SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk.
    SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.
    Regards,
    Mandeep.
    Note: Award points if contents are useful.

  • How to implement classes and methods in badi's ?

    how to implement classes and methods in badi's? and where i have to write the code based on the requirement?can anyone explain me briefly?

    Hi
    Every BADI by default Implements an INTERFACE which already contains some methods with parameters.
    So you have to find the relavenet method based on the related paramters (by checking the fields in that paramters) you have to double click on the method and to write the code.
    see the doc
    DEFINING THE BADI
    1) execute Tcode SE18.
    2) Specify a definition Name : ZBADI_SPFLI
    3) Press create
    4) Choose the attribute tab. Specify short desc for badi.. and specify the type :
    multiple use.
    5) Choose the interface tab
    6) Specify interface name: ZIF_EX_BADI_SPFLI and save.
    7) Dbl clk on interface name to start class builder . specify a method name (name,
    level, desc).
    Method level desc
    Linese;ection instance methos some desc
    8) place the cursor on the method name desc its parameters to define the interface.
    Parameter type refe field desc
    I_carrid import spfli-carrid some
    I_connid import spefi-connid some
    9) save , check and activate…adapter class proposed by system is
    ZCL_IM_IM_LINESEL is genereated.
    IMPLEMENTATION OF BADI DEFINITION
    1) EXECUTE tcode se18.choose menuitem create from the implementation menubar.
    2) Specify aname for implementation ZIM_LINESEL
    3) Specify short desc.
    4) Choose interface tab. System proposes a name fo the implementation class.
    ZCL_IM_IMLINESEL which is already generarted.
    5) Specify short desc for method
    6) Dbl clk on method to insert code..(check the code in “AAA”).
    7) Save , check and activate the code.
    Some useful URL
    http://www.esnips.com/doc/e06e4171-29df-462f-b857-54fac19a9d8e/ppt-on-badis.ppt
    http://www.esnips.com/doc/10016c34-55a7-4b13-8f5f-bf720422d265/BADIs.pdf
    http://www.esnips.com/doc/43a58f51-5d92-4213-913a-de05e9faac0d/Business-Addin.doc
    http://www.esnips.com/doc/1e10392e-64d8-4181-b2a5-5f04d8f87839/badi.doc
    www.sapgenie.com/publications/saptips/022006%20-%20Zaidi%20BADI.pdf
    http://www.sapdevelopment.co.uk/enhance/enhance_badi.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/04/f3683c05ea4464e10000000a114084/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/e6/d54d3c596f0b26e10000000a11402f/content.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/c2/eab541c5b63031e10000000a155106/frameset.htm
    Now write a sample program to use this badi method..
    Look for “BBB” sample program.
    “AAA”
    data : wa_flights type sflight,
    it_flights type table of sflight.
    format color col_heading.
    write:/ 'Flight info of:', i_carrid, i_connid.
    format color col_normal.
    select * from sflight
    into corresponding fields of table it_flights
    where carrid = i_carrid
    and connid = i_connid.
    loop at it_flights into wa_flights.
    write:/ wa_flights-fldate,
    wa_flights-planetype,
    wa_flights-price currency wa_flights-currency,
    wa_flights-seatsmax,
    wa_flights-seatsocc.
    endloop.
    “BBB”
    *& Report ZBADI_TEST *
    REPORT ZBADI_TEST .
    tables: spfli.
    data: wa_spfli type spfli,
    it_spfli type table of spfli with key carrid connid.
    *Initialise the object of the interface.
    data: exit_ref type ref to ZCL_IM_IM_LINESEL,
    exit_ref1 type ref to ZIF_EX_BADISPFLI1.
    selection-screen begin of block b1.
    select-options: s_carr for spfli-carrid.
    selection-screen end of block b1.
    start-of-selection.
    select * from spfli into corresponding fields of table it_spfli
    where carrid in s_carr.
    end-of-selection.
    loop at it_spfli into wa_spfli.
    write:/ wa_spfli-carrid,
    wa_spfli-connid,
    wa_spfli-cityfrom,
    wa_spfli-deptime,
    wa_spfli-arrtime.
    hide: wa_spfli-carrid, wa_spfli-connid.
    endloop.
    at line-selection.
    check not wa_spfli-carrid is initial.
    create object exit_ref.
    exit_ref1 = exit_ref.
    call method exit_ref1->lineselection
    EXPORTING
    i_carrid = wa_spfli-carrid
    i_connid = wa_spfli-connid.
    clear wa_spfli.
    Reward points for useful Answers
    Regards
    Anji
    Message was edited by:
            Anji Reddy Vangala

  • Access to class-attribute by Interface-reference

    Hi OO-Gurus,
    I use an implementation of BADI ME_PROCESS_REQ_CUST to fill and handle user-defined fields in the MM-Purchase-Requisition, method IF_EX_ME_PROCESS_REQ_CUST~OPEN.
    There I  use a reference variable which refers to an interface (type ref to IF_PURCHASE_REQUISITION_ITEM) to access the item-object. My problem is that I need to have access to the class-attribute my_state. The corresponding class lcl_req_item is defined locally (LMEREQF01). So I can’t use  a reference variable with reference to this class (so widening cast using the interface-reference is not possible) .. Does anyone know a trick how to access the class-attribute anyway?
    Coding:
      data:  l_item_list       TYPE MMPUR_REQUISITION_ITEMS,
               l_item             TYPE MMPUR_REQUISITION_ITEM,
               l_item_akt       TYPE mereq_item,
               l_item_ref        TYPE ref to IF_PURCHASE_REQUISITION_ITEM. 
      l_item_list = im_header->get_items().
      loop at l_item_list into l_item.
        l_item_akt = l_item-item->get_data( ).
        l_item_ref = l_item-item.
      endloop.
    (Debugging the code, I manage by doubleclicking the fieldcontent of l_item_ref (e.g ) to show the content of the class-attribute my_state. This works only if the field “Interface” in the Debugger is empty because then I see the attributes of the class. If the field Interface is filled with “IF_PURCHASE_REQUISITION_ITEM”, there aren’t any attributes shown.)
    Thanks in advance for your kind help!!
    Nicole

    Hello Nicole
    The following sample coding shows you how to solve your problem. Please do not ask me how I came across this solution.
    However, if you are studying it carefully you may stumble across a most beautiful property of field-symbols as I did.
    METHOD if_ex_me_process_req_cust~open.
      DATA: l_item_list TYPE mmpur_requisition_items,
      l_item TYPE mmpur_requisition_item,
      l_item_akt TYPE mereq_item,
      l_item_ref TYPE REF TO if_purchase_requisition_item.
      DATA:
        ld_attr         TYPE string,
        lo_obj          TYPE REF TO object.
      FIELD-SYMBOLS:
        <lo_lcl>        TYPE ANY,
        <ls_item>       TYPE mereq_item,
        <ls_itemx>      TYPE mereq_itemx.
      l_item_list = im_header->get_items( ).
      LOOP AT l_item_list INTO l_item.
        l_item_akt = l_item-item->get_data( ).
        l_item_ref = l_item-item.
        lo_obj     ?= l_item-item.  " casting to root object !!!!!
        ld_attr = 'MY_STATE'.
        ASSIGN lo_obj->(ld_attr) TO <lo_lcl>.
        ld_attr = 'MY_STATE->ITEM'.
        ASSIGN lo_obj->(ld_attr) TO <ls_item>.
    "    ASSIGN l_item_ref->(ld_attr) TO <ls_item>.  " does not work...
        ld_attr = 'MY_STATE->ITEMX'.
        ASSIGN lo_obj->(ld_attr) TO <ls_itemx>.
      ENDLOOP.
      " NOTE: data definition of local class lcl_req_item_state (fg MEREQ)
    **    DATA:  item           TYPE mereq_item,
    **           itemx          TYPE mereq_itemx,
    **           header         TYPE REF TO lcl_req_header,
    **           ref_item       TYPE REF TO lcl_req_item,
    **           acct_container TYPE REF TO lcl_acct_container,
    **           source         TYPE REF TO cl_source_of_supply_mm,
    **           release_state  TYPE REF TO cl_release_state_mm,
    **           text_manager   TYPE REF TO lcl_text_manager,
    **           bom            TYPE REF TO lcl_bom,
    **           funds_mgt_active TYPE mmpur_bool VALUE mmpur_no,
    **           aktyp          TYPE aktyp,
    **           no_auth        TYPE mmpur_bool VALUE mmpur_no,
    **           release_op     type mmpur_bool value mmpur_no,
    **           persistent     TYPE mmpur_bool VALUE mmpur_no,
    **           checked        TYPE mmpur_bool VALUE mmpur_no,
    **           manual_configuration TYPE mmpur_bool,
    **           input_buffer_changed TYPE mmpur_bool VALUE mmpur_no,
    **           changed        TYPE mmpur_bool,
    **           broken_rules   TYPE lty_mask,
    **           referenced_rules TYPE lty_mask,
    **           chp_changes    TYPE mmchp_chp_list,
    **           dcm_manager    TYPE REF TO if_revision_manager_dcm,
    **           "DCM Retrofit
    **           rel_state_after_release TYPE REF TO cl_release_state_mm,
    **           "DCM Retrofit
    **           chdoc_container TYPE REF TO lcl_chdoc_container,
    **           "DCM Retrofit
    **           service_changed TYPE mmpur_bool,
    **           "DCM Retrofit
    **           determinants   TYPE lty_item_determinants.
    ENDMETHOD.
    Regards
      Uwe

Maybe you are looking for