2007 Jan 03 5:26 AM
I'm using ALV Grid of cl_gui_alv_grid class, and already registerd data_changed event.
I use two functioning :
1) when F4 Help clicked on <b>editable key fields</b>
--> delete the row and insert new row
2) when user command in ALV Grid toolbar clicked on <b>editable key fields</b>
--> insert new row
Q1. After key fields are edited, I want to delete & insert the changed data to the corresponding DB table when save button clicked.
Q2. In case 2), Is there any way to make data_changed event triggered after user command event?
2007 Jan 03 6:29 AM
Hi,
CLASS lcl_coma_list_event_receiver DEFINITION.
PUBLIC SECTION.
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.
PRIVATE SECTION.
DATA: l_data_error(1) TYPE c.
ENDCLASS.
CLASS lcl_coma_list_event_receiver IMPLEMENTATION.
** Handle DATA Changed:
METHOD handle_data_changed.
Write your own code in the handle_data_changed.
ENDCLASS.
2007 Jan 03 8:26 AM
Thank but, that's not for my case.
Editable fields in ALV Grid are key fields from user-defined DB table.
There are three key fields, first is filled and two of the rest is empty.
At first, select that records from the DB table to display in ALV Grid.
And user input two key fields using F4 help or button in toolbar of ALV Grid.
Because these fields are key, therefore if they are not initial and have some value already, so old record which is selected must be deleted and inserted to internal table like <g_deltab>. And new record with new value must be inserted to main internal table.
I need a solution or sample code to fullfill this purpose.
I aleady searched SDN but can't find something like this.
Please help ~
2007 Jan 03 10:43 AM
Hi,
Here is the sample code : Save is the pushbutton on ALV grid toolbar. Once the changes are done on the key fields, the user has to press this 'SAVE' button.
REPORT y_test_alv_data_changed.
TYPE-POOLS : icon.
TABLES : yalv_data_chg.
TYPES: BEGIN OF ty_output.
TYPES : mandt TYPE mandt,
zsmanager TYPE zsmanager,
name TYPE char30.
INCLUDE STRUCTURE zalv_data_chg.
TYPES: END OF ty_output.
DATA: i_output1 TYPE STANDARD TABLE OF ty_output WITH HEADER LINE,
i_output2 TYPE STANDARD TABLE OF ty_output WITH HEADER LINE,
i_deltab TYPE STANDARD TABLE OF ty_output WITH HEADER LINE,
o_alvgrid TYPE REF TO cl_gui_alv_grid,
o_custom_container TYPE REF TO cl_gui_custom_container,
o_container TYPE scrfname VALUE 'CUST_CTRL_200',
ok_code LIKE sy-ucomm,
wa_layout TYPE lvc_s_layo,
w_fieldcat TYPE lvc_s_fcat,
i_fieldcat TYPE lvc_t_fcat,
wa_variant LIKE disvariant.
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS:s_dtype(20) TYPE c OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK b1.
IF s_dtype = 'DECO01' .
select * from yalv_data_chg into table i_output1.
<b>*****Selecting values from DB to display</b>
i_output2[] = i_output1[].
CALL SCREEN 200.
ENDIF.
****----EVENT HANDLING.....*****
*------Class definition
CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION.
METHODS handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive.
METHODS user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
METHODS handle_data_changed_finished FOR EVENT data_changed_finished
OF cl_gui_alv_grid IMPORTING e_modified et_good_cells.
ENDCLASS. "lcl_event_handler DEFINITION
*-----Class implementation
CLASS lcl_event_handler IMPLEMENTATION.
"handle_usercom
**----Handle Toolbar
METHOD handle_toolbar.
PERFORM handle_toolbar USING e_object e_interactive.
ENDMETHOD. "handle_toolbar
**----User Command
METHOD user_command.
PERFORM user_command USING e_ucomm.
ENDMETHOD. "user_command
**----DATA changed
METHOD handle_data_changed_finished.
PERFORM handle_data_changed_finished USING
e_modified et_good_cells.
ENDMETHOD. "handle_data_changed_finished
ENDCLASS. "lcl_event_handler IMPLEMENTATION
**&----
**
**& Form data_changed
**&----
FORM handle_data_changed_finished USING i_modified TYPE char01
i_good_cells TYPE lvc_t_modi.
DATA: wa_good_cells TYPE lvc_s_modi.
READ TABLE i_output1 INDEX 1.
ENDFORM. "handle_data_changed_finished
&----
*& Module ALV_BUILD OUTPUT
&----
Alv grid
----
MODULE alv_build OUTPUT.
IF o_alvgrid IS INITIAL.
IF o_custom_container IS INITIAL.
CREATE OBJECT o_custom_container
EXPORTING container_name = o_container.
CREATE OBJECT o_alvgrid
EXPORTING i_parent = o_custom_container.
ENDIF.
wa_layout-cwidth_opt = 'X'.
wa_layout-smalltitle = 'X'.
wa_layout-grid_title = 'Data Changed'.
wa_layout-edit_mode = 'X'.
wa_layout-sel_mode = 'D'.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'ZALV_DATA_CHG'
CHANGING
ct_fieldcat = i_fieldcat.
w_fieldcat-reptext = 'Sales Manager'.
w_fieldcat-fieldname = 'ZSMANAGER'.
w_fieldcat-tabname = 'I_OUTPUT1'.
w_fieldcat-edit = 'X'.
APPEND w_fieldcat TO i_fieldcat.
CLEAR w_fieldcat.
w_fieldcat-reptext = text-001.
w_fieldcat-fieldname = 'NAME'.
w_fieldcat-tabname = 'I_OUTPUT1'.
w_fieldcat-edit = 'X'.
APPEND w_fieldcat TO i_fieldcat.
*******Setting handler
DATA: gl_event_handler TYPE REF TO lcl_event_handler,
i_toolbar_exclude TYPE ui_functions.
CREATE OBJECT gl_event_handler.
SET HANDLER gl_event_handler->handle_data_changed_finished
FOR o_alvgrid.
SET HANDLER gl_event_handler->user_command
FOR o_alvgrid.
SET HANDLER gl_event_handler->handle_toolbar FOR o_alvgrid.
PERFORM exclude_toolbar CHANGING i_toolbar_exclude.
CALL METHOD o_alvgrid->set_table_for_first_display
EXPORTING
is_variant = wa_variant
i_save = 'U'
i_default = 'X'
is_layout = wa_layout
it_toolbar_excluding = i_toolbar_exclude[]
CHANGING
it_outtab = i_output1[]
it_fieldcatalog = i_fieldcat[].
ELSE.
CALL METHOD o_alvgrid->refresh_table_display
EXPORTING
IS_STABLE =
I_SOFT_REFRESH =
EXCEPTIONS
finished = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDMODULE. "ALV_BUILD OUTPUT
&----
*& Module STATUS_0200 OUTPUT
&----
text
----
MODULE status_0200 OUTPUT.
SET PF-STATUS 'SATYA'.
SET TITLEBAR 'SATYA'.
ENDMODULE. "STATUS_0200 OUTPUT
&----
*& Module USER_COMMAND_0200 INPUT
&----
text
----
MODULE user_command_0200 INPUT.
CASE ok_code.
WHEN 'EXIT' OR 'CANC'.
LEAVE PROGRAM.
WHEN 'BACK'.
SET SCREEN '0'.
LEAVE SCREEN.
ENDCASE.
ENDMODULE. "USER_COMMAND_0200 INPUT
&----
*& Form handle_toolbar
&----
handle toolbar
----
FORM handle_toolbar USING
i_object TYPE REF TO cl_alv_event_toolbar_set
i_interactive TYPE char01.
DATA : ls_toolbar TYPE stb_button.
CLEAR ls_toolbar.
MOVE 'SAVE' TO ls_toolbar-function.
MOVE 0 TO ls_toolbar-butn_type.
MOVE icon_abap TO ls_toolbar-icon.
MOVE 'Save' TO ls_toolbar-text.
APPEND ls_toolbar TO i_object->mt_toolbar.
ENDFORM. " handle_toolbar
&----
*& Form exclude_toolbar
&----
Toolbar Exclude
----
FORM exclude_toolbar CHANGING i_toolbar_exclude TYPE ui_functions.
APPEND cl_gui_alv_grid=>mc_fc_info TO i_toolbar_exclude.
APPEND cl_gui_alv_grid=>mc_fc_sum TO i_toolbar_exclude.
APPEND cl_gui_alv_grid=>mc_fc_graph TO i_toolbar_exclude.
APPEND cl_gui_alv_grid=>mc_fc_sort TO i_toolbar_exclude.
APPEND cl_gui_alv_grid=>mc_mb_export TO i_toolbar_exclude.
APPEND cl_gui_alv_grid=>mc_mb_filter TO i_toolbar_exclude.
APPEND cl_gui_alv_grid=>mc_mb_paste TO i_toolbar_exclude.
APPEND cl_gui_alv_grid=>mc_mb_subtot TO i_toolbar_exclude.
APPEND cl_gui_alv_grid=>mc_mb_sum TO i_toolbar_exclude.
APPEND cl_gui_alv_grid=>mc_mb_variant TO i_toolbar_exclude.
APPEND cl_gui_alv_grid=>mc_mb_view TO i_toolbar_exclude.
APPEND cl_gui_alv_grid=>mc_fg_sort TO i_toolbar_exclude.
APPEND cl_gui_alv_grid=>mc_fg_edit TO i_toolbar_exclude.
APPEND cl_gui_alv_grid=>mc_fc_find TO i_toolbar_exclude.
APPEND cl_gui_alv_grid=>mc_fc_print TO i_toolbar_exclude.
ENDFORM. " exclude_toolbar
&----
*& Form user_command
&----
User Command
----
FORM user_command USING e_ucomm TYPE sy-ucomm.
CASE e_ucomm.
WHEN 'SAVE'. <b>Code for deleting old rows and inserting new rows</b>
LOOP AT i_output1.
read table i_output2 with key mandt = i_output1-mandt
zsmanager = i_output1-zsmanager
name = i_output1-name.
if sy-subrc eq 0.
move i_output1 to i_deltab.
append i_deltab.
delete i_output1.
endif.
ENDLOOP.
message s000(ZOCM) with 'Successful Updation'.
ENDCASE.
ENDFORM. " user_command
i_deltab contains the old rows to be deleted and i_output1 contains the new rows to be inserted.
-Hope this helps u.
2007 Jan 04 8:59 AM
Thanks for your concern, but it doesn't help me. I can't find the exact solution that I want.
So, I solved this using another way...
I did not use data_changed EVENT but controled directly to the related internal tables.