Application Development 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: 

Need help with CL_ALV_CHANGED_DATA_PROTOCOL

Former Member

Hello,

I have another ALV Problem. I check all the entered data in the events data_changed and data_changed_finished. Works fine. Now I want to check the internal table from my alv grid at USER_COMMAND SAVE. I use class CL_ALV_CHANGED_DATA_PROTOCOL to create a message protocol.

Here's what I've done.

Data my_proto type ref to cl_alv_changed_data_protocol.

create object my_proto exporting i_calling_alv = grid_100 .

call method grid_100->get_frontend_fieldcatalog 
           importing
                     et_fieldcatalog   = my_proto->mt_fieldcat.

call method my_proto->add_protocol_entry 
           exporting i_msgid = '0K' 
                     i_msgno = '000' 
                     i_msgty = 'I' 
                     i_msgv1 = text-007 
                     i_msgv2 = text-008 
                     i_fieldname = 'MATNR'
                     i_row_id    = 1.
call method my_proto->display_protocol

call method my_proto>display_protocol.

The protocoll dialog is diplayed but the column is not marked. How can I do it?

Thank you

Gregor

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos

Since you are instantiating the object MY_PROTO, it would not be integrated to your ALV instance.

You can save the instance ER_DATA_CHANGED as an attribute in your event handler class. This ER_DATA_CHANGED would be available to you when you handle the event DATA_CHANGED. Once you have the attribute refercing to the CL_ALV_CHANGED_DATA_PROTOCOL, you can use the method ADD_PROTOCOL_ENTRY to add messages and DISPLAY_PROTOCOL to display the messages.

Regards,

Naimesh Patel

8 REPLIES 8

naimesh_patel
Active Contributor
0 Kudos

Since you are instantiating the object MY_PROTO, it would not be integrated to your ALV instance.

You can save the instance ER_DATA_CHANGED as an attribute in your event handler class. This ER_DATA_CHANGED would be available to you when you handle the event DATA_CHANGED. Once you have the attribute refercing to the CL_ALV_CHANGED_DATA_PROTOCOL, you can use the method ADD_PROTOCOL_ENTRY to add messages and DISPLAY_PROTOCOL to display the messages.

Regards,

Naimesh Patel

0 Kudos

thank you for your answer but the Problem is still the same.

Here what I did:

FORM data_changed_finished USING  lr_data_changed TYPE REF TO
                                         cl_alv_changed_data_protocol.
  gr_data_changed = lr_data_changed.
.
.
.
ENDFORM.

IN PAI

MODULE user_command_0100 INPUT.
  DATA: lv_valid(1) TYPE c.
  DATA: lv_refresh TYPE c VALUE 'X'.
  CASE ok_code.
    WHEN 'SAVE'.
      CALL METHOD gr_grid1->check_changed_data
        IMPORTING
          e_valid   = lv_valid
        CHANGING
          c_refresh = lv_refresh.
      IF lv_valid = 'X'.

        CALL METHOD gr_data_changed->add_protocol_entry
          EXPORTING
            i_msgid     = 'M3'
            i_msgty     = 'E'
            i_msgno     = '305'
       i_msgv1     = 'BlaBla'
*    i_msgv2     =
*    i_msgv3     =
*    i_msgv4     =
            i_fieldname = 'MATNR'
             i_row_id    = 1
*    i_tabix     =
            .
        CALL METHOD gr_data_changed->display_protocol.

The Message Protocol is shown but the field in ALV Grid is not red marked.

What can I do?

Thanks!

Gregor

Edited by: Gregor Sure on Oct 15, 2009 8:24 AM

0 Kudos

When you call the method CHECK_CHANGED_DATA of the ALV grid, it would internally raise the event DATA_CHANGED. If you have handled this event, then you would be properly access the ER_DATA_CHANGED in your Event handler method. So, try to call the method ADD_PROTOCOL_ENTRY in the event handler method of the event DATA_CHANGED.

Regards,

Naimesh Patel

0 Kudos

I have handled data_changed but its not working because no changes have been made.

Here's my code:

class lcl_event_receiver implementation.
  method handle_data_changed.
    perform data_changed using er_data_changed.
  endmethod.                    "handle_data_changed

  method handle_data_changed_finished.
    perform data_changed_finished using er_data_changed.
  endmethod.                    "handle_data_changed_finished

class lcl_event_receiver definition.
  public section.
    methods handle_data_changed
      for event data_changed of cl_gui_alv_grid
      importing er_data_changed.

    methods handle_data_changed_finished
      for event data_changed of cl_gui_alv_grid
      importing er_data_changed.

