Alv --- handle_data_change

hi...
I am using a alv to create new entries in a table.I ma making use ofthe following
CLASS lcl_grid_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS:
        handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
          IMPORTING
            er_data_changed
            e_onf4
            e_onf4_before
            e_onf4_after
            e_ucomm
            sender.
ENDCLASS.                
everything works fine ....
but in the alv i have a few fields with the value help.
when i try to change a field ... or add a value to this field using the drop down ..... it gives me a dump....
how can i get these values when i click on drop down or press f4.
how can i solve this problem
Thanks in avdvance

hi
check these programs BCALV_EDIT_01 and BCALV_TEST_GRID_EVENTS
hope this helps
regards
Aakash Banga

Similar Messages

  • ALV wrong row_id in  METHOD handle_data_changed when grid is sorted

    Hi everybody,
    we've made a small data maintenance report with the ALV grid using the class CL_GUI_ALV_GRID.
    My problem is the behaviour of ALV, when the grid is autosorted on a field, which is changed by a user. Within the hanlde method of the event data_changed I get the internal table er_data_changed->mt_good_cells containing entries (of the type lvc_s_modi) for every field which was changed.  The field ROW_ID containes the row id of the internal table of the grid, in which the change was made by the user. This ROW_ID can be wrong, when the change the user made leads to an autosort of the table, which sorts the table in a different order. When you then access the ALV-table by the row-id you get the wrong, not changed row back.
    Here a short extract of the code:
    METHOD handle_data_changed.
        LOOP AT er_data_changed->mt_good_cells INTO ls_good.
           READ TABLE gt_alv INDEX ls_good-row_id ASSIGNING <l_line_of_alv>.
    <i>*      wrong line of the ALV grid is in <l_line_of_alv></i>
        ENDLOOP.
    ENDMETHOD.
    Have you any idea, how this can be avoided?
    Is it possible to disable the autosort <b>before</b> handle_changed is triggert and to enable it afterwards again?
    I'm thankful for any idea.
    Regards,
    Horst

    I don't do it this way myself.
    I use  a "generalized"  ALV class using a dynamic table --then the latest state of the GRID data is always in your dynamic table <dyn_table>. I have a copy of the original as well in <orig_table>.
    This means at either event ON DATA CHANGED or ON DATA CHANGED FINISHED I've got the latest state of the table even if sorted and the last cell(s) / row(s) selected
    Here's the code
    INCLUDE ZZJIMBOXX_INCL.
    Generic ALV class etc  for use as INCLUDE  Jimbo 2007.
    DEFINE col_name.
    READ TABLE it_fldcat INTO wa_it_fldcat INDEX &1.
          wa_it_fldcat-coltext = &2.
          wa_it_fldcat-outputlen = &3.
          modify it_fldcat from wa_it_fldcat index &1.
    END-OF-DEFINITION.
    DEFINE toolbar_funcs.
       CLEAR ls_toolbar.
        MOVE 0 TO ls_toolbar-butn_TYPE.
        MOVE &1 TO ls_toolbar-function.
        MOVE SPACE TO ls_toolbar-disabled.
        MOVE &2 TO ls_toolbar-icon.
        MOVE &3 TO ls_toolbar-quickinfo.
        APPEND ls_toolbar TO e_object->mt_toolbar.
    END-OF-DEFINITION.
    INCLUDE  <icon>.
    FIELD-SYMBOLS :
       <fs1>          TYPE STANDARD TABLE,
       <fs0>          TYPE STANDARD TABLE,
       <dyn_table>    TYPE STANDARD TABLE,
       <orig_table>   TYPE STANDARD TABLE,
       <dyn_wa>      TYPE ANY.
    CLASS  zcl_alv_test DEFINITION DEFERRED.
    DATA:
       z_object           TYPE REF TO zcl_alv_test.  "Instantiate our class
    Attributes
    DATA:
            it_fldcat          TYPE lvc_t_fcat,
            i_gridtitle        TYPE lvc_title,
            wa_it_fldcat       TYPE lvc_s_fcat,
            new_table          TYPE REF TO DATA,
            dy_table           TYPE REF TO DATA,
            inserted_tab       TYPE lvc_t_moce,
            deleted_tab        TYPE LVC_T_MOCE,
            changed_tab        TYPE REF TO DATA,
            is_layout          TYPE LVC_S_LAYO,
            modified_cells_tab TYPE LVC_T_MODI,
            dy_line            TYPE REF TO DATA.
    CLASS zcl_alv_test DEFINITION.
      PUBLIC SECTION.
        METHODS:
         constructor
            IMPORTING
              z_object TYPE REF TO zcl_alv_test,
         display_grid
          IMPORTING
             g_outtab TYPE STANDARD TABLE
             g_fldcat TYPE lvc_t_fcat
           CHANGING
             it_fldcat TYPE lvc_t_fcat
             GT_OUTTAB TYPE STANDARD TABLE,
          change_title
           IMPORTING
             i_gridtitle TYPE lvc_title,
          refresh_grid,
          set_cursor
           IMPORTING
             row_id      TYPE lvc_s_row
             column_id   TYPE lvc_s_col
             row_no      TYPE lvc_s_roid,
          build_dynamic_structures
           IMPORTING
             my_line TYPE ANY
             calling_program TYPE sy-repid
           EXPORTING
             dy_table TYPE REF TO DATA
           CHANGING
             it_fldcat TYPE lvc_t_fcat .
      PRIVATE SECTION.
    Attributes
        DATA:
         lr_rtti_struc           TYPE REF TO cl_abap_structdescr,
         zog                     LIKE LINE OF lr_rtti_struc->components,
         zogt                    LIKE table of zog,
         struct_grid_lset        TYPE lvc_s_layo,
         e_row                   TYPE lvc_s_row,
         e1_row                  TYPE i,
         e_value                 TYPE c,
         e1_col                  TYPE i,
         e_column                TYPE lvc_s_col,
         es_rowid                TYPE lvc_s_roid,
         es_row_id               TYPE LVC_S_ROW,
         es_col_id               TYPE LVC_S_COL,
         es_row_no               TYPE lvc_s_roid,
         grid_container1         TYPE REF TO cl_gui_custom_container,
         grid1                   TYPE REF TO cl_gui_alv_grid,
         ls_layout               TYPE kkblo_layout,
         lt_fieldcat_wa          TYPE kkblo_fieldcat,
         gt_outtab               TYPE REF TO DATA,
         l_mode                  TYPE raw4,
         celltab                 TYPE lvc_t_styl,
         wa_celltab              TYPE lvc_s_styl,
         lt_fieldcat             TYPE kkblo_t_fieldcat,
         l_tabname               TYPE slis_tabname,
         ls_toolbar              TYPE stb_button,
         caller                  TYPE sy-repid,
         g_outtab1               TYPE REF TO DATA,
         g_fldcat1                TYPE REF TO DATA.
    Event Receivers - These methods are entered
    when the specified event occurs
        EVENTS: before_user_command.
        METHODS:
         on_user_command
            FOR EVENT before_user_command OF cl_gui_alv_grid
            IMPORTING
              e_ucomm
              sender,
         on_toolbar
            FOR EVENT toolbar OF cl_gui_alv_grid
            IMPORTING
              e_object
              e_interactive,
         on_dubbelklik
            FOR EVENT double_click OF cl_gui_alv_grid
            IMPORTING
               e_row
               e_column
               es_row_no,
        handle_data_changed
            FOR EVENT data_changed OF cl_gui_alv_grid
            IMPORTING
              er_data_changed,
         handle_data_changed_finished
            FOR EVENT data_changed_finished OF cl_gui_alv_grid
            IMPORTING
              e_modified
              et_good_cells,
    Rest of the methods
         process,
         dubbelklik
            IMPORTING
               e_row       TYPE lvc_s_row
               e_column    TYPE lvc_s_col
               es_row_no   TYPE lvc_s_roid,
         return_structure
            IMPORTING
              my_line      TYPE ANY,
         create_dynamic_fcat
            EXPORTING
              it_fldcat    TYPE lvc_t_fcat,
         create_dynamic_table
            IMPORTING
               it_fldcat   TYPE lvc_t_fcat
            EXPORTING
              dy_table     TYPE REF TO DATA,
         download_to_excel,
         refresh.
    ENDCLASS.                    "zcl_alv_test DEFINITION
    Implementation definition
    CLASS zcl_alv_test IMPLEMENTATION.
    Constructor
    create our reference / instance to cl_gui_alv_grid
      METHOD constructor.
        CREATE OBJECT grid_container1
            EXPORTING
               container_name = 'CCONTAINER1'.
        CREATE OBJECT  grid1
           EXPORTING
              i_parent = grid_container1.
    Set event handlers
        SET HANDLER z_object->on_user_command for grid1.
        SET HANDLER z_object->on_toolbar for grid1.
        SET HANDLER Z_OBJECT->handle_data_changed FOR grid1.
        SET HANDLER Z_OBJECT->handle_data_changed_finished FOR grid1.
        SET HANDLER Z_OBJECT->on_dubbelklik FOR grid1.
        CALL METHOD grid1->register_edit_event
          EXPORTING
            i_event_id = cl_gui_alv_grid=>mc_evt_enter.
      ENDMETHOD.                    "constructor
    Rest of the methods
      METHOD on_dubbelklik.
        CALL METHOD me->dubbelklik
          EXPORTING
            e_row     = e_row
            e_column  = e_column
            es_row_no = es_row_no.
      ENDMETHOD.                       "on_dubbelklik
      METHOD set_cursor.
        CALL METHOD grid1->set_current_cell_via_id
        EXPORTING
            is_row_id     = row_id
            is_column_id  = column_id
            is_row_no  =    row_no.
      ENDMETHOD.
      METHOD  handle_data_changed.
        call method grid1->get_current_cell
          IMPORTING
            e_row     = e1_row
            e_value   = e_value
            e_col     = e1_col
            es_row_id = es_row_id
            es_col_id = es_col_id
            es_row_no = es_row_no.
        changed_tab  = er_data_changed->mp_mod_rows.
        inserted_tab = er_data_changed->mt_inserted_rows.
        deleted_tab  = er_data_changed->mt_deleted_rows.
        modified_cells_tab = er_data_changed->mt_mod_cells.
        PERFORM data_changed  IN PROGRAM (caller) IF FOUND
           USING changed_tab
                 inserted_tab
                 deleted_tab
                 modified_cells_tab.
      ENDMETHOD.                    "handle_data_changed
      METHOD handle_data_changed_finished.
      ENDMETHOD.                    "handle_data_changed_finished
      METHOD return_structure.
        lr_rtti_struc ?= cl_abap_structdescr=>DESCRIBE_BY_DATA( my_line ).
        zogt[]  = lr_rtti_struc->components.
      ENDMETHOD.                    "return_structure
      METHOD create_dynamic_fcat.
        LOOP AT zogt INTO zog.
          CLEAR wa_it_fldcat.
          wa_it_fldcat-fieldname = zog-name .
          wa_it_fldcat-dataTYPE = zog-TYPE_kind.
          wa_it_fldcat-intTYPE = zog-TYPE_kind.
          wa_it_fldcat-intlen = zog-length.
          wa_it_fldcat-decimals = zog-decimals.
          wa_it_fldcat-coltext = zog-name.
          wa_it_fldcat-lowercase = 'X'.
          APPEND wa_it_fldcat TO it_fldcat .
        ENDLOOP.
      ENDMETHOD.                    "create_dynamic_fcat
      METHOD  download_to_excel.
        assign g_outtab1->* to <fs0>.
        assign g_fldcat1->* to <fs1>.
        CALL FUNCTION  'LVC_TRANSFER_TO_KKBLO'
         EXPORTING
           it_fieldcat_lvc   = <fs1>
        is_layout_lvc     = m_cl_variant->ms_layout
            is_tech_complete  = ' '
         IMPORTING
           es_layout_kkblo   = ls_layout
           et_fieldcat_kkblo = lt_fieldcat.
        LOOP AT lt_fieldcat INTO lt_fieldcat_wa.
          CLEAR lt_fieldcat_wa-tech_complete.
          IF lt_fieldcat_wa-tabname IS initial.
            lt_fieldcat_wa-tabname = '1'.
            MODIFY lt_fieldcat FROM lt_fieldcat_wa.
          ENDIF.
          l_tabname = lt_fieldcat_wa-tabname.
        ENDLOOP.
        CALL FUNCTION 'ALV_XXL_CALL'
          EXPORTING
            i_tabname           = l_tabname
            is_layout           = ls_layout
            it_fieldcat         = lt_fieldcat
            i_title             = sy-title
          TABLES
            it_outtab           = <fs0>
          EXCEPTIONS
            fatal_error         = 1
            no_display_possible = 2
            others              = 3.
        IF  sy-subrc <> 0.
          message id sy-msgid TYPE 'S' number sy-msgno
                 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
      ENDMETHOD.                    "download_to_excel
      METHOD change_title.
        CALL METHOD grid1->set_gridtitle
          EXPORTING
            i_gridtitle = i_gridtitle.
      ENDMETHOD.                    "CHANGE_TITLE
      METHOD create_dynamic_table.
        CALL METHOD cl_alv_table_create=>create_dynamic_table
          EXPORTING
            it_fieldcatalog = it_fldcat
          IMPORTING
            ep_table        = dy_table.
      ENDMETHOD.                    "create_dynamic_table
      METHOD build_dynamic_structures.
        caller = calling_program.
        CALL METHOD me->return_structure
          EXPORTING
            my_line = my_line.
        CALL METHOD me->create_dynamic_fcat
          IMPORTING
            it_fldcat = it_fldcat.
        CALL METHOD me->create_dynamic_table
          EXPORTING
            it_fldcat = it_fldcat
          IMPORTING
            dy_table  = dy_table.
      ENDMETHOD.                    "build_dynamic_structures
      METHOD display_grid.
        GET REFERENCE OF g_outtab INTO g_outtab1.
        GET REFERENCE OF g_fldcat INTO g_fldcat1.
        struct_grid_lset-edit = 'X'. "To enable editing in ALV
        struct_grid_lset-grid_title = 'TEST ALV USE generic class'.
        struct_grid_lset-ctab_fname = 'T_CELLCOLORS'.
        struct_grid_lset-stylefname = 'CELLTAB'.
        CALL METHOD grid1->set_ready_for_input
          EXPORTING
            i_ready_for_input = '1'.
        CALL METHOD grid1->set_table_for_first_display
          EXPORTING
            is_layout       = struct_grid_lset
          CHANGING
            it_outtab       = gt_outtab
            it_fieldcatalog = it_fldcat.
      ENDMETHOD.                    "display_grid
      METHOD on_user_command.
        CASE e_ucomm.
          WHEN 'EXIT'.
            LEAVE PROGRAM.
          WHEN 'EXCEL'.
            CALL METHOD me->download_to_excel.
          WHEN 'SAVE'.
          WHEN 'PROC'.
            CALL METHOD me->process.
          WHEN 'REFR'.
            CALL METHOD me->refresh.
        ENDCASE.
      ENDMETHOD.  "on_user_command
      METHOD on_toolbar.
    customize this section with your own Buttons
    When a button is pressed method ON_USER_COMMAND is entered
       toolbar_funcs 'EXIT'  icon_system_end            'Click2exit'.
       toolbar_funcs 'SAVE'  icon_system_save           'Savedata'.
       toolbar_funcs 'EDIT'  icon_toggle_display_change 'Edit data'.
       toolbar_funcs 'PROC'  icon_businav_process       'Process'.
       toolbar_funcs 'EXCEL' icon_xxl                   'Excel'.
       toolbar_funcs 'REFR'  icon_refresh               'Refresh'.
       ENDMETHOD.                    "on_toolbar
      METHOD refresh_grid.
        CALL METHOD cl_gui_cfw=>flush.
        CALL METHOD grid1->refresh_table_display.
      ENDMETHOD.                    "refresh_grid
      METHOD refresh.
        PERFORM refresh IN PROGRAM (caller) IF FOUND.
      ENDMETHOD.                    "refresh
      METHOD process.
        PERFORM process IN PROGRAM (caller) IF FOUND.
      ENDMETHOD.                    "process
      METHOD dubbelklik.
        perform dubbelklik IN PROGRAM (caller) IF FOUND
           USING e_row
                 e_column
                 es_row_no.
      ENDMETHOD.                    "dubbelklik
    ENDCLASS.                    "zcl_alv_test IMPLEMENTATION
    Now for example I can use this program to fill a grid
    Program  ZJIMBOTESTX.
    INCLUDE ZZJIMBOXX_INCL.  "Code is above
    TABLES : SPFLI.
    TYPES:  BEGIN OF s_elements.
            INCLUDE  STRUCTURE spfli..
    TYPES: END OF    s_elements.
    DATA:
           t_elements         TYPE TABLE OF s_elements,  "refers to our ITAB
           my_line            TYPE s_elements.
    START-OF-SELECTION.
    CALL SCREEN 100.
    END-OF-SELECTION.
    MODULE status_0100 OUTPUT.
    CREATE OBJECT z_object
          EXPORTING z_object = z_object.
    CALL METHOD z_object->build_dynamic_structures
         EXPORTING
           my_line = my_line
           calling_program = sy-repid
         IMPORTING
           dy_table = dy_table
         CHANGING
           it_fldcat = it_fldcat.
    Here before displaying you can change the field catalog to
    adjust your own column names.
    *col_name  col-nr 'your name' output length.
       col_name 2 'Carrier' 5.
       col_name 3 'Flt' 4.
       col_name 4 'Dep Ctry' 8.
       col_name 5 'Dep City'  8.
       col_name 6 'Airport'  6.
    fill dynmic table and display
    PERFORM populate_dynamic_itab.
    is_layout-zebra = 'X'.
    CALL METHOD z_object->display_grid
        EXPORTING
          g_outtab = <dyn_table>
          g_fldcat = it_fldcat
         CHANGING
          it_fldcat = it_fldcat
          gt_outtab = <dyn_table>.
      SET PF-STATUS '0001'.
      SET TITLEBAR '000'.
    ENDMODULE.
    MODULE user_command_0100 INPUT.
      CASE sy-ucomm.
        WHEN 'BACK'.
          LEAVE PROGRAM.
        WHEN 'EXIT'.
          LEAVE PROGRAM.
        WHEN 'RETURN'.
          LEAVE PROGRAM.
        WHEN OTHERS.
      ENDCASE.
    ENDMODULE.
    FORM populate_dynamic_itab.
    ASSIGN dy_table->* TO <dyn_table>.
    CREATE DATA dy_line LIKE LINE OF <dyn_table>.
    ASSIGN dy_line->* TO <dyn_wa>.
    SELECT *
           UP TO 200 rows
           FROM SPFLI
           INTO  CORRESPONDING FIELDS OF TABLE <dyn_table>.
    save a copy (original table). Use same fcat as ist table.
    create 2nd Dyn table to hold original data
    CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
             it_fieldcatalog = it_fldcat
          IMPORTING
             ep_table = dy_table.
    ASSIGN dy_table->* TO <orig_table>.
    CREATE DATA dy_line LIKE LINE OF <orig_table>.
    ASSIGN dy_line->* TO <dyn_wa>.
      <orig_table> = <dyn_table>.
    ENDFORM.
    FORM DATA_CHANGED
       USING
         changed_tab
         inserted_tab
         deleted_tab
         modified_cells_tab.
    ENDFORM.
    FORM process.
    Orig table is in dynamic table <orig_table>
    ALV GRID changed table is in <dyn_table>.
    Loop AT <orig_table>  INTO  <dyn_wa>.
      Do what you want
    end
    ENDLOOP.
    ENDFORM.
    FORM refresh.
    change data for example delete some lines.
    *DELETE  <dyn_table> from 1 to 16.
    CALL METHOD z_object->refresh_grid.
    ENDFORM.
    FORM dubbelklik
         USING
            e_row       TYPE lvc_s_row
            e_column    TYPE lvc_s_col
            es_row_no   TYPE  lvc_s_roid.
         SET TITLEBAR '001'.
         i_gridtitle = 'Grid Title Changed'.
         CALL METHOD  z_object->change_title
             EXPORTING
             i_gridtitle = i_gridtitle.
        PERFORM refresh.
    CALL METHOD z_object->set_cursor
       EXPORTING
           row_id     = e_row
           column_id  = e_column
            row_no  = es_row_no.
    ENDFORM.
    Now yoy can sort / delete / insert / or wahtever.
    The code is pretty general so it should cover all your needs.
    All your application ever needs to do is simply define a structure and fill it.The class will generate the dynamic table and FCAT.
    Modify the class to rmeove toolbar buttons wuou don't use or need.
    This class aslo includes a download to EXCEL  with column headings which I often find useful.
    I don't bother with mt_good cells etc etc as you can manipulate the <dyn_table> directly.
    Cheers
    Jimbo

  • ALV Grid handle_data_changed error?

    Hi all,
    I've been working on an implementation of an ALV grid in which the user has the ability to edit certain fields. I want to capture those changed values in my program. I've implemented a lcl_event_handler class and I've defined a method within the class to process the data_changed event. I've also defined and instantiated a handle to the class. I've also registered the mc_evt_enter event with the ALV grid. When I run the grid and change a value the data_changed event fires as you would expect. The trouble is an error message is returned which says "Field ty_pan-gsmng is not defined in the ABAP dictionary". I pass a reference to a custom type I defined within the program to the ALV grid...you guessed the name...ty_plan. One of the editable fields within the custome type is gsmng. I'm curious...do I have to pass a reference to a table or type defined within the ABAP dictionary or can I get this code to work with my custom type?
    Thanks in advance...Mat.

    As follows:
    DATA: obj_handler TYPE REF TO lcl_event_handler.
    CLASS lcl_event_handler IMPLEMENTATION.
      METHOD handle_data_changed.
        DATA: ls_good TYPE lvc_s_modi.
        LOOP AT er_data_changed->mt_good_cells INTO ls_good.
          CASE ls_good-fieldname.
    Order Quantity
            WHEN 'GSMNG'.
    Order Start
            WHEN 'PSTTR'.
    Order Finish
            WHEN 'PEDTR'.
    All other fields
            WHEN OTHERS.
          ENDCASE.
        ENDLOOP.
      ENDMETHOD. 
    Call the method to display the data in ALV grid
        CALL METHOD obj_alv_grid->set_table_for_first_display
          EXPORTING
            is_layout                     = wa_layo
            i_structure_name              = 'ty_plan'
            is_variant                    = gs_variant
            i_save                        = gv_save_variant
          CHANGING
            it_outtab                     = pt_plan
            it_fieldcatalog               = pt_fieldcat
            it_sort                       = lt_sort
          EXCEPTIONS
            invalid_parameter_combination = 1
            program_error                 = 2
            OTHERS                        = 3.
      CALL METHOD obj_alv_grid->set_ready_for_input
        EXPORTING
          i_ready_for_input = 1.
      CALL METHOD obj_alv_grid->register_edit_event
        EXPORTING
          i_event_id = cl_gui_alv_grid=>mc_evt_enter.
      CALL METHOD obj_alv_grid->register_edit_event
        EXPORTING
          i_event_id = cl_gui_alv_grid=>mc_evt_modified.
    CREATE OBJECT obj_handler.
    SET HANDLER obj_handler->handle_data_changed FOR obj_alv_grid.

  • Alv  :  how can i delete the checkbox on  handle_data_changed ?

    hello
    Due to field checsk  (like field empty) in "HANDLE_DATA_CHANGED" ,
    (  CALL METHOD ER_DATA_CHANGED->DISPLAY_PROTOCOL.)
    i notice the user "field empty"   , but also i want to delete his mark in the checkbox  ,.
    all of my tests to delete the checkbox failed .
    i tried  :
             CALL METHOD ER_DATA_CHANGED->modify_cell
                 EXPORTING i_row_id    = LS_GOOD-ROW_ID
                           i_fieldname = LS_GOOD-fieldname   " 'CHECKBOX'
                           i_value     = '' .
      or 
           READ TABLE IT_BSIK INDEX LS_GOOD-ROW_ID INTO WA_BSIK.
           WA_BSIK-checkbox = ' '.
          Modify IT_BSIK from WA_BSIK index 1 .
    What is the right way to erase the checkbox  ?

    You are reading with index "LS_GOOD-ROW_ID" and modifying index 1 ? Check the below corrected code...
    READ TABLE IT_BSIK INDEX LS_GOOD-ROW_ID INTO WA_BSIK.
    IF sy-subrc eq 0.
      WA_BSIK-checkbox = ' '.
      Modify IT_BSIK from WA_BSIK index LS_GOOD-ROW_ID transporting checkbox .
    Endif.

  • Here's how to do ALV (OO) with dynamic fcat, int table and editable data

    Hi everybody
    Here's a more useful approach to ALV grid with OO using dynamic table, data NOT from DDIC, dynamic FCAT and how to get changed lines from the grid when ENTER key is pressed.
    It's really not too dificult but I think this is more useful than the ever present SFLIGHT methods from the demos.
    This also defines a subclass of cl_gui_alv_grid so you can access the protected attributes / methods of that class.
    You don't need to add the class via SE24 -- done fron this ABAP.
    When you run it click Edit for the first time.
    After editing data press ENTER and the break point should bring you into the relevant method.
    Code developed on NW2004S trial version but also works on rel 6.40 on a "Real" system.
    The code should work without any changes on any system >=6.40.
    All you need to do is to create a blank screen 100 via SE51  with a custom container on it called CCONTAINER1.
    The rest of the code can just be uploaded into your system using the SE38 upload facility.
    When running the program click on the EDIT button to enable the edit functionality of the grid.
    Change your data and when you press ENTER you should get the break-point where you can see the original table and changed rows.
    This program is actually quite general as it covers Dynamic tables, building a dynamic fcat where your table fields are NOT in the DDIC, intercepting the ENTER key via using an event, and accessing the protected attributes of the cl_gui_alv_grid by defining a subclass of this class in the abap.
    I've seen various questions relating to all these functions but none in my view ever answers the questions in a simple manner. I hope this simple program will answer all these and show how using OO ALV is actually quite easy and people shouldn't be scared of using OO.
    Have fun and award points if useful.
    Cheers
    Jimbo.
    <b>PROGRAM zdynfieldcat.
    Simple test of dynamic ITAB with user defined (not ddic) fields
    Build dynamic fcat
    use ALV grid to display and edit.
    *When edit mode set to 1 toolbar gives possibility of adding and
    *deleting rows.
    *Define subclass of cl_gui_alv_grid so we can use protected attributes
    *and methods.
    Add event handler to intercept user entering data and pressing the
    *ENTER key.
    When enter key is pressed get actual value of NEW table (all rows)
    rather than just the changed data.
    *use new RTTI functionality to retrieve internal table structure
    *details.
    Create a blank screen 100  with a custom container called CCONTAINER1.
    James Hawthorne
    include <icon>.
    define  any old internal structure  NOT in DDIC
    types: begin of s_elements,
           anyfield1(20) type c,
           anyfield2(20) type c,
           anyfield3(20) type c,
           anyfield4(20) type c,
           anyfield5(11) type n,
           end of s_elements.
    types:  lt_rows  type lvc_t_roid.
    Note new RTTI functionality allows field detail retrieval
    at runtime for dynamic tables.
    data:   wa_element type s_elements ,
            wa_data type s_elements,
            c_index type sy-index,
            c_dec2 type s_elements-anyfield5,
            wa_it_fldcat type lvc_s_fcat,
            it_fldcat type lvc_t_fcat,
            lr_rtti_struc TYPE REF TO cl_abap_structdescr,    "RTTI
            lt_comp TYPE cl_abap_structdescr=>component_table,"RTTI
            ls_comp LIKE LINE OF lt_comp,                     "RTTI
            zog  like line of lr_rtti_struc->components,      "RTTI
            struct_grid_lset type lvc_s_layo,
            l_valid  type c,
            new_table type ref to data.
    field-symbols: <dyn_table> type standard table,
                   <actual_tab> type standard table,
                   <fs1> type ANY,
                   <FS2> TYPE TABLE.
    data: grid_container1 type ref to cl_gui_custom_container.
    class lcl_grid_event_receiver definition deferred.
    data: g_event_receiver type ref to lcl_grid_event_receiver.
    data: ls_modcell type LVC_S_MODI,
          stab type ref to data,
          sdog type  s_elements.      .
    class lcl_grid_event_receiver definition.
      public section.
        methods:
        handle_data_changed
             for event data_changed of cl_gui_alv_grid
                 importing er_data_changed,
           toolbar for event toolbar of cl_gui_alv_grid
                     importing e_object
                               e_interactive,
          user_command for event user_command of cl_gui_alv_grid
                     importing e_ucomm.
    endclass.
    *implementation of Grid event-handler class
    class lcl_grid_event_receiver implementation.
    method handle_data_changed.
    code whatever required after data entry.
    various possibilites here as you can get back Cell(s) changed
    columns or the entire updated table.
    Data validation is also possible here.
    perform check_data using er_data_changed.
    endmethod.
    Method for handling all creation/modification calls to the toolbar
      method toolbar.
        data : ls_toolbar type stb_button.
    Define Custom Button in the toolbar
        clear ls_toolbar.
        move 0 to ls_toolbar-butn_type.
        move 'EDIT' to ls_toolbar-function.
        move space to ls_toolbar-disabled.
        move 'Edit' to ls_toolbar-text.
        move icon_change_text to ls_toolbar-icon.
        move 'Click2Edit' to ls_toolbar-quickinfo.
        append ls_toolbar to e_object->mt_toolbar.
        clear ls_toolbar.
        move 0 to ls_toolbar-butn_type.
        move 'UPDA' to ls_toolbar-function.
        move space to ls_toolbar-disabled.
        move 'Update' to ls_toolbar-text.
        move icon_system_save to ls_toolbar-icon.
        move 'Click2Update' to ls_toolbar-quickinfo.
        append ls_toolbar to e_object->mt_toolbar.
        clear ls_toolbar.
        move 0 to ls_toolbar-butn_type.
        move 'EXIT' to ls_toolbar-function.
        move space to ls_toolbar-disabled.
        move 'Exit' to ls_toolbar-text.
        move icon_system_end to ls_toolbar-icon.
        move 'Click2Exit' to ls_toolbar-quickinfo.
        append ls_toolbar to e_object->mt_toolbar.
      endmethod.
      method user_command.
        case e_ucomm .
          when 'EDIT'.          "From Tool bar
            perform set_input.
             perform init_grid.
          when 'UPDA'.          "From Tool bar
            perform refresh_disp.
            perform update_table.
          when 'EXIT'.          "From Tool bar
            leave program.
        endcase.
      endmethod.
    endclass.
    class zcltest definition inheriting from  cl_gui_alv_grid.
    define this as a subclass so we can access the protected attributes
    of the superclass cl_gui_alv_grid
    public section.
    methods: constructor, disp_tab.
    endclass.
    need this now to instantiate object
    as we are using subclass rather than the main cl_gui_alv_grid.
    class zcltest implementation.
    METHOD constructor.
    CALL METHOD super->constructor
            exporting i_appl_events = 'X'
               i_parent = grid_container1.
    endmethod.
    method disp_tab.
    FIELD-SYMBOLS: <outtab> TYPE STANDARD TABLE.
    break-point 1.
    mt_outtab is the data table held as a protected attribute
    in class cl_gui_alv_grid.
    ASSIGN me->mt_outtab->* TO <outtab>.  "Original data
    do whatever you want with <outtab>
    contains data BEFORE changes each time.
    Note that NEW (Changed) table has been obtained already by
    call to form check_data USING P_ER_DATA_CHANGED
             TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
    Entered data is in table defined by <fs2>
    In this method you can compare original and changed data.
    Easier than messing around with individual cells.
    do what you want with data in <fs2>  validate / update / merge etc
    endmethod.
    endclass.
    data :
        ok_code like sy-ucomm,
        save_ok like sy-ucomm,
        i4 type int4,
    Container Object [grid_container]
    now created via method constructor
    in the subclass zcltest.
    Control Object [grid]
    grid1 type ref to zcltest,
    Event-Handler Object [grid_handler]
    grid_handler type ref to lcl_grid_event_receiver.
    start-of-selection.
    call screen 100.
    module status_0100 output.
    now display it as grid
    if grid_container1 is initial.
        create object grid_container1
            exporting
              container_name = 'CCONTAINER1'.
        create object grid1.
         break-point 1.
        create object grid_handler.
        set handler:
           grid_handler->user_command for grid1,
           grid_handler->toolbar for grid1,
           grid_handler->handle_data_changed for grid1.
    perform create_dynamic_fcat.
    perform create_dynamic_itab.
    perform populate_dynamic_itab.
    perform init_grid.
    perform register_enter_event.
    set off ready for input initially
    i4 = 0.
      call method grid1->set_ready_for_input
             exporting
               i_ready_for_input = i4.
    endif.
    endmodule.
    module user_command_0100 input.
    *PAI not needed in OO ALV anymore as User Commands are handled as events
    *in method user_command.
    *we can also get control if the Data entered and the ENTER is pressed by
    *raising an event.
    Control then returns to method handle_data_changed.
    endmodule.
    form create_dynamic_fcat.
    get structure of our user table for building field catalog
    Use the RTTI functionality
    lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_data ).
    Build field catalog just use basic data here
    colour specific columns as well
    loop at lr_rtti_struc->components into zog.
    c_index = c_index + 1.
    clear wa_it_fldcat.
      wa_it_fldcat-fieldname = zog-name .
      wa_it_fldcat-datatype =  zog-type_kind.
      wa_it_fldcat-inttype =   zog-type_kind.
      wa_it_fldcat-intlen =    zog-length.
      wa_it_fldcat-decimals =  zog-decimals.
      wa_it_fldcat-lowercase = 'X'.
      if c_index eq 2.
      wa_it_fldcat-emphasize = 'C411'.
         endif.
        if c_index eq 3.
      wa_it_fldcat-emphasize = 'C511'.
       endif.
      append wa_it_fldcat to it_fldcat .
    endloop.
    endform.
    form create_dynamic_itab.
    Create dynamic internal table and assign to field sysmbol.
    Use dynamic field catalog just built.
    call method cl_alv_table_create=>create_dynamic_table
                 exporting
                    it_fieldcatalog = it_fldcat
                 importing
                    ep_table        = new_table.
    assign new_table->* to <dyn_table>.
    endform.
    form populate_dynamic_itab.
    load up a line of the dynamic table
    c_dec2 = c_dec2 + 11.
    wa_element-anyfield1 = 'Tabbies'.
    wa_element-anyfield2 = 'ger.shepards'.
    wa_element-anyfield3  = 'White mice'.
    wa_element-anyfield4 =  'Any old text'.
    wa_element-anyfield5 =  c_dec2.
    append  wa_element to <dyn_table>.
    endform.
    form check_data USING P_ER_DATA_CHANGED
               TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
    Get altered data back
      ASSIGN   p_er_data_changed->mp_mod_rows TO <FS1>.
    stab =       p_er_data_changed->mp_mod_rows.
    ASSIGN STAB->* TO <FS2>.
    LOOP AT <FS2> INTO sdog.
    ALV grid display with altered data is now in <fs2>.
    do any extra processing you want here
    endloop.
    now display new table
    call method grid1->disp_tab.
    endform.
    form exit_program.
      call method grid_container1->free.
      call method cl_gui_cfw=>flush.
      leave program.
    endform.
    form refresh_disp.
      call method grid1->refresh_table_display.
    endform.
    form update_table.
    The dynamic table here is the changed table read from the grid
    after user has changed it
    Data can be saved to DB or whatever.
    loop at <dyn_table> into wa_element.
    do what you want with the data here
    endloop.
    switch off edit mode again for next function
    i4 = 0.
      call method grid1->set_ready_for_input
          exporting
              i_ready_for_input = i4.
    endform.
    form set_input.
    i4 = 1.
      call method grid1->set_ready_for_input
         exporting
           i_ready_for_input = i4.
    endform.
    form switch_input.
    if i4 = 1.
    i4 = 0.
    else.
    i4 = 1.
    endif.
      call method grid1->set_ready_for_input
         exporting
           i_ready_for_input = i4.
    endform.
    form init_grid.
    Enabling the grid to edit mode,
         struct_grid_lset-edit = 'X'. "To enable editing in ALV
         struct_grid_lset-grid_title  = 'Jimbos Test'.
         call method grid1->set_table_for_first_display
           exporting
             is_layout           = struct_grid_lset
           changing
             it_outtab             =  <dyn_table>
             it_fieldcatalog       =  it_fldcat.
    endform.
    form register_enter_event.
    call method grid1->register_edit_event
                   exporting
                      i_event_id = cl_gui_alv_grid=>mc_evt_enter.
    Instantiate the event or it won't work.
    create object g_event_receiver.
    set handler g_event_receiver->handle_data_changed for grid1.
    endform.</b>

    Hi there
    IE7 doesn't give me the add new page option and I get 404 error when trying to access the "How to contribute" section.
    I'll load up Firefox later (this browser usually works when IE7 doesn't always work properly).
    I'll copy the stuff to the wiki when I've got the browser sorted out.
    Cheers
    jimbp

  • Display error protocol in an alv list

    Hi!
    I have in my program an alv list.Two of its fields are editable. For one of this field I want to control the value key by the user. So , i used ADD_PROTOCOL_ENTRY from class CL_ALV_CHANGED_DATA_PROTOCOL like in report BCALV_EDIT_04. The control works very well when the user key a wrong value.
    But, here is my problem. I add a button to allow user to change value for several line with one click (mass change) and i would like to control entry too. 
    Since when i call method CHECK_CHANGED_DATA after my mass changes nothing appends, in PAI module i add this code.
    DATA WT_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.    CREATE OBJECT WT_CHANGED EXPORTING I_CALLING_ALV = GRID1.
    PERFORM MASS_CHANGE.
    CALL METHOD G_VERIFIER->HANDLE_DATA_CHANGED( WT_CHANGED ).
    In perform mass_change i had this code :
    WT_CELLS-ROW_ID = WT_INDEX2-ROW_ID.
    WT_CELLS-FIELDNAME = '/BIC/ZC_SIPROD'.
    WT_CELLS-VALUE = P_SIPROD.
    WT_CELLS-TABIX = W_TABIX.
    APPEND WT_CELLS.
    APPEND WT_CELLS TO WT_CHANGED->MT_GOOD_CELLS.
    The protocol windows appears. When i click on an error message the cell witch contains the error is selected but the fiels <i>name of the columns</i> is empty in the protocol windows and the incorrect value is not deleted.
    NB : when i do manual change (i.e line by line) this columns isn't empty and the incorrect value is deleted.
    can you help me in order to solve my problem?
    Thanks by advance,
    LB.
    Message was edited by:
            Laurent BOUDART

    Hi,
    you can have a look in BCALV_GRID_EDIT.
    Look in the perform data_changed.
    Edited by: Mario Schmidt on Jun 21, 2010 5:05 AM

  • To edit the field in the ALV report

    Hi,
        i want to edit the field of the ALV report what i need to do for that..
    Thanks & Regards
    Ashu Singh

    hi,
    check the code,
    REPORT  zalv_fcat.* Output table T006 structure declarationTYPES : BEGIN OF ty_t006.
            INCLUDE STRUCTURE t006.
    TYPES : END OF ty_t006.*Internal table and wa declaration for T006
    DATA : it_t006 TYPE STANDARD TABLE OF ty_t006,
           wa_t006 TYPE ty_t006.*declarations for ALV
    DATA: ok_code               TYPE sy-ucomm,
    fieldcatalog for T006
          it_fielcat           TYPE lvc_t_fcat,
    fieldcatalog for fieldcatalog itself:
          it_fielcatalogue           TYPE lvc_t_fcat,
          it_layout           TYPE lvc_s_layo.*declaration for toolbar function
    DATA:   it_excl_func        TYPE ui_functions.
    Controls to display it_t006 and corresponding fieldcatalog
    DATA: cont_dock TYPE REF TO cl_gui_docking_container,
          cont_alvgd     TYPE REF TO cl_gui_alv_grid.*controls to display the fieldcatalog as editable alv grid and container
    DATA: cont_cust TYPE REF TO cl_gui_custom_container,
          cont_editalvgd     TYPE REF TO cl_gui_alv_grid.*intialization event
    INITIALIZATION.*start of selection event
    START-OF-SELECTION.
    LOCAL CLASS Definition for data changed in fieldcatalog ALV
    CLASS lcl_event_receiver DEFINITION.
      PUBLIC SECTION.
        METHODS handle_data_changed
          FOR EVENT data_changed OF cl_gui_alv_grid
          IMPORTING er_data_changed.
    ENDCLASS.                    "lcl_event_receiver DEFINITION
    LOCAL CLASS implementation for data changed in fieldcatalog ALV
    CLASS lcl_event_receiver IMPLEMENTATION.
      METHOD handle_data_changed.
      ENDMETHOD.                    "handle_data_changed
    ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION*data declaration for event receiver
    DATA: event_receiver TYPE REF TO lcl_event_receiver.*end of selection event
    END-OF-SELECTION.*setting the screen for alv output for table display and
    *changed fieldcatalalogue display
    SET SCREEN 600.
    On this statement double click  it takes you to the screen painter SE51. Enter the attributes
    *Create a Custom container and name it CCONT and OK code as OK_CODE.
    *Save check and Activate the screen painter.
    *Now a normal screen with number 600 is created which holds the ALV grid.
    PBO of the actual screen , Here we can give a title and customized menus
    *Go to SE41 and create status 'STATUS600' and create THE function code 'SUBMIT'
    *and 'EXIT' with icons and icon texts
    Also create a TitleBar 'TITLE600' and give the relevant title.&----
    *&      Module  STATUS_0600  OUTPUT
    MODULE status_0600 OUTPUT.
      SET PF-STATUS 'STATUS600'.
      SET TITLEBAR 'TITLE600'.
    CREATE ALV GRID CONTROL IF DOES NOT EXISTS INITIALLY
      IF cont_dock IS INITIAL.
        PERFORM create_alv.
      ENDIF.ENDMODULE.                             " STATUS_0600  OUTPUT* PAI module of the screen created. In case we use an interactive ALV or
    *for additional functionalities we can create OK codes and based on the
    *user command we can do the coding as shown below
    *&      Module  USER_COMMAND_0600  INPUT
    MODULE user_command_0600 INPUT.
      CASE ok_code.
        WHEN 'SUBMIT'.
    *TO GET THE CURRENT FIELDCATALOGUE FROM THE FRONTEND
          CALL METHOD cont_alvgd->set_frontend_fieldcatalog
            EXPORTING
              it_fieldcatalog = it_fielcat.
    *refresh the alv
          CALL METHOD cont_alvgd->refresh_table_display.
    *to Send Buffered Automation Queue to Frontend
          CALL METHOD cl_gui_cfw=>flush.*Exit button clicked to leave the program
        WHEN 'EXIT'.
          LEAVE PROGRAM.  ENDCASE.ENDMODULE.                             " USER_COMMAND_0600  INPUT&----
    *&      Form  CREATE_ALV
    &----FORM create_alv.*create a docking container and dock the control at the botton
      CREATE OBJECT cont_dock
          EXPORTING
               dynnr = '600'
               extension = 100
               side = cl_gui_docking_container=>dock_at_bottom.*create the alv grid for display the table
      CREATE OBJECT cont_alvgd
          EXPORTING
               i_parent = cont_dock.*create custome container for alv
      CREATE OBJECT cont_cust
          EXPORTING
               container_name = 'CCONT'.
    *create alv editable grid
      CREATE OBJECT cont_editalvgd
          EXPORTING
               i_parent = cont_cust.* register events for the editable alv
      CREATE OBJECT event_receiver.
      SET HANDLER event_receiver->handle_data_changed FOR cont_editalvgd.  CALL METHOD cont_editalvgd->register_edit_event
        EXPORTING
          i_event_id = cl_gui_alv_grid=>mc_evt_modified.*building the fieldcatalogue for the initial display
      PERFORM build_fieldcat CHANGING it_fielcat it_fielcatalogue.*building the fieldcatalogue after the user has changed it
      PERFORM change_fieldcat CHANGING it_fielcatalogue.*fetch data from the table
      PERFORM fetch_data.*    Get excluding functions for the alv editable tool bar  APPEND cl_gui_alv_grid=>mc_fc_loc_append_row TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_fc_loc_insert_row TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_fc_loc_cut TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_fc_sort TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_fc_sort_asc TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_fc_sort_dsc TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_fc_subtot TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_fc_sum TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_fc_graph TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_fc_info TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_fc_print TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_fc_filter TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_fc_views TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_mb_export TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_mb_sum TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_mb_sum TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_mb_paste TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_fc_find TO it_excl_func.
      APPEND cl_gui_alv_grid=>mc_fc_loc_copy  TO it_excl_func.
    *Alv display for the T006 table at the bottom
      CALL METHOD cont_alvgd->set_table_for_first_display
        CHANGING
          it_outtab       = it_t006[]
          it_fieldcatalog = it_fielcat[].
    optimize column width of grid displaying fieldcatalog
      it_layout-cwidth_opt = 'X'.* Get fieldcatalog of table T006 - alv might have
    modified it after passing.
      CALL METHOD cont_alvgd->get_frontend_fieldcatalog
        IMPORTING
          et_fieldcatalog = it_fielcat[].to Send Buffered Automation Queue to Frontend  CALL METHOD cl_gui_cfw=>flush. Display fieldcatalog of table T006 in editable alv grid
      CALL METHOD cont_editalvgd->set_table_for_first_display
        EXPORTING
          is_layout            = it_layout
          it_toolbar_excluding = it_excl_func
        CHANGING
          it_outtab            = it_fielcat[]
          it_fieldcatalog      = it_fielcatalogue[].
    ENDFORM.                               " CREATE_alv
    *&      Form  fetch_data
    FORM fetch_data.* select data of T006
      SELECT * FROM t006 INTO TABLE it_t006 UP TO 50 ROWS.
    ENDFORM.                               " fetch_data
    *&      Form  BUILD_FIELDCAT
    FORM build_fieldcat CHANGING it_fldcat TYPE lvc_t_fcat
                                       it_fcat TYPE lvc_t_fcat.
    Fieldcatalog for table T006: it_fldcat
    to generate the fields automatically  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name       = 'T006'
        CHANGING
          ct_fieldcat            = it_fldcat[]
        EXCEPTIONS
          inconsistent_interface = 1
          program_error          = 2
          OTHERS                 = 3.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.*----
    Fieldcatalog for table LVC_T_FCAT:it_fcat
    Generate fieldcatalog of fieldcatalog structure.
    This fieldcatalog is used to display fieldcatalog 'it_fldcat'
    on the top of the screen.  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name       = 'LVC_S_FCAT'
        CHANGING
          ct_fieldcat            = it_fcat[]
        EXCEPTIONS
          inconsistent_interface = 1
          program_error          = 2
          OTHERS                 = 3.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                               " BUILD_FIELDCAT
    *&      Form  CHANGE_FIELDCAT
    *after the user has modified the fieldcatalogue we build another fieldcat
    *for the modified alv display
    FORM change_fieldcat CHANGING it_fcat TYPE lvc_t_fcat.  DATA ls_fcat TYPE lvc_s_fcat.  LOOP AT it_fcat INTO ls_fcat.
        ls_fcat-coltext = ls_fcat-fieldname.
        ls_fcat-edit = 'X'.    IF ls_fcat-fieldname = 'COL_POS' OR ls_fcat-fieldname = 'FIELDNAME'.
          ls_fcat-key = 'X'.
        ENDIF.    MODIFY it_fcat FROM ls_fcat.
      ENDLOOP.
    ENDFORM.                               " CHANGE_FIELDCAT
    ref:saptechnical tutorial.
    Regards,
    Anirban

  • Validation of data in editable ALV report output for particular field

    Hi Experts,
    I have one input enabled field in ALV output. How to validate the data once user enters  in that field and press enter? Is it possible to capture the value, hit the enter after user enters the data?
    Thanks,
    Surya Prakash

    Halo Prakash,
    1 First you should registeer the ENTER Event.
    call method g_grid->register_edit_event
                   exporting
                      i_event_id = cl_gui_alv_grid=>mc_evt_enter.
    2 Declare event handler method for Event data_changed of cl_gui_alv_grid.
    handle_data_changed
             for event data_changed of cl_gui_alv_grid
                 importing er_data_changed.
    3 Inside the Event handler method , you get the event parameter er_data_changed type ref to CL_ALV_CHANGED_DATA_PROTOCOL.
    loop at er_data_changed->mt_good_cells into ls_good.
          case ls_good-fieldname.
            when 'FIELD1'.
              call method check_FIELD1.
            when 'FIELD2 '.
              call method check_FIELD2
          endcase.
        endloop.
    4 Inside the Method check_FIELD1 and check_FIELD2 you can do the validation check .
    call method er_data_changed->get_cell_value( Passing the row no and field name).
    if the check  fails you can use add_protocol_entry to write the error.
    5 Finally call
    er_data_changed->display_protocol.
    Regards
    Arshad

  • Dynamic value assignment to a particular column in a vertical ALV

    Hi Friends,
    In the present program ALV has 44 fields and output row is only one(with some field editable).
    My requirement is to change present output to vertical ALV and editable field should be available
    as editable.
    Now I have changed this to transposed ALV manually(not dynamically) with required fields editable.
    Now there is 44 rows and two column "FIELD and "VALUE'.Some values in the second column is editable.
    Previously output was like this:
    field1   field2  field3 ...
    val1     val2    val3   ...
    Now output is like:
    FIELD   VALUE
    field1  value1(type INT)
    field2  value2(type char5) Editable(need F4 help)
    field3  value3(type date)
    My present structure declaration is:
    types: begin of ty_itab,
            field type char 50,
            value type char70,
            celltab type lvc_t_styl,(for editing some values in VALUE column).
           end of ty_itab.
    data: itab type standard table of ty_itab.
    Now the second column i have declared as CHAR70 which contains only char
    values because to put all differt types of values to one single column named
    'VALUE'.
    But as field1 field2 field3... had differnt type of value like integer char date...I need to validate some values
    (specially those which are editable) before saving to custom DB table.
    So I need dynamic value assignment to VALUE column when preparing internal table for display.
    What I want to say is that VALUE column should be able to contain different type of values like INT, DATE, CHAR...etc
    Is the requirement is feasible?
    If yes then How should I declare the structure and populate different type of values within single column 'VALUE'.
    Also is it possible to have F4 helps in the second column (VALUE)???

    Hi Manab,
    I did something comparable: We have a very complex transaction with several subscreens with multiple fields to be filled with complex logic to create a very special contract. The requirement was to create a method to create a copy of this contract being able to apply some changes.
    I created a wizard (transaction SBPT_WIZARD_BUILDER - Wizard-Builder) to accomplish that. I grouped all the fields to just 3 logical groups and thius created 3 stesp where the user gets an ALV as you describe, but we have the rows like FIELD  with the new value editable. Additionally I have hidden fields with table name and field name so that I can determine the characteristics (datatype) at run time.
    The value fields are just strings (every ALV field is a text field on the surface).
    For editable fields, you have an event DATA_CHANGED. I used this method as a handler for the event:
    (I will leave out the wizard part here - maybe a good idea for a blog to explain that)
    METHOD handle_data_changed.
        CALL FUNCTION 'RS_CONV_EX_2_IN'
          EXPORTING
             input_external                     = <mod>-value
             table_field                        = ls_tabfield
    I also created handlers for F1 and F4
    Handler for CL_GUI_ALV_GRID->ONF1
    METHOD handle_f1.
        CALL FUNCTION 'HELP_OBJECT_SHOW_FOR_FIELD'
          EXPORTING
            called_for_tab   = lv_tabname
            called_for_field = lv_fieldname
          EXCEPTIONS
            object_not_found = 1
            sapscript_error  = 2
            OTHERS           = 3.
    Handler for CL_GUI_ALV_GRID->HANDLE_F4
    METHOD handle_f4.
      CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
        EXPORTING
          tabname    = lv_tabname
          fieldname  = lv_fieldname
        TABLES
          return_tab = lt_return_tab
        EXCEPTIONS
          OTHERS     = 5.
        er_event_data->m_event_handled = abap_true.
    * if er_event_data->m_event_handled is not set to abap_true, system will handle it.
    * In this context the message 'Keine Eingabehilfe verfügbar' will be displayed
    ENDMETHOD.
    This is just an excerpt from my project. It shows that you can do more in ALV as you knew.
    I tried to post a little more but the formatting break down, possibly a result of the character limit
    Regards,
    Clemens

  • Run ALV in Background JOB (DUMP)

    HI Experts,
    Before post  i have already  look at this forum and tried many solutions , im on  SAPGUI 7.20 and already creatde a doc container... so nothing has work yet...
    Im trying to run a alv report in a  scheduled JOB...!!
    Below the Dump Description and My source code...!
    Many Thanks for any help..!!!!
    DUMP.
    Short text
        Exception condition "CNTL_ERROR" raised.
    What happened?
        The current ABAP/4 program encountered an unexpected
        situation.
    What can you do?
        Note down which actions and inputs caused the error.
        To process the problem further, contact you SAP system
        administrator.
        Using Transaction ST22 for ABAP Dump Analysis, you can look
        at and manage termination messages, and you can also
        keep them for a long time.
    Error analysis
        A RAISE statement in the program "CL_GUI_CONTROL================CP" raised the
         exception
        condition "CNTL_ERROR".
        Since the exception was not intercepted by a superior
        program, processing was terminated.
        Short description of exception condition:
        For detailed documentation of the exception condition, use
        Transaction SE37 (Function Library). You can take the called
        function module from the display of active calls.
    How to correct the error
        If the error occures in a non-modified SAP program, you may be able to
        find an interim solution in an SAP Note.
        If you have access to SAP Notes, carry out a search with the following
        keywords:
    SOURCE CODE:
    DATA: gro_doc_container     TYPE REF TO cl_gui_docking_container,
            w_off                 TYPE  INT4.
      IF w_1c_container IS INITIAL.
      CALL METHOD cl_gui_alv_grid=>offline
       RECEIVING e_offline = w_off.
    IF NOT w_off is initial.
        CREATE OBJECT w_1obj_alv
                 EXPORTING i_parent = gro_doc_container .
      else.
          CREATE OBJECT w_1c_container
            EXPORTING
              container_name = c_1alv.
          CREATE OBJECT w_1obj_alv
            EXPORTING
              i_parent = w_1c_container.
        ENDIF.
        CREATE OBJECT w_event_receiver.
        SET HANDLER: w_event_receiver->handle_data_changed FOR w_1obj_alv,
                     w_event_receiver->handle_toolbar FOR w_1obj_alv,
                     w_event_receiver->handle_user_command FOR w_1obj_alv.
        CALL METHOD w_1obj_alv->register_edit_event
          EXPORTING
            i_event_id = cl_gui_alv_grid=>mc_evt_modified.
        CALL METHOD w_1obj_alv->set_table_for_first_display
          EXPORTING
            i_save               = c_a
            is_layout            = e_1layout
            is_variant           = e_1variant
            it_toolbar_excluding = is_1func
            i_structure_name     = c_1strucs1
          CHANGING
            it_outtab            = is_1pant
            it_fieldcatalog      = is_1fcat[].

    HI ,
    The ALV grid will not work in background. You need to check sy-batch (for background processing ) and write a seperate code .
    The better way of doing is to use SALV factory methods - It works both in background and foreground modes.
    Remember It will work on ECC and it doesnot support editable ALV directly.
    For Demo program  SALV_DEMO* and F4
    Hope this brings clarity and neccassary help to you.

  • Editable and non editable issue in ALV OOPS

    Hi All,
    After giving the input in selection screen when i execute the report program will display the output in ALV OOOps.
    Here i need few fields in Editable and some fields are non editbale mode. I can't use Edit  ='X" in fieldcatalog.
    I refered few threads in SDN at last  i found the method cl_gui_alv_grid=>mc_style_enabled. using this method also i am not getting. PLz see below sample code.
        gs_celltab-fieldname = 'Z_MESSAGEID'.
        gs_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
         INSERT gs_celltab INTO TABLE gt_celltab.
          gs_final-celltab = gt_celltab.
          APPEND gs_final TO gt_final.
    I am passing GT_FINAL to below mthiod.
        CALL METHOD grid->set_table_for_first_display
          EXPORTING
            i_save               = 'A'
           i_default            = 'X'
            is_layout            = gs_layout
            is_variant           = gs_variant
            it_toolbar_excluding = gt_exclud
          CHANGING
            it_fieldcatalog      = gt_fieldcat[]
            it_outtab            = gt_final[].
    still inut all fields are in disply mode. Any body can suggest me how to approach.
    Regards,
    Maheedhar

    Here is the sample code.
    DATA :PT_CELLTAB Type LVC_T_STYL,
               LS_CELLTAB TYPE LVC_S_STYL,
               L_MODE type RAW4.
      LS_CELLTAB-fieldname = 'KUNRG'.
      LS_CELLTAB-style = cl_gui_alv_grid=>mc_style_disabled.
      Insert LS_CELLTAB Into Table PT_CELLTAB.
      LS_CELLTAB-fieldname = 'KUNNR_AG'.
      LS_CELLTAB-style = cl_gui_alv_grid=>mc_style_enabled.
      Insert LS_CELLTAB Into Table PT_CELLTAB.
    Append X_OUTTAB to TB_OUTTAB.
    *---Switch edit mode 0 for No-edit 1 for Edit
      CALL METHOD g_grid->set_ready_for_input
        EXPORTING
          i_ready_for_input = 1.
    its recommended to use the below events for editable mode to handle changed data
    example
    handle_data_changed
           FOR EVENT     data_changed OF cl_gui_alv_grid
               IMPORTING e_onf4
                         e_onf4_before
                         e_onf4_after
                         er_data_changed,
    Handle data Change Finished
        handle_data_changed_finished
           FOR EVENT data_changed_finished OF cl_gui_alv_grid
               IMPORTING. ...
    Edited by: Ashwin Kumar Chitram on Oct 3, 2011 8:06 PM

  • Check_changed_data method on editable ALV Grid ( class cl_gui_alv_grid)

    Hi guys,
    I use the following method (register_edit_event) in the PBO soon after first display of an editable ALV grid to register enter as an event to do validations on fields like qty. If user enters some character like 'abc' for qty and hits enter on keyboard, ALV grid pop's up a standard message ( I haven't coded for this.Since I use DDIC structure in field catalog, the Std. ALV program takes care of it. ). THis takes care of the validation before I click on save.
    call method alv_grid->register_edit_event
                            exporting
                               i_event_id = cl_gui_alv_grid=>mc_evt_enter.
    This works fine. But I want this validation to run when I also click the SAVE button of the screen. Is it possible to run this standard validation in my PAI event eg. SAVE ? I thought I will be, by calling the method check_changed_data in my PAI event. But this is doing nothing. Does this method conflict with register_edit_event or something ? So , basically what I am looking for is to trigger the event or call the method which does the same work as the "check" button on ALV grid.
    Any advice or tips or sample code is greatly appreciated.
    Thanks,
    Shareen

    Hi Shareen,
    Handle the data_changed event in the grid.
    Whenever you make changes in the data in ALV Grid this event would be triggered. Here you can perform additional validations that you may need to perform.
        METHODS handle_data_changed
          FOR EVENT data_changed OF cl_gui_alv_grid
          IMPORTING er_data_changed.
    Implementation:
      METHOD handle_data_changed.
        PERFORM validations USING er_data_changed.
      ENDMETHOD.
    FORM validations USING er_data_changed TYPE REF TO cl_alv_changed_data_protocol.
      DATA: ls_good TYPE lvc_s_modi.
      DATA  wa LIKE LINE OF lt_good_cells.
      CALL METHOD g_grid->register_edit_event
        EXPORTING
          i_event_id = cl_gui_alv_grid=>mc_evt_modified.
      LOOP AT er_data_changed->mt_good_cells INTO ls_good.
        CASE ls_good-fieldname.
        WHEN 'FIELDNAME'. "Your fieldname
            CALL METHOD er_data_changed->get_cell_value "Get the changed value
              EXPORTING
                i_row_id    = ls_good-row_id
                i_fieldname = ls_good-fieldname
              IMPORTING
                e_value     = temp. "Your temp variable
            "Make your validations here.
        ENDCASE.
    Ps: Reward points if helpful.
    Regards,
    Wenceslaus.

  • Update ZTable from editable ALV

    Hi All,
    i'm calling a Function Module from within a Badi Class ( Workorder_Update) which uses an ALV to Add Comments in a Field of the ALV for Transportation to a ZTable. Therefore the ALV is set to editable.
    The Problem is that if the User does not press 'enter' after she/he added the Comment, the value is not send back to the internal Table wich updates the ZTab. If the User presses 'enter' ONLY the Comment is transported but the remainder of the Fields are cleared.
    This is part of the Coding:
    Before Calling FM -->
      + IF wa_header_old-pronr NE wa_header-pronr.
            CLEAR wa_zthlog.
            wa_zthlog-uzeit     = sy-uzeit.
            wa_zthlog-aufnr     = wa_header-aufnr.
            wa_zthlog-objnr     = wa_header-objnr.
            wa_zthlog-vornr     = wa_operation-vornr.
            wa_zthlog-ktext     = wa_header-ktext.
            wa_zthlog-aenam     = sy-uname.
            wa_zthlog-aedat     = sy-datum.
            wa_zthlog-larnt     = wa_operation-larnt.
            wa_zthlog-pronr     = wa_header-pronr.
            wa_zthlog-arbei     = wa_operation-arbei.
            wa_zthlog-dauno     = wa_operation-dauno.
            wa_zthlog-dauno     = wa_operation-dauno.
            wa_zthlog-ltxa1     = wa_operation-ltxa1.
            wa_zthlog-arbid     = wa_operation-arbid.
            wa_zthlog-fieldname = 'PRONR'.
            wa_zthlog-matkl     = wa_operation-matkl.
            wa_zthlog-preis     = wa_operation-preis.
            wa_zthlog-waers     = wa_header-waers.
            wa_zthlog-old_value = wa_header_old-pronr.
            wa_zthlog-new_value = wa_header-pronr.
    Fill t_zthlog - Call FM
            APPEND wa_zthlog TO t_zthlog.
          ENDIF.
        ENDLOOP.
    Secure Values before change
        MOVE t_zthlog TO y_zthlog.+
    Calling FM -->
    +function z_thlog.
      t_zthlog[] = c_zthlog[].
      call screen 0100 starting at 10 3.
      c_zthlog[] = t_zthlog[].
    endfunction.+
    ALV Grid - Processing -->
    +module output_0100 output.
    Fill Fieldcatalog
      call function 'LVC_FIELDCATALOG_MERGE'
        exporting
          i_structure_name       = 'ZTHLOG'
        changing
          ct_fieldcat            = gt_fieldcat[]
        exceptions
          inconsistent_interface = 1
          program_error          = 2
          others                 = 3.
      if g_custom_container is initial.
    Prepare ALV
        create object g_custom_container
             exporting container_name = g_container.
        create object grid1
             exporting i_parent = g_custom_container.
        g_repid = sy-repid.
        gs_layout-grid_title = 'Änderungsprotokoll'.
        gs_layout-zebra      = 'X'.
        gs_layout-cwidth_opt = 'X'.
        gs_variant-report    = g_repid.
        gs_variant           = '/default'.
    gs_layout-edit = 'X'.
    Call ALV
        call method grid1->set_table_for_first_display
          exporting
            i_structure_name = 'ZTHLOG'
            is_layout        = gs_layout
            i_save           = 'A'
            is_variant       = gs_variant
          changing
            it_outtab        = t_zthlog
            it_fieldcatalog  = gt_fieldcat[].
    Ready for Input
        call method grid1->set_ready_for_input
          exporting
            i_ready_for_input = 1.
    Eventregistration
        call method grid1->register_edit_event
          exporting
            i_event_id = cl_gui_alv_grid=>mc_evt_enter.
        create object g_event_receiver.
        set handler g_event_receiver->handle_data_changed for grid1.
      else.
    Refresh, if filled
        call method grid1->refresh_table_display.
      endif.
    set Cursor
      call method cl_gui_control=>set_focus
        exporting
          control = grid1.
    endmodule.                 " output_0100  OUTPUT+
    There are alot of fields so the manual creation of the fieldcatalog should be avoided if possible.
    Any Help is appreciated!
    Best Regards
    Stefan

    Hi,
    Check this
    * Module Pai INPUT                                                     *
    * PAI module                                                           *
    module pai input.
      save_ok = ok_code.
      clear ok_code.
      call method grid1->check_changed_data
        importing
          e_valid = v_valid.
    " After this system will automatically update your changed data into
    " internal table t_zthlog
      case save_ok.
        when 'EXIT'.
          perform f_exit_program.
        when 'CANC'.
          perform f_exit_program.
        when 'BACK'.
          perform f_exit_program.
        when 'SAVE'.
          perform f_save_data.
      endcase.
    endmodule.                               " Pai INPUT
    aRs

  • Editable alv: add custom validation and display "errors" in protocol list

    Hi,
    What I want to do:
    PAI validation of editable alv with displaying error's in the protocol list by adding custom entries to the existing protocol object.
    What is my problem:
    After registering "data_changed event", the protocol list don't appear.
    My understanding is, that the object "er_data_changed" is passed by the event "data_changed"
    an so I thought I can add some more entries to the protocol list.
    After "de-registering" the "data_changed" event, the protocol appears with the standard errros messages (e.g. "input to numeric" by enter charachters)
    One more hint:
    By creating a new object "er_data_changed" in the handler method the protocol list works, but I would like to append entries to the object that was passed with the event.
    Probably I've misunderstand something, please help !
    My coding:
    PAI:
    trigger event "data_changed" -> calls handler method
      CALL METHOD r_myalv->check_changed_data
        IMPORTING
          e_valid = is_valid.
    stop processing
      IF is_valid NE 'X'.
        MESSAGE 'invalid input' TYPE 'E' .
      ENDIF.
    handler method:
    handle_data_changed FOR EVENT data_changed  OF cl_gui_alv_grid  IMPORTING e_ucomm
                                                                                    er_data_changed.
    METHOD handle_data_changed.
        data: ls_mod_cell type lvc_s_modi.
         CALL METHOD er_data_changed->add_protocol_entry
                    EXPORTING
                           i_msgid     = 'SU'
                           i_msgty     = 'E'
                           i_msgno     = '000'
                           i_msgv1     = 'This is a test !'
                           i_fieldname = ls_mod_cell-fieldname.
         er_data_changed->refresh_protocol( ).
         er_data_changed->DISPLAY_PROTOCOL( ).
    ENDMETHOD.                    "handle_data_changed

    Dear Olaf,
        If understood correctly, you want to Edit an ALV and do some data validations when some data is changed in an ALV.   To do this follow the following steps:
    1.   Before displaying ALV, Register the edit event.
    * Set cell modified to trigger data_changed
    CALL METHOD go_alv_grid->register_edit_event
    EXPORTING
    i_event_id = cl_gui_alv_grid=>mc_evt_modified.
    2.  Register the event DATA_CHANGED of class CL_GUI_ALV_GRID & handle the event.
    SET HANDLER lo_event_receiver->handle_data_changed FOR go_alv_grid.
    The event DATA_CHANGED of class CL_GUI_ALV_GRID has a parameter ER_DATA_CHANGED which is of type CL_ALV_CHANGED_DATA_PROTOCOL.
    This er_data_changed has internal table MT_MOD_CELLS(contains index of records changed ) & MP_MOD_ROWS(contains the changed row), using these update your internal table accordingly.
    DATA : wa_mod_cell TYPE lvc_s_modi.
    FIELD-SYMBOLS: <fs> TYPE table.
    LOOP AT er_data_changed->mt_mod_cells INTO wa_mod_cell.
    ASSIGN er_data_changed->mp_mod_rows->* TO <fs>.
    READ TABLE <fs> INTO wa_output INDEX wa_mod_cell-tabix.
    MODIFY lt_output FROM wa_output INDEX wa_mod_cell-row_id.
    ENDLOOP.
    3.   Here it self you can do the required data validations(No need of any PAI modules) as below.
    IF wa_orders-zfstfirmtyp = c_9.
    MESSAGE s288(zcsp).
    DELETE er_data_changed->mt_mod_cells.
    EXIT.
    ENDIF.
    Regards
    Kesava

  • Editable Alv: ERROR in er_data_changed- display_protocol

    I have one fields "Emp_dept" in the record of the ALV Grid which can be edited, but when I edit this field  with  enter  event it will generate a error in display protocal, I want it to save in database , I debuged the program it reflect the in internal table but failed to reflect the in change in data base, as i Just started dveelopment in abap programing i searched the whole web for this problem but couldnot sucessfull please help me in this regarrd
    Here is my code:
    I am using module pool programing and I am following abap slandered program Bcalv_edit_03.
    FUNCTION-POOL Z_EMPLOYEE.                   "MESSAGE-ID ..
    * INCLUDE LZ_EMPLOYEED...                    " Local class definition
    TABLES:ZEMPLOYEE, ZEMP_COMM.
    DATA: zemploye TYPE TABLE OF zemployee  WITH HEADER LINE,
      WA TYPE zemployee .
    DATA: ZEMP_COM TYPE TABLE OF ZEMP_COMM   WITH HEADER LINE.
      DATA : WACOMM TYPE ZEMP_COMM.
    DATA: ZEMP_ADR TYPE TABLE OF ZEMP_ADRESS  WITH HEADER LINE,
    WA_ADR TYPE ZEMP_ADRESS.
    DATA: ZEMP_EDU TYPE TABLE OF ZEMP_EDUCATION1  WITH HEADER LINE,
    WA_EDU1 TYPE ZEMP_EDUCATION1.
    DATA EMPD TYPE ZEMP_ID.
    *data empd LIKE zemployee-emp_id.
      data: O_DOCKING TYPE REF TO CL_GUI_DOCKING_CONTAINER,
    O_GRID TYPE REF TO CL_GUI_ALV_GRID,"Grid
       i_selected_rows TYPE lvc_t_row,"Selected Rows
            w_selected_rows TYPE lvc_s_row,
       WA_LAYOUT TYPE LVC_S_LAYO,
    class lcl_event_receiver definition deferred.
    data: g_event_receiver type ref to lcl_event_receiver.
    types:BEGIN OF i_zemployee ,
        emp_id type zemployee-emp_id,
       emp_name type zemployee-emp_name,
       D_O_BIRTH TYPE ZEMPLOYEE-D_O_BIRTH,
       D_o_jOIN TYPE ZEMPLOYEE-D_o_jOIN,
       EMP_DEPT TYPE ZEMPLOYEE-EMP_DEPT,
       EMP_NO type ZEMP_COMM-EMP_NO,
       eemp_id type zemp_comm-emp_id,
       EMP_ADRESS TYPE ZEMP_ADRESS-EMP_ADRESS,
       EMP_RES_ADDR TYPE ZEMP_ADRESS-EMP_RES_ADDR,
       EMP_EDU1 TYPE ZEMP_EDUCATION1-EMP_EDU1,
      END OF i_zemployee.
       Data:
         i_tb type i_zemployee,
         emp_itb like table of i_tb.
         data:t_fcat TYPE lvc_t_fcat,
         wa_fcat TYPE lvc_s_fcat.
    DATA:
       screen  TYPE n LENGTH 4 VALUE 0100,
       screen1  TYPE n LENGTH 4 VALUE 0110,
       screen2  TYPE n LENGTH 4 VALUE 0120,
       screen3  TYPE n LENGTH 4 VALUE 0130,
        ok_code LIKE sy-ucomm.
       FORM FREE_OBJECTS .
       CALL METHOD O_GRID->FREE
         EXCEPTIONS
           CNTL_ERROR        = 1
           CNTL_SYSTEM_ERROR = 2
           OTHERS            = 3.
       IF SY-SUBRC <> 0.
         MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
       ENDIF.
       FREE O_GRID.
       CALL METHOD O_DOCKING->FREE
         EXCEPTIONS
           CNTL_ERROR        = 1
           CNTL_SYSTEM_ERROR = 2
           OTHERS            = 3.
       IF SY-SUBRC <> 0.
         MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
       ENDIF.
      FREE O_DOCKING.
    ENDFORM.
      form sol using emp_idd .
        data l_num(5) type n.
        l_num = emp_idd.
    * CALL FUNCTION 'NUMBER_GET_NEXT'
    *         EXPORTING
    *              nr_range_nr             = '01'
    *              object                  = 'ZEMP_AUTO'
    *         IMPORTING
    *              number                  = l_num
    *         EXCEPTIONS
    *              interval_not_found      = 1
    *              number_range_not_intern = 2
    *              object_not_found        = 3
    *              quantity_is_0           = 4
    *              quantity_is_not_1       = 5
    *              interval_overflow       = 6
    *              buffer_overflow         = 7
    *              OTHERS                  = 8.
        l_num = l_num + 1.
    EMP_IDD = L_NUM.
    endform.
      class lcl_event_receiver definition.
      public section.
         methods:
           handle_data_changed
              for event data_changed of cl_gui_alv_grid
                  importing er_data_changed.
      private section.
    * This flag is set if any error occured in one of the
    * following methods:
         data: error_in_data type c.
    * Methods to modularize event handler method HANDLE_DATA_CHANGED:
         methods: check_planetype
          importing
             ps_good_planetype type lvc_s_modi
             pr_data_changed type ref to cl_alv_changed_data_protocol.
    *    methods: ch_new_plane_v_new_seatsocc
    *           importing
    *              psg_plane type lvc_s_modi
    *              psg_socc type lvc_s_modi
    *              ps_saplane type saplane
    *              pr_data_changed type ref to cl_alv_changed_data_protocol.
    *    methods: ch_new_plane_v_old_seatsocc
    *           importing
    *              psg_plane type lvc_s_modi
    *              ps_saplane type saplane
    *              pr_data_changed type ref to cl_alv_changed_data_protocol.
    *    methods: check_seatsocc
    *           importing
    *              ps_good type lvc_s_modi
    *              pr_data_changed type ref to cl_alv_changed_data_protocol.
    * This is a suggestion how you could comment your checks in each method:
    * CHECK: fieldname(old/new value) !<comp> fieldname(old/new value)
    * IF NOT: (What to tell the user is wrong about the input)
    * Remarks:
    *  fieldname:       fieldname of table for the corresponding column
    *  (old/new value): ckeck with value of GT_OUTTAB or MT_GOOD_CELLS.
    *  !<comp>        : the value is valid if the condition <comp> holds.
    * Example:
    *  CHECK seatsocc(new) !>= seatsmax(old)
    *  IF NOT: There are not enough number of seats according to this
    *          planetype.
    endclass.
    class lcl_event_receiver implementation.
       method handle_data_changed.
         data: ls_good type lvc_s_modi.
        error_in_data = space.
         loop at er_data_changed->mt_good_cells into ls_good.
           case ls_good-fieldname.
    * check if column PLANETYPE of this row was changed
             when 'EMP_DEPT'.
               call method check_planetype
                      exporting
                         ps_good_planetype = ls_good
                         pr_data_changed   = er_data_changed.
          endcase.
         endloop.
    *§7.Display application log if an error has occured.
         if error_in_data eq 'X'.
            call method er_data_changed->display_protocol.  ( Error line)        <-------------------------------
         endif.
       endmethod.
       method check_planetype.
         data: l_planetype type zemp_dept,
               ls_saplane type zemployee,
               ls_good_seatsocc type lvc_s_modi.
         call method pr_data_changed->get_cell_value
               exporting i_row_id =    ps_good_planetype-row_id
                         i_fieldname = ps_good_planetype-fieldname
               importing e_value     = l_planetype.
    MODIFY ZEMPLOYEE FROM TABLE emp_itb.
         select single * from zemployee into ls_saplane where
                                          emp_dept = l_planetype.
               if sy-subrc ne 0.
           call method pr_data_changed->add_protocol_entry
            exporting
               i_msgid = '0K' i_msgno = '000'  i_msgty = 'E'
               i_msgv1 = text-m03           "Flugzeugtyp
               i_msgv2 = l_planetype
               i_msgv3 = text-m05           "exitstiert nicht
               i_fieldname = ps_good_planetype-fieldname
               i_row_id = ps_good_planetype-row_id.
           error_in_data = 'X'.
           exit. "plane does not exit, so we're finished here!
         endif.
    endmethod.
    endclass.
    **********************************************Module output****************
    MODULE STATUS_0120 OUTPUT.
      SET PF-STATUS 'START'.
      SET TITLEBAR 'STARTT'.
    IF O_DOCKING IS INITIAL.
    *   Creating Docking Container
        data: lt_exclude type ui_functions.
           CREATE OBJECT O_DOCKING
                  EXPORTING
                    RATIO                       = '95'.
           IF SY-SUBRC EQ 0.
    *   Creating Grid
             CREATE OBJECT O_GRID
                 EXPORTING
                    I_PARENT          = O_DOCKING.
           ENDIF.
    endif.
    * Filling the fieldcatalog table
    *    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    *      EXPORTING
    *        I_STRUCTURE_NAME       = 'i_tb'
    *      CHANGING
    *        CT_FIELDCAT            = t_fcat
    *      EXCEPTIONS
    *        INCONSISTENT_INTERFACE = 1
    *        PROGRAM_ERROR          = 2
    *        OTHERS                 = 3.
       WA_LAYOUT-GRID_TITLE = 'EMPLOYEE TABLE DETAILS'.
       WA_LAYOUT-ZEBRA = 'X'.
       WA_LAYOUT-EDIT = 'X'.
    IF T_FCAT is  initial.
    *  wa_fcat-fieldname = 'EMP_ID'.
    *  wa_fcat-ref_table = 'ZEMPLOYEE'.
    *  wa_fcat-ref_field = 'EMP_ID'.
    *  wa_fcat-col_pos = 2.
    *  APPEND wa_fcat TO t_fcat.
    *  CLEAR wa_fcat.
       wa_fcat-fieldname = 'EMP_NAME'.
       wa_fcat-ref_table = 'ZEMPLOYEE'.
       wa_fcat-ref_field = 'EMP_NAME'.
       wa_fcat-col_pos = 3.
       APPEND wa_fcat TO t_fcat.
       CLEAR wa_fcat.
        wa_fcat-fieldname = 'EMP_DEPT'.
       wa_fcat-ref_table = 'ZEMPLOYEE'.
       wa_fcat-ref_field = 'EMP_DEPT'.
       wa_fcat-col_pos = 4.
       APPEND wa_fcat TO t_fcat.
       CLEAR wa_fcat.
          wa_fcat-fieldname = 'D_O_BIRTH'.
       wa_fcat-ref_table = 'ZEMPLOYEE'.
       wa_fcat-ref_field = 'D_O_BIRTH'.
       wa_fcat-col_pos = 5.
       APPEND wa_fcat TO t_fcat.
       CLEAR wa_fcat.
       wa_fcat-fieldname = 'D_O_JOIN'.
      wa_fcat-ref_table = 'ZEMPLOYEE'.
      wa_fcat-ref_field = 'D_O_JOIN'.
      wa_fcat-col_pos = 6.
       APPEND wa_fcat TO t_fcat.
       CLEAR wa_fcat.
    wa_fcat-fieldname = 'EMP_NO'.
      wa_fcat-ref_table = 'ZEMP_COMM'.
      wa_fcat-ref_field = 'EMP_NO'.
      wa_fcat-col_pos = 7.
       APPEND wa_fcat TO t_fcat.
       CLEAR wa_fcat.
       wa_fcat-fieldname = 'EMP_ADRESS'.
       wa_fcat-ref_table = 'ZEMP_ADRESS'.
       wa_fcat-ref_field = 'EMP_ADRESS'.
       wa_fcat-col_pos = 7.
       APPEND wa_fcat TO t_fcat.
       CLEAR wa_fcat.
       wa_fcat-fieldname = 'EMP_RES_ADDR'.
       wa_fcat-ref_table = 'ZEMP_ADRESS'.
       wa_fcat-ref_field = 'EMP_RES_ADDR'.
       wa_fcat-col_pos = 8.
       APPEND wa_fcat TO t_fcat.
       CLEAR wa_fcat.
       wa_fcat-fieldname = 'EMP_EDU1'.
       wa_fcat-ref_table = 'ZEMP_EDUCATION1'.
       wa_fcat-ref_field = 'EMP_EDU1'.
       wa_fcat-col_pos = 9.
       APPEND wa_fcat TO t_fcat.
       CLEAR wa_fcat.
    ENDIF.
    * CALL METHOD o_grid->register_edit_event
    *    EXPORTING  i_event_id = cl_gui_alv_grid=>mc_evt_modified.
    *    W_VARIANT-REPORT = SY-REPID.
    * Displaying the output
         CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
           EXPORTING
    *       IS_VARIANT                    = VARIANT
             I_SAVE                        = 'A'
            I_STRUCTURE_NAME       = 'i_tb'
             IS_LAYOUT                     = WA_LAYOUT
             it_toolbar_excluding  = lt_exclude
           CHANGING
           IT_OUTTAB                     =  emp_itb
             IT_FIELDCATALOG               = t_fcat
           EXCEPTIONS
             INVALID_PARAMETER_COMBINATION = 1
             PROGRAM_ERROR                 = 2
             TOO_MANY_LINES                = 3
             OTHERS                        = 4.
         IF SY-SUBRC <> 0.
           MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                       WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
         ENDIF.
    *call method cl_gui_control=>set_focus exporting control = O_GRID.
    *      call method cl_gui_cfw=>flush.
           CALL METHOD o_grid->set_ready_for_input
          EXPORTING
            I_READY_FOR_INPUT = 1.
      CALL METHOD O_GRID->REGISTER_EDIT_EVENT
         EXPORTING
           I_EVENT_ID = CL_GUI_ALV_GRID=>mc_evt_enter.
    *    EXCEPTIONS
    *      ERROR      = 1
    *      OTHERS     = 2.
    **** UPDATE zemployee FROM TABLE emp_itb.
      create object g_event_receiver.
       set handler g_event_receiver->handle_data_changed for o_grid.
    *  IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *  ENDIF.
    ENDMODULE.                 " STATUS_0120  OUTPUT
    *&      Module  USER_COMMAND_0120  INPUT
    *       text
    MODULE USER_COMMAND_0120 INPUT.
    DATA LV_UCOMM TYPE SY-UCOMM.
    *  data: ok_code like sy-ucomm .
      LV_UCOMM = SY-UCOMM.
       CASE LV_UCOMM.
      WHEN 'CANCEL' OR 'EXIT'.
           PERFORM FREE_OBJECTS.
           LEAVE PROGRAM.
         WHEN 'BACK'.
            CALL METHOD o_grid->set_frontend_fieldcatalog
             EXPORTING
               it_fieldcatalog = t_fcat[].
            if o_grid is not initial.
        CALL METHOD o_grid->refresh_table_display
           EXCEPTIONS
             finished = 1
             OTHERS   = 2.
    endif.
           PERFORM FREE_OBJECTS.
           CALL SCREEN 110.
    *      SET SCREEN '0'.
    *      LEAVE SCREEN.
       ENDCASE.
    ENDMODULE.   
    Please help me to solve this porblem..

    Hi suhas,
    my issue is not the lack of data .....
    my issue is about the error handling in data_changed event in alv oops application....am able to display the error log using display_protocol method..,.. but after displaying the error log am still able to save the changes which should not happen....the thing is we should not be able to save the changes...... am having the same issue as the following thread
    Re: CL_ALV_CHANGED_DATA_PROTOCOL - Protocol Popup is not modal
    if u still require any clarifications...pls let me know ur mail-id ill post my code to u ..
    thanks
    suresh

Maybe you are looking for

  • How to remove the battery on the Vado HD

    I am pulling the slot out but it won't come out. Is there some kind of tool that came in the box? The main reason I want to take out the battery is because I plugged the Vado to my t.v. using the hdmi connector and now the screen on the vado is white

  • Cannot open PDF in Firefox on MAC

    I have looked at and tried almost every single solution provided in the community support but for some reason none of them seem to work! I cannot open a PDF in Firefox no matter what! I tried going to preferences and then application and then in acti

  • Mixing Java and JavaFX

    Hola! I wondered how I could use a JavaFX class inside a Java class. Like this: FXClass.fx package fxpackage; public class FXClass  {     var chiquito: Integer; JavaClass.java package javapackage; import fxpackage.FXClass; public class JavaClass {   

  • How to fix table tags?

    Hi When I have a yellow highlighted table tag, indicating there is not a close table tag, I can never figure out where to add the closing table tag. Is there a handy helper tool to help you know how to fix a yellow highlight of an open table tag in t

  • Ipod 5th generation screen is white and black

    I can't see my music selections or any memu items (i.e. music, artists, song names, albums, etc). The screen is white on the left 3rd and grey/blackish on the right 3rd. I can hear music out of the headphones so I know that is working, but can't see