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: 

Validation required on CELL in ALV using OOPs

Former Member
0 Kudos

Hi all,

I am using class CL_GUI_ALV_GRID to show the data in ALV.

In ALV on editable field is there to enter EBELN.

When i enter any value in that field and press 'ENTER', it shold fetch the LIFNR from EKKO and shows that in very next field in ALV.

Please tell me in which EVENT of CL_GUI_ALV_GRID should i write the code??

remember, i want this logic while i press ENTER or AFTER SELECTING FROM F4 DROP DOWN...

Thnaks,,,

4 REPLIES 4

former_member555112
Active Contributor
0 Kudos

Hi,

Register the DATA_CHANGED event of the ALV GRID.

Set a handler method for the same.

In the handler method fetch the required value and use the er_data_changed->modify_cell method to modify the particular cell.

For eg.

Suppose I have my grid Y_V_ROLEGRID.

I am registering the event MC_EVT_MODIFIED.

I am creating a handler Y_OBJ_ROLE_EVT_HANDLER and hanlding it via the method Y_M_HANDLE_ROLE_CELL_MODIFIED.


    CALL METHOD y_v_rolegrid->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_modified.

    CREATE OBJECT  y_obj_role_evt_handler.

    SET HANDLER y_obj_role_evt_handler->y_m_handle_role_cell_modified
    FOR y_v_rolegrid.

y_obj_role_evt_handler is of type yobj_evnt_handler

The code in the handler class is as follows:-

CLASS  yobj_evnt_handler DEFINITION.

  PUBLIC SECTION.

    METHODS y_m_handle_role_cell_modified
    FOR EVENT data_changed OF cl_gui_alv_grid
    IMPORTING er_data_changed
              e_onf4
              e_onf4_before
              e_onf4_after
              e_ucomm.
ENDCLASS

The implementation is as follows:-

CLASS yobj_evnt_handler IMPLEMENTATION.
  METHOD y_m_handle_role_cell_modified.


    y_i_mod_cell = er_data_changed->mt_mod_cells.

    LOOP AT y_i_mod_cell INTO y_wa_mod_cell
    WHERE fieldname EQ y_k_username.

            CALL METHOD er_data_changed->modify_cell
              EXPORTING
                i_row_id    = y_wa_mod_cell-row_id
                i_tabix     = y_wa_mod_cell-tabix
                i_fieldname = y_wa_mod_cell-fieldname
                i_value     = space.

  ENDLOOP.
  ENDMETHOD.
ENDCLASS

I have not pasted the entire code but I hope you will be able to understand.

Regards,

Ankur Parab

0 Kudos

Hello

Define an event handler method (e.g. HANDLE_DATA_CHANGED) for the event DATA_CHANGED.

However, I do not recommend to make the update of the LIFNR column within this method because there is a much simpler way:


METHOD handle_data_changed.

" Just trigger PAI of the dynpro by calling:
  CALL METHOD cl_gui_cfw=>set_new_ok_code
    IMPORTING
      ok_code = 'REFRESH'.

ENDMETHOD.

After finishing method HANDLE_DATA_CHANGED the program will jump to the PAI section of your screen. Importantly, your OUTTAB itab contains now already the changed EBELN value and you have a defined OK-code:


MODULE user_command_0100. " PAI

  case gd_okcode.
    WHEN '...'.

    WHEN 'REFRESH'.
      PERFORM update_list.  " routine which updates LIFNR column
    WHEN OTHERS
    ENDCASE.
ENDMODULE.

For more details you may have a look at my blog:

[A Christmas Collection of Useful Classes|https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/12377] [original link is broken] [original link is broken] [original link is broken];

Regards

Uwe

Former Member
0 Kudos

<font color="Black">

<b>Refer the following code. This is the exact way you want to do. I took this sample code from program BCALV_GRID_EDIT. it will give all the information and it will fulfill your requirement.

any clarification please ask. </b>

</font>

<font color="Blue">

<br />

<br />

TOP Module. <br />

<br />

class lcl_event_receiver definition deferred. <br />

data: event_receiver type ref to lcl_event_receiver. <br />