module user_command_0100 input.
  data: lv_valid(1) type c.
  data: lv_refresh type c value 'X'.
  data: lr_save_data type ref to cl_alv_changed_data_protocol.
  data: lv_value type lvc_value.
  data: ls_scol type lvc_s_scol.
  case ok_code.
    when 'SAVE'.
        call method gr_grid1->refresh_table_display
          exporting
            is_stable = gc_stable
          exceptions
            finished  = 1
            others    = 2.
        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 gr_grid1->check_changed_data
        importing
          e_valid   = lv_valid
        changing
          c_refresh = lv_refresh.
      if lv_valid = 'X'.
        if gr_data_changed is initial.

FORM data_changed USING  lr_data_changed TYPE REF TO
                                         cl_alv_changed_data_protocol.

  DATA: ls_mod_cells TYPE lvc_s_modi.
  DATA: ls_cells TYPE lvc_s_modi,
        lv_value TYPE lvc_value ,
        lv_matnr TYPE matnr,
        lv_maktx TYPE maktx,
        lv_meins TYPE meins,
        lv_error TYPE c.
  DATA: ls_result LIKE gs_result,
      lv_zetikett TYPE zmm_inv_iseg-zetikett,
      lv_zzeile TYPE zmm_inv_iseg-zzeile.
  CLEAR lv_error.

  DATA: ls_deleted_rows LIKE LINE OF lr_data_changed->mt_deleted_rows.
*   data is deleted or not. If yes, than fill the temporary table to
*   its copy

break-point.

regards

Gregor

0 Kudos

Change the sequence of the method call CHECK_CHANGED_DATA and REFRESH_TABLE_DISPLAY. Ideally the flow should be:

1. Call method CHECK_CHANGED_DATA, import parameters VALID and REFERSH

2. If valid, do the DATA_SAVE process

3. If the REFRESH required, call the method REFRESH_TABLE_DISPLAY

Regards,

Naimesh Patel

0 Kudos

You are right. In case of changes my subroutines: data_changed and data_changed_finished is working. Also when I click on save. In that case I would be able to check the required things.

Thats a code spippet from BCALV_EDIT_04

* §7.Check if any errors exist in protocol by using method
*    CHECK_CHANGED_DATA of your ALV Grid instance.

* The method CHECK_CHANGED_DATA checks all new cells syntactically,
* raises event DATA_CHANGED and looks then for any entries
* in the error protocol. If any exist the parameter e_valid
* is initial ('X' in the other case).

But in my case I have for example three fields (MATNR, MENGE, ZSTATUS, The User entered only one (MATNR). The entered data is correct (MATNR is in MARA). If I would check the other two fields at that moment because they are mandatory, the user would get two errors that he have to enter some data for the rest of the fields. Since the user have to fill a lot of data in my application I would like to check that when the user wants to save. Otherwise he would have to close the messagebox after every entered field.

Maybe it's because I'm using Register_edit_event to show the Material short text after the User has entered the Material. I think if I would not check the fields after enter or modified it should work with the problem that the short text will only be showed after the User pressed on Check data icon or SAVE.

call method gr_grid1->register_edit_event
        exporting
          i_event_id = cl_gui_alv_grid=>mc_evt_modified.

      call method gr_grid1->register_edit_event
        exporting
          i_event_id = cl_gui_alv_grid=>mc_evt_enter.

If I'm wrong, please place some Code Snippets how you would realize that.

regards

Gregor

Edited by: Gregor Sure on Oct 16, 2009 9:38 AM

Edited by: Gregor Sure on Oct 16, 2009 9:40 AM

Edited by: Gregor Sure on Oct 16, 2009 9:42 AM

0 Kudos

You may try using only the DATA_CHANGED event, not the DATA_CHANGED_FINISHED.

Instead of Displaying the Protocol in the Popup, you can display it in another custom container on the screen. This way it would be less annoying to users.

Check the program BCALV_GRID_EDIT. Run by selecting the checkbox "Error Log on Screen". TO get it the protocol on the screen instead of the popup, you need to create a container on your screen and specify it while instantiating the GRID object. Like:


    create object grid1
           exporting i_parent = g_custom_container
                     i_applogparent = g_custom_container2.  " << For Protocol

Regards,

Naimesh Patel

Former Member
0 Kudos

Hello Sure .....

one thing u can do ...upon user actions , u can call call method g_grid%->check_changed_data.

so that u can put validations in that event - data_changed .

regards

Prabhu