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: 

ALV Grid default values for new rows added with Add/Insert buttons

Former Member
0 Kudos

Hi!

Help, please, to find a way how to set default values for new rows added with Add/Insert buttons in

ALV Grid.

1 REPLY 1

Former Member
0 Kudos

I have found salution:

ALV Grid u2013 Insert row function

Sometimes we need to assign some default values when we create a new row in a grid using standard ALV Append row button. In our scenario we will see how to assign default values to Airline Code (CARRID), Flight Connection Number (CONNID) and Flight date (FLDATE) when a new row is created. To do that we need to handle DATA_CHANGED event in the program like mentioned below.

Definition of a class:

Code:

----


  • CLASS lcl_event_receiver DEFINITION

----


  • ........ *

----


CLASS LCL_EVENT_RECEIVER DEFINITION.

*.............

PUBLIC SECTION.

METHODS:

handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed

e_ucomm.

ENDCLASS. "lcl_event_receiver DEFINITION

Implementation of a class:

Code:

*----


*

CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.

METHOD HANDLE_DATA_CHANGED.

DATA: dl_ins_row TYPE lvc_s_moce. " Insert Row

FIELD-SYMBOLS: <fs> TYPE table. " Output table

  • Loop at the inserted rows table and assign default values

LOOP AT er_data_changed->mt_inserted_rows INTO dl_ins_row.

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

loop at <fs> into ls_outtab.

ls_outtab-carrid = 'LH'.

ls_outtab-connid = '400'.

ls_outtab-fldate = sy-datum.

MODIFY <fs> FROM ls_outtab INDEX sy-tabix.

endloop.

endloop.

ENDMETHOD. "handle_data_changed

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

*----


*

Register the events to trigger DATA_CHANGED event when a new row is created.

Code:

CALL METHOD OBJ_GRID->REGISTER_EDIT_EVENT

EXPORTING

I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.

CALL METHOD OBJ_GRID->REGISTER_EDIT_EVENT

EXPORTING

I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.