<br />

<br />

----


<br />

  • CLASS LCL_EVENT_RECEIVER DEFINITION <br />

----


<br />

class lcl_event_receiver definition. <br />

public section. <br />

methods handle_data_changed <br />

for event data_changed of cl_gui_alv_grid <br />

importing er_data_changed. <br />

methods handle_f4 <br />

for event onf4 of cl_gui_alv_grid <br />

importing e_fieldname <br />

es_row_no <br />

er_event_data <br />

et_bad_cells. <br />

endclass. <br />

<br />

+++++++++++++++++++++++++++++++++++++++++++++++++++ <br />

<br />

perform Module. <br />

<br />

----


<br />

  • CLASS lcl_event_receiver IMPLEMENTATION <br />

----


<br />

class lcl_event_receiver implementation. <br />

method handle_data_changed. <br />

perform data_changed using er_data_changed. <br />

endmethod. <br />

<br />

method handle_f4. <br />

perform f4 using e_fieldname <br />

es_row_no <br />

er_event_data <br />

et_bad_cells. <br />

endmethod. <br />

endclass. <br />

<br />

&----


<br />

*& Form data_changed <br />

&----


<br />

form data_changed using rr_data_changed type ref to <br />

cl_alv_changed_data_protocol. <br />

<br />

data: ls_mod_cells type lvc_s_modi. <br />

data: ls_cells type lvc_s_modi. <br />

data: l_carrid type sflight-carrid. <br />

data: l_seats type sflight-seatsocc. <br />

data: l_curr type sflight-currency. <br />

data: l_seatsmax type sflight-seatsmax. <br />

data: ls_sflight like gt_sflight1. <br />

data: ls_tcurc like tcurc. "#EC NEEDED <br />

<br />

loop at rr_data_changed->mt_good_cells into ls_mod_cells. <br />

<br />

case ls_mod_cells-fieldname. <br />

when 'CARRID'. <br />

call method rr_data_changed->get_cell_value <br />

exporting i_row_id = ls_mod_cells-row_id <br />

i_fieldname = ls_mod_cells-fieldname <br />

importing e_value = l_carrid. <br />

<br />

select single * <br />

into corresponding fields of ls_sflight <br />

from ( sflight left join scarr <br />

on sflightcarrid = scarrcarrid ) <br />

where sflight~carrid = l_carrid. <br />

<br />

if sy-subrc eq 0. <br />

<br />

call method rr_data_changed->modify_cell <br />

exporting i_row_id = ls_mod_cells-row_id <br />

i_fieldname = 'CARRNAME' <br />

i_value = ls_sflight-carrname. <br />

endif. <br />

endcase. <br />

endloop. <br />

endform. <br />

<br />

&----


<br />

*& Form F4 <br />

&----


<br />

form f4 using r_fieldname type lvc_fname <br />

rs_row_no type lvc_s_roid <br />

rr_event_data type ref to cl_alv_event_data <br />

rt_bad_cells type lvc_t_modi. "#EC * <br />

<br />

field-symbols: <lt_f4> type lvc_t_modi. <br />

data: ls_f4 type lvc_s_modi. <br />

<br />

assign rr_event_data->m_data->* to <lt_f4>. <br />

ls_f4-fieldname = r_fieldname. <br />

ls_f4-row_id = rs_row_no-row_id. <br />

ls_f4-value = 'BLUBBER'. <br />

append ls_f4 to <lt_f4>. <br />

rr_event_data->m_event_handled = 'X'. <br />

<br />

endform. <br />

<br />

+++++++++++++++++++++++++++++++++++++++++++++++++++ <br />

<br />

PBO Module. <br />

<br />

create object event_receiver. <br />

set handler event_receiver->handle_data_changed for grid1. <br />

set handler event_receiver->handle_f4 for grid1. <br />

<br />

call method grid1->register_f4_for_fields <br />

exporting it_f4 = gt_f4. <br />

<br />

call method grid1->register_edit_event <br />

exporting i_event_id = cl_gui_alv_grid=>mc_evt_modified. <br />

</font>

Former Member
0 Kudos

SOLVED