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: 

Save changes in alvgrid

Former Member
0 Kudos

Hi all,

In my alvgrid I have few columns which are editable, i edit cells, insert a new row and modify row and delete.

All these changes should be stored in internal table. I should save automaticaly when i invoke display button.

I use this code but i need the modification without tranporting the fields how do i do?

WHEN 'DISPLAY'.

PERFORM changed_data.

PERFORM filter_condpri.

WHEN 'SAVE'.

PERFORM save_data.

ENDCASE.

ENDMODULE. "pai_100 INPUT

&----


*& Module exit_0100 INPUT

&----


MODULE exit_0100 INPUT.

CASE ok_code.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " pai_100 INPUT

&----


*& Form changed_data

&----


FORM changed_data.

LOOP AT gt_zflp_ttcualcond

INTO gs_zflp_stcualcond

WHERE chflg = 'M'.

MODIFY gt_zflp_ttcualcondpri

FROM gs_zflp_stcualcond

TRANSPORTING delkzr_1 delkzr_2

delkzd_1 delkzd_2

matnr_1 matnr_2

maktx_1 maktx_2

WHERE profil = gs_zflp_stcualcond-profil

AND alcat = gs_zflp_stcualcond-alcat

AND indcopr = gs_zflp_stcualcond-indcopr

AND norule = gs_zflp_stcualcond-norule.

ENDLOOP.

LOOP AT gt_zflp_ttcualpri

INTO gs_zflp_stcualpri

WHERE chflg = 'M'.

MODIFY gt_zflp_ttcualcondpri

FROM gs_zflp_stcualpri

TRANSPORTING delkzr_1 delkzr_2

delkzd_1 delkzd_2

matnr_1 matnr_2

maktx_1 maktx_2

WHERE profil = gs_zflp_stcualpri-profil

AND alcat = gs_zflp_stcualpri-alcat

AND indcopr = gs_zflp_stcualpri-indcopr

AND norule = gs_zflp_stcualpri-norule.

ENDLOOP.

ENDFORM. "changed_data

Looking forward.

Regards

Sap team

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.</b>

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.

*-- 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

7 REPLIES 7

Former Member
0 Kudos

Former Member
0 Kudos

Check some of the standard programs:

BCALV_EDIT_01

BCALV_EDIT_02

BCALV_EDIT_03

BCALV_EDIT_04

BCALV_EDIT_05

BCALV_EDIT_06

BCALV_EDIT_07

BCALV_EDIT_08

Regards,

Prakash.

uwe_schieferstein
Active Contributor
0 Kudos

Hello

I do not fully understand what do you mean by "... need the modification without tranporting the fields...".

Does this mean that you want to know the changes yet when the ALV list is in display mode the unmodified entries should be displayed? This does not make sense to me.

In any case, you should call method <b>CHECK_DATA_CHANGED</b> at PAI. This will raise <b>event DATA_CHANGED</b> for which you should have defined an event handler method (e.g. HANDLE_DATA_CHANGED). This method has an IMPORTING parameter <b>er_data_changed</b>. This object has all information about the changes in the ALV grid:

- er_data_changed->mt_mod_cells == modified cells

- er_data_changed->mp_mod_rows == data object with modified row

- er_data_changed->mt_deleted_rows == deleted rows

- er_data_changed->mt_inserted_rows == inserted rows

Thus, you simply have to analyse these attribute of the er_data_changed object to find out what the user changed on the ALV grid.

Regards

Uwe

0 Kudos

Hello Uwe,

You are right. We can use with these importing parameters.

My question is : i want to store the modified rows & new inserted row in internal table.

I have a user defined button where I invoke this data_changed form, here i need all the modifed rows and inserted row to be saved before i click on save button. How do i do this?

I have another save button in tool bar where I invoke this for saving the modified fields in database table.

Waiting for your reply.

Regards

sap team.

0 Kudos

Hi

As have been told by Uwe

you need to use the

Method Check_Changed_Data in the PAI part.

Just cut and paste the following code it should be working after that.

data : l_valid type c value ' ',

l_refresh type c value ' '.

call method g_grid0100->check_changed_data

importing

e_valid = l_valid

changing

c_refresh = l_refresh.

Cheers

0 Kudos

Hi sushi,

I did as you said but there is no success. The values are not retained when i press "display" button.

1st time when i press "display" the 1st values I show in alvgrid. I try to change them.

2nd time when i press "display" another set of values I show. at this moment interanlly, I should retain the 1st changed values in internal table..

How do i do this? Please help me out.

Regards

Madhavi.

Former Member
0 Kudos

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.</b>

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.

*-- 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