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

save changes automatically in alvgrid

Former Member
0 Likes
1,244

Hello all,

How do i save changes automatically in alvgrid. I display data with fields which can be editable & some which are not.

The fields which are editable should be saved automatically. These fields should be saved in global internal table.

I have save button, but I invoke only when the changed data is saved in database table via global internal table.

Looking forward for your reply.

regards

Madhavi.

7 REPLIES 7
Read only

Former Member
0 Likes
1,081

You have to use the method "CHECK_CHANGED_DATA" for this purpose.

Check the standard SAP program BCALV_EDIT_04 FOR YOUR REFERENCE.

Read only

0 Likes
1,081

Hi ravi,

I use data changed for cell this code..

handle_data_changed2

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed

e_onf4_before

e_onf4_after.

In which class this "check_changed_data" present.

regards

Madhavi.

Read only

Former Member
0 Likes
1,081

Hi

Check the sample code:

*-- Display Report

CALL METHOD o_alvgrid->set_table_for_first_display

EXPORTING

i_save = c_a

is_layout = p_layout

it_toolbar_excluding = i_excl_func

CHANGING

it_outtab = p_output[]

it_fieldcatalog = p_fieldcat[]

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE s001(zesspa) WITH text-029. " Error in Displaying

LEAVE LIST-PROCESSING.

ELSE.

<b>* Register events

CALL METHOD o_alvgrid->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_enter.

CALL METHOD o_alvgrid->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_modified.

This registering event will make the data changes to be automatically update to the internal table.

Then write the code in the data changed event to modify the global internal table.

</b>

*-- ALV Grid data declaration

----


  • CLASS v_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,

ENDCLASS. "o_lcl_event_receiver DEFINITION

----


  • CLASS LCL_EVENT_RECEIVER IMPLEMENTATION

----


CLASS lcl_event_receiver IMPLEMENTATION.

    • "handle_data_changed

METHOD handle_data_changed.

PERFORM handle_data_changed USING er_data_changed.

ENDMETHOD. "handle_data_changed

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

&----


*& Form f2200_handle_data_changed

&----


  • Handle Data Changed in the ALV grid

----


FORM handle_data_changed USING ir_data_changed

TYPE REF TO

cl_alv_changed_data_protocol.

DATA : ls_mod_cell TYPE lvc_s_modi,

  • lv_value TYPE lvc_value,

lws_date TYPE scal-date.

DATA: lws_contrlife LIKE zspa_es_contlife-zzcontrlife,

lwa_contrlife TYPE zspa_es_contlife,

lws_mod_eff_code TYPE zspa_es_mod_code-zzmod_eff_code,

lwa_mod_eff_code TYPE zspa_es_mod_code.

SORT ir_data_changed->mt_mod_cells BY row_id .

LOOP AT ir_data_changed->mt_mod_cells

INTO ls_mod_cell

WHERE fieldname = text-025 "ZZCONTRLIFE

OR fieldname = text-026 "ZZMOD_EFF_CODE

OR fieldname = text-027 "DATE

OR fieldname = text-028. "CLIENT_AGGR.

READ TABLE i_final INTO wa_final

INDEX ls_mod_cell-row_id.

IF sy-subrc = 0.

IF ls_mod_cell-fieldname = text-025. "ZZCONTRLIFE

lws_contrlife = ls_mod_cell-value.

SELECT SINGLE * FROM zspa_es_contlife

INTO lwa_contrlife WHERE zzcontrlife = lws_contrlife.

IF sy-subrc NE 0.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-025

i_value = ''.

MESSAGE s001(zesspa) WITH text-035.

EXIT.

ELSE.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-025

i_value = lws_contrlife.

wa_final-zzcontrlife = lws_contrlife.

MODIFY i_final FROM wa_final INDEX ls_mod_cell-row_id.

ENDIF.

ENDIF.

IF ls_mod_cell-fieldname = text-026. "ZZMOD_EFF_CODE

lws_mod_eff_code = ls_mod_cell-value.

SELECT SINGLE * FROM zspa_es_mod_code

INTO lwa_mod_eff_code

WHERE zzmod_eff_code = lws_mod_eff_code.

IF sy-subrc NE 0.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-026

i_value = ''.

MESSAGE s001(zesspa) WITH text-036.

EXIT.

ELSE.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-026

i_value = lws_mod_eff_code.

wa_final-zzmod_eff_code = lws_mod_eff_code.

IF wa_final-zzmod_eff_code = 1 OR

wa_final-zzmod_eff_code = 2.

wa_final-date = ''.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-027

i_value = ''.

ENDIF.

