Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ALV cl_alv_changed_protocol->mt_mod_cells

Former Member
0 Kudos
3,043

Hello all,

I am creating an ALV grid control for a ztable.My requirement is the when the user changes any data those modified cell values has to be captured in the data_changed event.....

Any help is appreciated by rewarding points....

Thankyou,

Mili.

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Kudos
1,318

Hello Mili

You have to call method go_grid->check_changed_data( ) at PAI of your screen. This will trigger event DATA_CHANGED if data of the editable ALV have been changed.

Define an event handler method for this event (e.g. HANDLE_DATA_CHANGED). The IMPORTING parameter ER_DATA_CHANGED of the event interface contains all changes.

For details please refer to:

[ALV GRID Problem with reading contents|;

[Where/how would you add the actual DB update to BCALV_EDIT_03?|;

Regards

Uwe

5 REPLIES 5
Read only

uwe_schieferstein
Active Contributor
0 Kudos
1,319

Hello Mili

You have to call method go_grid->check_changed_data( ) at PAI of your screen. This will trigger event DATA_CHANGED if data of the editable ALV have been changed.

Define an event handler method for this event (e.g. HANDLE_DATA_CHANGED). The IMPORTING parameter ER_DATA_CHANGED of the event interface contains all changes.

For details please refer to:

[ALV GRID Problem with reading contents|;

[Where/how would you add the actual DB update to BCALV_EDIT_03?|;

Regards

Uwe

Read only

1,318

Hi Uwe

You don't actually have to do this at PAI

You can do this in your event handler.

I'm using a self defined Z class (ZCL_GUI_ALV_GRID) but essentially references cl_gui_alv_grid and one of the method parameters is the name of the calling program but otherwise the code is simple and fairly self explanatory.



method constructor .
create object grid_container1
        exporting
*           container_name = 'CCONTAINER1'.
    container_name = cfname.
    create object  grid1
       exporting
          i_parent = grid_container1.
    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.
    set handler z_object->on_hotspot for grid1.
    call method grid1->register_edit_event
        exporting
           i_event_id = cl_gui_alv_grid=>mc_evt_enter.
  endmethod.


method handle_data_changed .
* Insert user code here if required
* this METHOD is entered if user ENTERS DATA.
    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.

Then in your application program code the following



FORM data_changed
USING
  changed_tab
  inserted_tab
  deleted_tab
  modified_cells_tab.
break-point 2.
  ASSIGN  changed_tab->* TO <fs1>.
* code anything here to be done when data in the grid is changed.
ENDFORM.

Note so long as you've registered the event ENTER then you'll get control at Data Changed and Data Changed finished.

If you do this in the CONSTRUCTOR Method (code as above) then after you've displayed your grid (normally in the PBO) you will raise the event data changed after you change any cell directly without needing to use the PAI.

Much easier than messing around in the PAI.

Cheers

jimbo

Read only

0 Kudos
1,318

Hello all,

Thank you for all the replies....

Now I have a different issue.

I am using atrribute mc_style_enabled to make the table editable except for the key fields,when the user hit the button change.

It is working fine.......

After making changes in the table, when the user hits SAVE, I am making the table first to uneditable and updating the ZTABLE(as per requirement).

IF the user hits the change button again to make it editable I am getting a short dump ITAB_DUPLICATE_KEYS.

My sample code looks like this:

FORM adjust_editables USING pt_list LIKE gt_list[] .
DATA ls_listrow LIKE LINE OF pt_list .
DATA ls_stylerow TYPE lvc_s_styl .
DATA lt_styletab TYPE lvc_t_styl .
LOOP AT pt_list INTO ls_listrow .

ls_stylerow-fieldname = 'SEATSMAX' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled .
APPEND ls_stylerow TO lt_styletab .

ls_stylerow-fieldname = 'PLANETYPE' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled .
APPEND ls_stylerow TO lt_styletab .


INSERT LINES OF lt_styletab INTO ls_listrow-cellstyles.
MODIFY pt_list FROM ls_listrow .
ENDLOOP .
ENDFORM .

I am getting error at the INSERT LINES statement.

ANY HELP IS APPRECIATED BY REWARDING POINTS.

Thank you,

Mili

Read only

0 Kudos
1,318

Hello Mili

LVC_T_STYL is sorted table type. Therefore, you must not add entries with identical key fields to this itab.

Simply change your coding as following and it will work:


"FORM adjust_editables USING pt_list LIKE gt_list[] .  " poor programming
FORM adjust_editables CHANGING pt_list LIKE gt_list[] .

DATA ls_listrow LIKE LINE OF pt_list .
DATA ls_stylerow TYPE lvc_s_styl .
DATA lt_styletab TYPE lvc_t_styl .


LOOP AT pt_list INTO ls_listrow .

  REFRESH: ls_listrow-cellstyles.  " initialize sorted itab!!!
 
ls_stylerow-fieldname = 'SEATSMAX' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled .
* APPEND ls_stylerow TO lt_styletab .  " add empty record?
INSERT ls_stylerow INTO TABLE lt_styletab.  " sorted itab !!!
 
ls_stylerow-fieldname = 'PLANETYPE' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled .
* APPEND ls_stylerow TO lt_styletab .  " add empty record?
INSERT ls_stylerow INTO TABLE lt_styletab.  " sorted itab !!!
 
 
*INSERT LINES OF lt_styletab INTO ls_listrow-cellstyles.
INSERT LINES OF lt_styletab INTO TABLE ls_listrow-cellstyles.  " sorted itab!!!

  MODIFY pt_list FROM ls_listrow .
ENDLOOP .

ENDFORM .

Regards

Uwe

Read only

mnicolai_77
Active Participant
0 Kudos
1,318

hi,

try this way.

After the method set table for first display register the event enter.


CALL METHOD alv->set_table_for_first_display
      EXPORTING
        is_layout                     = ls_layo
        it_toolbar_excluding          = lt_exclude[]
      CHANGING
        it_outtab                     = <fs_outtab>[]
        it_fieldcatalog               = lt_fieldcat[]
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        OTHERS                        = 4.

    CREATE OBJECT event_handler
                    EXPORTING
                        dynnr = dynnr.

    CALL METHOD alv->register_edit_event
      EXPORTING
        i_event_id = alv->mc_evt_enter.

    CALL METHOD alv->activate_display_protocol
      EXPORTING
        i_dialog = ' '.

    SET HANDLER event_handler->data_changed                FOR  alv.
    SET HANDLER event_reciver->data_changed_finished       FOR  alv.

and so every time that a user press the enter button or another button on the alv grid toolbar this method start


  METHOD data_changed.
    DATA: ls_fcat TYPE lvc_s_fcat.
    DATA: structure TYPE REF TO data.
    DATA: ls_modi TYPE lvc_s_modi.
    DATA: tabix TYPE i.
    FIELD-SYMBOLS: <itab> TYPE ANY TABLE,
                   <struct> TYPE ANY.
    CHECK e_onf4 IS INITIAL.

    READ TABLE er_data_changed->mt_fieldcatalog INTO ls_fcat
                                INDEX 1.

    CREATE DATA structure TYPE (ls_fcat-ref_table).

    ASSIGN structure->* TO <struct> CASTING TYPE (ls_fcat-ref_table).

    ASSIGN er_data_changed->mp_mod_rows->* TO <itab>.

    LOOP AT <itab> ASSIGNING <struct>.
      MOVE sy-tabix TO tabix.

      READ TABLE er_data_changed->mt_mod_cells INTO ls_modi
                                  WITH KEY tabix = tabix.

      CALL METHOD alv_gest->(ls_fcat-ref_table)
        EXPORTING
          data_changed = er_data_changed
          struct       = <struct>
          tabix        = tabix
          row_id       = ls_modi-row_id.

    ENDLOOP.
  ENDMETHOD.                    "data_changed

Hope that is useful

Bye.