2006 Mar 02 10:03 AM
Hi all,
The situation is:
I have an editable alv, built with ALV GRID class.
Usually I use the events BEFORE_USER_COMMAND with no problem
Now I see that with editable alv, using the DELETE button (of a row of alv) the event isn't raised?
Do anyone why and how can solv this problem?
Thanls in advantage
Andrea
2006 Mar 02 10:18 AM
have u put the SET HANDLER statement?
also u need to register for data_changed event
Message was edited by: Hymavathi Oruganti
Hi all,
The situation is:
I have an editable alv, built with ALV GRID class.
Usually I use the events BEFORE_USER_COMMAND with no problem
Now I see that with editable alv, using the DELETE button (of a row of alv) the event isn't raised?
Do anyone why and how can solv this problem?
Thanls in advantage
Andrea
2006 Mar 02 10:09 AM
Hi,
Check this Example Program<b> BCALV_EDIT_04</b> for delete and append Rows.
Regards
vijay
2006 Mar 02 10:20 AM
Hi Vijay,
I've seen the report.
But there is no way to raise the any events at the DELETE button neither the data_change event is raised by this button
bye
enzo
2006 Mar 02 10:18 AM
have u put the SET HANDLER statement?
also u need to register for data_changed event
Message was edited by: Hymavathi Oruganti
2006 Mar 02 10:26 AM
Hi Hymavathi Oruganti
yes, I put the set handler statement.
I try to make a copy of BCALV_EDIT_01 and adding the event handler class but nothing.
bye
enzo
2006 Mar 02 10:32 AM
Hi,
it should be done in the data_changed event. when ever you delete any entry it should trigger, i don't think you have implemented it properly...
can you show you local class definiton, and implementation, i am assuming that you have set the handlers for all the events..
Regards
vijay
2006 Mar 02 10:57 AM
Hi,
it's my code.
i did a copy of BCALV_EDIT_01 and I added this
THE CLASS DEFINITION AND IMPLEMENTATION.
*----------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
DATA: deleted_rows TYPE STANDARD TABLE OF za0014.
METHODS:
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm,
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object,
handle_before_user_command
FOR EVENT before_user_command OF cl_gui_alv_grid
IMPORTING e_ucomm,
handle_data_change
for event data_changed of cl_gui_alv_grid
importing e_ucomm.
ENDCLASS. "lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_toolbar.
break-point.
ENDMETHOD . "handle_toolbar
METHOD handle_user_command .
break-point.
ENDMETHOD. "handle_user_command
METHOD handle_before_user_command .
break-point.
ENDMETHOD . "handle_before_user_command
METHOD handle_data_change .
break-point.
ENDMETHOD . "handle_before_user_command
ENDCLASS. "lcl_event_handler IMPLEMENTATION
data event type ref to lcl_event_handler.
-------------------------
-------------------------
THE SET HANDLER STATEMENT
create object event.
SET HANDLER event->handle_toolbar FOR g_grid .
SET HANDLER event->handle_user_command FOR g_grid .
SET HANDLER event->handle_before_user_command FOR g_grid .
set handler event->HANDLE_DATA_CHANGE FOR G_GRID.
2006 Mar 02 11:06 AM
Hi,
use the logic from <b>BCALV_EDIT_04</b> not<b> BCALV_EDIT_01</b>. and try...BCALV_EDIT_04 this is having functionality of addition and deletion of rows.
Regards
vijay
2006 Mar 02 11:27 AM
u didnt copy REGISTER?
CALL METHOD GO_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = cl_gui_alv_grid=>mc_evt_modified.
CALL METHOD GO_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = cl_gui_alv_grid=>mc_evt_enter.
2006 May 31 12:09 PM
Hi,
I do not know if anybody will read this since the topic has been answered however I just tried the example with the additions mentioned in the last post and it does not work.
Has the issue really been answered?
Regards,
Dennis
2006 May 31 12:18 PM
Hi,
tell me what you did exactly....? and give more inputs..
Regards
vijay
Message was edited by: Vijay Babu Dudla
2006 May 31 12:28 PM
As described in the topic I copied the SAP program and made the changes and additions as mentioned in the topic. Regretfully it did not give the expected result.
Regards,
Dennis.
Copy of my program:
PROGRAM BCALV_EDIT_01.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Purpose:
~~~~~~~~
This report illustrates the simplest case of using an
editable ALV Grid Control.
Background:
~~~~~~~~~~~
As far as the edit feature is concerned
a cell of the alv grid control can have the following states:
1.non-editable : edit feature not set for this cell
2.editable : edit feature set for this cell
The second state ("editable") has two substates:
2a.editable deactivated : edit feature set but not active
3b.editable activated : edit feature set and active
In this example, all cells are set "editable".
You switch between "editable deactivated" and "editable activated"
using method SET_READY_FOR_INPUT.
*----
-
To check program behavior
~~~~~~~~~~~~~~~~~~~~~~~~~
Switch the state using the "Display/Change" icon. Initially,
the whole grid is in state "editable and deactivated".
After switching the state you may change values and enter new
lines. No semantic checks are made in this example.
*----
-
Essential steps (search for '§')
~~~~~~~~~~~~~~~
1.Set status of all cells to editable using the layout structure.
2.Use SET_READY_FOR_INPUT to deactivate the edit feature initially.
(state "editable deactivated").
3.Use IS_READY_FOR_INPUT to fetch current substate of editable cells.
4.Use SET_READY_FOR_INPUT to switch between the substates.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
DATA: ok_code LIKE sy-ucomm,
save_ok like sy-ucomm,
g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
g_grid TYPE REF TO cl_gui_alv_grid,
g_custom_container TYPE REF TO cl_gui_custom_container,
gs_layout TYPE lvc_s_layo,
g_max type i value 100.
DATA: gt_outtab type table of sflight.
*----
*
MAIN *
*----
*
CALL SCREEN 100.
*----
-
CLASS lcl_event_handler DEFINITION
*----
-
*
*----
-
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
*DATA: deleted_rows TYPE STANDARD TABLE OF za0014.
METHODS:
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm,
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object,
handle_before_user_command
FOR EVENT before_user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
*handle_data_change
*for event data_changed of cl_gui_alv_grid
*importing e_ucomm.
*
ENDCLASS. "lcl_event_handler DEFINITION
*----
-
CLASS lcl_event_handler IMPLEMENTATION
*----
-
*
*----
-
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_toolbar.
break-point.
ENDMETHOD. "handle_toolbar
METHOD handle_user_command.
break-point.
ENDMETHOD. "handle_user_command
METHOD handle_before_user_command.
break-point.
ENDMETHOD. "handle_before_user_command
*METHOD handle_data_change .
*break-point.
*ENDMETHOD . "handle_before_user_command
ENDCLASS. "lcl_event_handler IMPLEMENTATION
data event type ref to lcl_event_handler.
*----
-
*THE SET HANDLER STATEMENT
*----
*
MODULE PBO OUTPUT *
*----
*
MODULE pbo OUTPUT.
SET PF-STATUS 'MAIN100'.
set TITLEBAR 'MAIN100'.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING container_name = g_container.
CREATE OBJECT g_grid
EXPORTING i_parent = g_custom_container.
*§1.Set status of all cells to editable using the layout structure.
gs_layout-edit = 'X'.
select * from sflight into table gt_outtab up to g_max rows.
CALL METHOD g_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING it_outtab = gt_outtab.
*§2.Use SET_READY_FOR_INPUT to deactivate the edit feature initially.
(state "editable deactivated").
CALL METHOD g_grid->set_ready_for_input
EXPORTING i_ready_for_input = 0.
create object event.
SET HANDLER event->handle_toolbar FOR g_grid .
SET HANDLER event->handle_user_command FOR g_grid .
SET HANDLER event->handle_before_user_command FOR g_grid .
set handler event->HANDLE_DATA_CHANGE FOR G_GRID.
CALL METHOD G_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = cl_gui_alv_grid=>mc_evt_modified.
CALL METHOD G_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = cl_gui_alv_grid=>mc_evt_enter.
ENDIF.
ENDMODULE.
*----
*
MODULE PAI INPUT *
*----
*
MODULE pai INPUT.
save_ok = ok_code.
clear ok_code.
CASE save_ok.
WHEN 'EXIT'.
PERFORM exit_program.
WHEN 'SWITCH'.
PERFORM switch_edit_mode.
WHEN OTHERS.
do nothing
ENDCASE.
ENDMODULE.
*----
*
FORM EXIT_PROGRAM *
*----
*
FORM exit_program.
LEAVE PROGRAM.
ENDFORM.
*&----
*
*& Form SWITCH_EDIT_MODE
*&----
*
text
*----
*
--> p1 text
<-- p2 text
*----
*
FORM switch_edit_mode.
*§3.Use IS_READY_FOR_INPUT to fetch current substate of editable cells.
IF g_grid->is_ready_for_input( ) EQ 0.
*§4.Use SET_READY_FOR_INPUT to switch between the substates.
CALL METHOD g_grid->set_ready_for_input
EXPORTING i_ready_for_input = 1.
ELSE.
CALL METHOD g_grid->set_ready_for_input
EXPORTING i_ready_for_input = 0.
ENDIF.
ENDFORM. " SWITCH_EDIT_MODE
2006 May 31 12:39 PM
Hi,
check this sample code,
and let me know what problem you faced? and what changes you made in std proram...
REPORT ZTEST1234 MESSAGE-ID ZZ .
DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID, "First
G_GRID1 TYPE REF TO CL_GUI_ALV_GRID. "Second
DATA: L_VALID TYPE C,
V_FLAG,
V_DATA_CHANGE,
V_ROW TYPE LVC_S_ROW,
V_COLUMN TYPE LVC_S_COL,
V_ROW_NUM TYPE LVC_S_ROID.
DATA: OK_CODE LIKE SY-UCOMM,
SAVE_OK LIKE SY-UCOMM,
G_CONTAINER1 TYPE SCRFNAME VALUE 'TEST', "First Container
G_CONTAINER2 TYPE SCRFNAME VALUE 'TEST1',"Second container
GS_LAYOUT TYPE LVC_S_LAYO.
DATA:BEGIN OF ITAB OCCURS 0,
VBELN LIKE LIKP-VBELN,
POSNR LIKE LIPS-POSNR,
LFDAT like lips-vfdat,
BOX(1),
HANDLE_STYLE TYPE LVC_T_STYL,
END OF ITAB.
*---------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
CLASS LCL_EVENT_HANDLER DEFINITION .
PUBLIC SECTION .
METHODS:
**Hot spot Handler
HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,
**Handler to Check the Data Change
HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED
OF CL_GUI_ALV_GRID
IMPORTING ER_DATA_CHANGED
E_ONF4
E_ONF4_BEFORE
E_ONF4_AFTER,
**Double Click Handler
HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN ES_ROW_NO.
ENDCLASS. "lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
*Handle Hotspot Click
METHOD HANDLE_HOTSPOT_CLICK .
CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
V_ROW = E_ROW_ID.
V_COLUMN = E_COLUMN_ID.
V_ROW_NUM = ES_ROW_NO.
MESSAGE I000 WITH V_ROW 'clicked'.
ENDMETHOD. "lcl_event_handler
*Handle Double Click
METHOD HANDLE_DOUBLE_CLICK.
CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
V_ROW = E_ROW.
V_COLUMN = E_COLUMN.
V_ROW_NUM = ES_ROW_NO.
IF E_COLUMN = 'VBELN'.
SET PARAMETER ID 'VL' FIELD ITAB-VBELN.
CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.
ENDIF.
IF E_COLUMN = 'POSNR'.
MESSAGE I000 WITH 'Click on POSNR row number ' E_ROW.
"with this row num you can get the data
ENDIF.
ENDMETHOD. "handle_double_click
**Handle Data Change
METHOD HANDLE_DATA_CHANGED.
CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY
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.
ENDMETHOD. "HANDLE_DATA_CHANGED
ENDCLASS. "LCL_EVENT_HANDLER IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Global Definitions
*&---------------------------------------------------------------------*
DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,"Container1
G_HANDLER TYPE REF TO LCL_EVENT_HANDLER, "handler
G_CUSTOM_CONTAINER1 TYPE REF TO CL_GUI_CUSTOM_CONTAINER. "Container2
*- Fieldcatalog for First and second Report
DATA: IT_FIELDCAT TYPE LVC_T_FCAT,
X_FIELDCAT TYPE LVC_S_FCAT,
LS_VARI TYPE DISVARIANT.
*---------------------------------------------------------------------
* START-OF_SELECTION
*---------------------------------------------------------------------
START-OF-SELECTION.
SELECT VBELN
POSNR
FROM LIPS
UP TO 20 ROWS
INTO CORRESPONDING FIELDS OF TABLE ITAB.
END-OF-SELECTION.
IF NOT ITAB[] IS INITIAL.
CALL SCREEN 100.
ELSE.
MESSAGE I002 WITH 'NO DATA FOR THE SELECTION'(004).
ENDIF.
*&---------------------------------------------------------------------*
*& Form CREATE_AND_INIT_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM CREATE_AND_INIT_ALV .
DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.
"First Grid
CREATE OBJECT G_CUSTOM_CONTAINER
EXPORTING CONTAINER_NAME = G_CONTAINER1.
CREATE OBJECT G_GRID
EXPORTING I_PARENT = G_CUSTOM_CONTAINER.
"Second Grid
CREATE OBJECT G_CUSTOM_CONTAINER1
EXPORTING CONTAINER_NAME = G_CONTAINER2.
CREATE OBJECT G_GRID1
EXPORTING I_PARENT = G_CUSTOM_CONTAINER1.
* Set a titlebar for the grid control
CLEAR GS_LAYOUT.
GS_LAYOUT-GRID_TITLE = TEXT-003.
GS_LAYOUT-ZEBRA = SPACE.
GS_LAYOUT-CWIDTH_OPT = 'X'.
GS_LAYOUT-NO_ROWMARK = 'X'.
GS_LAYOUT-BOX_FNAME = 'BOX'.
GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.
GS_LAYOUT-STYLEFNAME = 'HANDLE_STYLE'.
CALL METHOD G_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.
CREATE OBJECT G_HANDLER.
SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.
* SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.
SET HANDLER G_HANDLER->HANDLE_DATA_CHANGED FOR G_GRID.
data: ls_outatb like line of itab,
v_index type sy-tabix.
DATA: LS_EDIT TYPE LVC_S_STYL,
LT_EDIT TYPE LVC_T_STYL.
LOOP AT ITAB INTO ls_outatb WHERE POSNR = '000010'.
V_INDEX = SY-TABIX.
LS_EDIT-FIELDNAME = 'VBELN'.
LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
LS_EDIT-STYLE2 = SPACE.
LS_EDIT-STYLE3 = SPACE.
LS_EDIT-STYLE4 = SPACE.
LS_EDIT-MAXLEN = 8.
INSERT LS_EDIT INTO TABLE LT_EDIT.
INSERT LINES OF LT_EDIT INTO TABLE ls_outatb-handle_style.
MODIFY ITAB INDEX V_INDEX FROM ls_outatb TRANSPORTING
HANDLE_STYLE.
ENDLOOP.
* setting focus for created grid control
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
EXPORTING
CONTROL = G_GRID.
* Build fieldcat and set editable for date and reason code
* edit enabled. Assign a handle for the dropdown listbox.
PERFORM BUILD_FIELDCAT.
* Optionally restrict generic functions to 'change only'.
* (The user shall not be able to add new lines).
PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.
**Vaiant to save the layout
LS_VARI-REPORT = SY-REPID.
LS_VARI-HANDLE = SPACE.
LS_VARI-LOG_GROUP = SPACE.
LS_VARI-USERNAME = SPACE.
LS_VARI-VARIANT = SPACE.
LS_VARI-TEXT = SPACE.
LS_VARI-DEPENDVARS = SPACE.
CALL METHOD G_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.
**Calling the Method for ALV output for First Grid
CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IT_TOOLBAR_EXCLUDING = LT_EXCLUDE
IS_VARIANT = LS_VARI
IS_LAYOUT = GS_LAYOUT
I_SAVE = 'A'
CHANGING
IT_FIELDCATALOG = IT_FIELDCAT
IT_OUTTAB = ITAB[].
**Calling the Method for ALV output for Second Grid
CALL METHOD G_GRID1->SET_TABLE_FOR_FIRST_DISPLAY
* EXPORTING
* IT_TOOLBAR_EXCLUDING = LT_EXCLUDE
CHANGING
IT_FIELDCATALOG = IT_FIELDCAT
IT_OUTTAB = ITAB[].
* Set editable cells to ready for input initially
CALL METHOD G_GRID->SET_READY_FOR_INPUT
EXPORTING
I_READY_FOR_INPUT = 1.
ENDFORM. "CREATE_AND_INIT_ALV
*&---------------------------------------------------------------------*
*& Form EXCLUDE_TB_FUNCTIONS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_EXCLUDE text
*----------------------------------------------------------------------*
FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.
* Only allow to change data not to create new entries (exclude
* generic functions).
DATA LS_EXCLUDE TYPE UI_FUNC.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
ENDFORM. " EXCLUDE_TB_FUNCTIONS
*&---------------------------------------------------------------------*
*& Form build_fieldcat
*&---------------------------------------------------------------------*
* Fieldcatalog
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT .
DATA: L_POS TYPE I.
L_POS = L_POS + 1.
X_FIELDCAT-SCRTEXT_M = 'Delivery'(024).
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-NO_ZERO = 'X'.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-OUTPUTLEN = '10'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-SCRTEXT_M = 'Item'(025).
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '5'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-SCRTEXT_M = 'Del Date'(015).
X_FIELDCAT-FIELDNAME = 'LFDAT'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '10'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
ENDFORM. " build_fieldcat
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAIN100'.
IF G_CUSTOM_CONTAINER IS INITIAL.
**Initializing the grid and calling the fm to Display the O/P
PERFORM CREATE_AND_INIT_ALV.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUTRegards
vijay
2006 May 31 3:34 PM
The additions would be:
DEFINITION
-
handle_before_user_command
FOR EVENT before_user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
IMPLEMENTATION
-
METHOD handle_before_user_command.
break-point.
ENDMETHOD. "handle_before_user_command
INITIALIZATION
-
SET HANDLER event->handle_before_user_command FOR g_grid .
CALL METHOD G_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = cl_gui_alv_grid=>mc_evt_modified.
CALL METHOD G_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = cl_gui_alv_grid=>mc_evt_enter.
Regards,
Dennis
2006 May 31 3:46 PM
Do you have any editable fields in the Output and do you have data_changed event to handle the change in the data of the grid.
Regards
Vijay
2006 May 31 4:11 PM
Yes and Yes only in the example I create there is no data_changed event.
I want to use the before_user_command event to build in a popup with an "are you sure" question.
Regards,
Dennis
2006 May 31 4:19 PM
ok , that when you want it?????????????
when you click on which button you want...?
Regards
vijay
2006 May 31 4:19 PM
Just to clarify the "before_user_command" event works for most of the buttons like "refresh" and the "sort" buttons but it does not work for the "delete row", "append row", "create row" and "duplicate row"
Regards,
Dennis
2006 May 31 4:26 PM
If you creat a copy of program BCALV_EDIT_01 (with screens etc)
and replace the code with the code below, you can do the following test.
Test:
- Run program
- Press the "Display/Change" button
- Press the first button on the alv toolbar ("Details" button) and the program will stop at a break point in method "handle_before_user_command".
- Press button "Append row" and you will notice that the break point is not reached.
The question is why does the event only work for certain buttons in the alv toolbar?
Regards,
Dennis
Copy of my program:
PROGRAM BCALV_EDIT_01.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Purpose:
~~~~~~~~
This report illustrates the simplest case of using an
editable ALV Grid Control.
Background:
~~~~~~~~~~~
As far as the edit feature is concerned
a cell of the alv grid control can have the following states:
1.non-editable : edit feature not set for this cell
2.editable : edit feature set for this cell
The second state ("editable") has two substates:
2a.editable deactivated : edit feature set but not active
3b.editable activated : edit feature set and active
In this example, all cells are set "editable".
You switch between "editable deactivated" and "editable activated"
using method SET_READY_FOR_INPUT.
*----
-
To check program behavior
~~~~~~~~~~~~~~~~~~~~~~~~~
Switch the state using the "Display/Change" icon. Initially,
the whole grid is in state "editable and deactivated".
After switching the state you may change values and enter new
lines. No semantic checks are made in this example.
*----
-
Essential steps (search for '§')
~~~~~~~~~~~~~~~
1.Set status of all cells to editable using the layout structure.
2.Use SET_READY_FOR_INPUT to deactivate the edit feature initially.
(state "editable deactivated").
3.Use IS_READY_FOR_INPUT to fetch current substate of editable cells.
4.Use SET_READY_FOR_INPUT to switch between the substates.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
DATA: ok_code LIKE sy-ucomm,
save_ok like sy-ucomm,
g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
g_grid TYPE REF TO cl_gui_alv_grid,
g_custom_container TYPE REF TO cl_gui_custom_container,
gs_layout TYPE lvc_s_layo,
g_max type i value 100.
DATA: gt_outtab type table of sflight.
*----
*
MAIN *
*----
*
CALL SCREEN 100.
*----
-
CLASS lcl_event_handler DEFINITION
*----
-
*
*----
-
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
*DATA: deleted_rows TYPE STANDARD TABLE OF za0014.
METHODS:
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm,
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object,
handle_before_user_command
FOR EVENT before_user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
*handle_data_change
*for event data_changed of cl_gui_alv_grid
*importing e_ucomm.
*
ENDCLASS. "lcl_event_handler DEFINITION
*----
-
CLASS lcl_event_handler IMPLEMENTATION
*----
-
*
*----
-
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_toolbar.
break-point.
ENDMETHOD. "handle_toolbar
METHOD handle_user_command.
break-point.
ENDMETHOD. "handle_user_command
METHOD handle_before_user_command.
break-point.
ENDMETHOD. "handle_before_user_command
*METHOD handle_data_change .
*break-point.
*ENDMETHOD . "handle_before_user_command
ENDCLASS. "lcl_event_handler IMPLEMENTATION
data event type ref to lcl_event_handler.
*----
-
*THE SET HANDLER STATEMENT
*----
*
MODULE PBO OUTPUT *
*----
*
MODULE pbo OUTPUT.
SET PF-STATUS 'MAIN100'.
set TITLEBAR 'MAIN100'.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING container_name = g_container.
CREATE OBJECT g_grid
EXPORTING i_parent = g_custom_container.
*§1.Set status of all cells to editable using the layout structure.
gs_layout-edit = 'X'.
select * from sflight into table gt_outtab up to g_max rows.
CALL METHOD g_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING it_outtab = gt_outtab.
*§2.Use SET_READY_FOR_INPUT to deactivate the edit feature initially.
(state "editable deactivated").
CALL METHOD g_grid->set_ready_for_input
EXPORTING i_ready_for_input = 0.
create object event.
SET HANDLER event->handle_toolbar FOR g_grid .
SET HANDLER event->handle_user_command FOR g_grid .
SET HANDLER event->handle_before_user_command FOR g_grid .
set handler event->HANDLE_DATA_CHANGE FOR G_GRID.
CALL METHOD G_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = cl_gui_alv_grid=>mc_evt_modified.
CALL METHOD G_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = cl_gui_alv_grid=>mc_evt_enter.
ENDIF.
ENDMODULE.
*----
*
MODULE PAI INPUT *
*----
*
MODULE pai INPUT.
save_ok = ok_code.
clear ok_code.
CASE save_ok.
WHEN 'EXIT'.
PERFORM exit_program.
WHEN 'SWITCH'.
PERFORM switch_edit_mode.
WHEN OTHERS.
do nothing
ENDCASE.
ENDMODULE.
*----
*
FORM EXIT_PROGRAM *
*----
*
FORM exit_program.
LEAVE PROGRAM.
ENDFORM.
*&----
*
*& Form SWITCH_EDIT_MODE
*&----
*
text
*----
*
--> p1 text
<-- p2 text
*----
*
FORM switch_edit_mode.
*§3.Use IS_READY_FOR_INPUT to fetch current substate of editable cells.
IF g_grid->is_ready_for_input( ) EQ 0.
*§4.Use SET_READY_FOR_INPUT to switch between the substates.
CALL METHOD g_grid->set_ready_for_input
EXPORTING i_ready_for_input = 1.
ELSE.
CALL METHOD g_grid->set_ready_for_input
EXPORTING i_ready_for_input = 0.
ENDIF.
ENDFORM. " SWITCH_EDIT_MODE
Message was edited by: Dennis
Message was edited by: Dennis
2006 May 31 4:44 PM
Hi,
Those Buttons will not respond to before user command, this is what i observed.
copy row, delete row, append row, insert row,move row,
copy, cut,paste,paste new row, undo Buttons....
if you want to check the program <b>BCALV_TEST_GRID_EVENTS</b> all buttons will respond to before usercommand, and the rest of the buttons which i mentioned won't respond , thats the reason they excluded.
Regards
vijay
2006 May 31 5:19 PM
Hi,
What I am wondering is why those buttons do not react on
the event.
Is there a setting (method) in the alv object that does allow the before_user_command event to be active for the
add, delete, etc buttons?
Regards,
Dennis
2006 Aug 28 8:30 PM
I still don't see a resolution to this problem. I too want when a user selects to Delete Row, to edit and ensure that the record can be deleleted. In my situation, if the record has been processed by payroll, we don't want to allow the user to delete the row.
Do we simply not use the before_user_command? If not then the only other option I see is define my own buttons and clone the code from the objects clear_selection method and bastardize it.
There has to be a simpler way.
2006 Mar 02 10:25 AM
Hi,
implement the delete functionality with your own delete button ,then you can easily track the user actions with handle_user_command event.
Laxman
2006 Mar 02 10:32 AM
hi
I have tried it but I prefer using the standard functionality.
maybe your's the finaly solution.
Thanks
Enzo
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |