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

Function code for dropdown on OO ALV Grid to trigger user_command

Former Member
0 Likes
2,851

Hi Experts,

I know we can add a dropdown to a column of an OO ALV Grid, set values to the dropdown list and allow the user to select some these values.

However , what I'm not sure is that if we can *assign a function code to the dropdown * which would then trigger the event user_command ( PAI ) of the ALV class so I can handle the changes to when a particular value is selected from a dropdown list, just like we do in normal dialogs.

Now I know that I can register the 'Enter' event and handle the data changes in data_changed event, but that is something I want to avoid the user from doing as far as possible to make the report more user friendly.

Awaiting your valuable inputs and would really appreciate your help.

Thanks & regards,

Advait

9 REPLIES 9
Read only

Former Member
0 Likes
1,840

HI,

Check the Demo program BCALV_EDIT_06 with having the DATA_CHANGED event still you can capture the changed data.

But you cannot assign the FCODES so that the change in list box will triggere the USER_COMMAND. You need to go with DATA_CHANGED event only.

Read only

0 Likes
1,840

Hi Avinash,

Thanks for your reply.

Yes I know this example and I know how dropdown is created etc as I have mentioned this in my original post.

However to get the data_changed triggered, I need to register the Enter event and the method data_changed is called only when enter is pressed after the value changed in the dropdown.

But I need to call the data_changed immediately after the value is changed in the dropdown list without having the user to press the enter button.

Is that possible anyways ?

regards,

Advait

Read only

0 Likes
1,840

Hi,

Register you edit event with


      CALL METHOD o_alv_grid->register_edit_event
        EXPORTING
          i_event_id = cl_gui_alv=>mc_evt_modified.  "this constant will triger event change withouth ENTER key

Regards

Marcin

Read only

0 Likes
1,840

Hi Marcin,

Sorry for the late reply, was occupied in lot of things.

Thanks of your reply. It worked to some extent, as in, the event data_changed is triggered after the focus is changed from the field, but not at the very moment I change the value by selecting it from the dropdown.

I can live with that for the moment.

But any more replies are most welcome.

regards,

Advait

Read only

0 Likes
1,840

Hi Advait,

No problem. Yes, this functionality requires changing the focus to other cell.

I think there is other solution. As the dropdown is kind of F4 activity try this way:


data: it_f4 type lvc_t_f4,
        wa_f4 type lvc_s_f4.

        wa_f4-FIELDNAME = 'CONNID'.
        wa_f4-REGISTER = 'X'.
        wa_f4-GETBEFORE = 'X'.
        wa_f4-CHNGEAFTER = 'X'.
        append wa_f4 to it_f4.

"register F4 event
  CALL METHOD g_alv_grid_ref->register_f4_for_fields
    EXPORTING
      it_f4  = it_f4.

"Once you try to pick the value HANDLE_DATA_CHANGED event will be triggered

"Definition
     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,

"Implementation
METHOD handle_data_changed .
    DATA: ls_mod_cells TYPE lvc_s_modi.

    IF e_onf4_before = 'X'.
      MESSAGE 'Data changed before F4' TYPE 'I'.
    ENDIF.

    IF e_onf4 = 'X'.   "if event triggered by F4
      MESSAGE 'Data changed on F4' TYPE 'I'.
    ENDIF.

    IF e_onf4_after = 'X'.
      MESSAGE 'Data changed after F4' TYPE 'I'.
    ENDIF.


   "here you know which cell was modified
    LOOP AT er_data_changed->mt_mod_cells INTO ls_mod_cells.
      
     "just example test case, here you can implement your code for modified cells
      IF ls_mod_cells-value >=5.
        CALL METHOD er_data_changed->add_protocol_entry
          EXPORTING
            i_msgid     = 'SABAPDOCU'
            i_msgty     = 'E'
            i_msgno     = '888'
            i_msgv1     = 'Only numbers below 5 are possibe'
            i_msgv2     = 'Please correct'
            i_fieldname = ls_mod_cells-fieldname
            i_row_id    = ls_mod_cells-row_id.

        CALL METHOD er_data_changed->modify_cell
          EXPORTING
            i_fieldname = ls_mod_cells-fieldname
            i_row_id    = ls_mod_cells-row_id
            i_value     = space.

      ENDIF.
    ENDLOOP.

  ENDMETHOD.                    "handle_data_changed

This approach works fine for picking value from input help. Never tried it for dropdown list. You have to try it out.

Regards

Marcin

Read only

0 Likes
1,840

Hi Marcin,

Sounds interesting, thanks again, I will try this tomorrow for sure

regards,

Advait

Read only

ramona_wolf
Explorer
0 Likes
1,840

Hi!

I have the same question, too. If a value is selected by dropdown, another cell-value should change.

I registered the event

call method alv->register_edit_event

exporting

i_event_id = cl_gui_alv_grid=>mc_evt_modified.

But it doesn't work.

The DATA_CHANGED is just triggered when I leave to another cell, so I can't manage the done changes.

Is there another possibility to get the event?

Greetings Ramona

Read only

Former Member
0 Likes
1,840

Hi Marcin,

I tried with f4 registration, but it still didn't work the way I thought it would. However, thanks for you valuable input.

Best regards,

Advait

Read only

0 Likes
1,840

Hi Advait ,

I have got exactly similar requirement as yours ,. Could you please share how resolved this issue ? It would be of great help.

Many thanks,

Kumaran