MODIFY i_final FROM wa_final INDEX ls_mod_cell-row_id.

**-- No Edit control for Date when mode eff code = '1', '2'.

PERFORM no_edit_for_date TABLES i_final.

*This perform Refresh's the ALV list and Set's the Focus to

*Current Cell and keep the Scroll bar in the same place.

PERFORM alv_refresh.

ENDIF.

ENDIF.

IF ls_mod_cell-fieldname = text-027. "DATE

CONCATENATE ls_mod_cell-value+6(4)

ls_mod_cell-value+3(2)

ls_mod_cell-value+0(2) INTO lws_date.

IF lws_date NE ''.

IF lws_date > sy-datum.

wa_final-date = lws_date.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-027

i_value = lws_date.

MODIFY i_final FROM wa_final INDEX ls_mod_cell-row_id.

ELSE.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-027

i_value = ''.

MESSAGE s001(zesspa) WITH text-037.

EXIT.

ENDIF.

ENDIF.

ENDIF.

IF ls_mod_cell-fieldname = text-028. "CLIENT_AGGR

TRANSLATE ls_mod_cell-value TO UPPER CASE. "#EC SYNTCHAR

*"#EC TRANSLANG

IF ls_mod_cell-value EQ c_s OR ls_mod_cell-value EQ c_n.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-028

i_value = ls_mod_cell-value.

wa_final-client_aggr = ls_mod_cell-value.

MODIFY i_final FROM wa_final INDEX ls_mod_cell-row_id.

ELSE.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-028

i_value = ''.

MESSAGE s001(zesspa) WITH text-039.

EXIT.

ENDIF.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. " handle_data_changed

Read only

0 Likes
1,081

Hello Prakash,

You are right I use the call method

CALL METHOD o_alvgrid->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_enter.

but not this :-

CALL METHOD o_alvgrid->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_modified.

This is my present code.. can you have alook on this..

METHOD handle_data_changed1.

FIELD-SYMBOLS: <myname> TYPE ANY.

DATA: lv_fieldname(30).

*instance of internal table grid..

DATA lt_mod_cells TYPE lvc_t_modi.

DATA ls_mod_cells TYPE lvc_s_modi.

  • for grid table..

DATA ls_flp_cualcond TYPE zflp_stcualcondpri.

DATA lv_tabix TYPE sytabix.

  • assign methods to a variable..

lt_mod_cells = er_data_changed->mt_mod_cells.

LOOP AT lt_mod_cells INTO ls_mod_cells.

  • read values from gt_zflp_ttcualcondpri..

READ TABLE gt_zflp_ttcualcond INTO ls_flp_cualcond

INDEX ls_mod_cells-row_id.

CONCATENATE 'LS_FLP_CUALCOND-' ls_mod_cells-fieldname

INTO lv_fieldname.

ASSIGN (lv_fieldname) TO <myname>.

<myname> = ls_mod_cells-value.

  • move the the cells

MOVE ls_mod_cells-row_id TO lv_tabix.

IF ls_flp_cualcond-chflg NE 'I'.

ls_flp_cualcond-chflg = 'M'.

ENDIF.

*modify internal table..

MODIFY gt_zflp_ttcualcond

FROM ls_flp_cualcond

INDEX lv_tabix.

ENDLOOP.

FREE er_data_changed.

  • implement the method in alvgrid class.

CALL METHOD grid1->refresh_table_display.

LEAVE TO SCREEN '0100'.

ENDMETHOD. "handle_data_changed1

Looking forward.

Thank you

Madhavi.

Read only

0 Likes
1,081

Don't free the er_data_changed, some time that may cuase the problem. Also there is no need of LEAVE TO SCREEN '0100'.

Also use the below method after calling the set_table_for_first_display.

CALL METHOD o_alvgrid->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_modified.

Regards,

Prakash.

Read only

0 Likes
1,081

Also while looping at loop at lt_mod_cells INTO ls_mod_cells, u will directly get the field in which the change is happened. So no need of code like this:

CONCATENATE 'LS_FLP_CUALCOND-' ls_mod_cells-fieldname

INTO lv_fieldname.

ASSIGN (lv_fieldname) TO <myname>.

<myname> = ls_mod_cells-value.

  • move the the cells

MOVE ls_mod_cells-row_id TO lv_tabix.

check in debugging mode whethere data's are updated to the internal table.

Regards,

Prakash.

Read only

Former Member
0 Likes
1,081

Hello Madhavi,

When you are using the editable field in ALV.

1) frist, catch the fields or row with key fields.

2) update/modify the itab/dbtab with the help of key fields. when input is done.

That should fix the problem

thanks

SDN