2006 May 31 8:36 AM
Hi,
1. What is the event available to handle toolbar clicks: insert row, delete row?
2. With answer to 1, do I need to register the event first?
Thanks
Rgds,
ET
2006 May 31 8:50 AM
Hi,
I guess there is not an event to directly add or delete row n class CL_GUI_ALV_GRID.
U need to add button for add/delete in toolbar using event toolbar.
Then check for usercommand.
U can do that in event USER_COMMAND.
Check for the sy-ucomm.
Then process and add or delete the row.
Regards,
Tanveer.
Hi,
1. What is the event available to handle toolbar clicks: insert row, delete row?
2. With answer to 1, do I need to register the event first?
Thanks
Rgds,
ET
2006 May 31 8:40 AM
Yes, you need to register the events first.
Refer the working code by Vijay Babu Dudla.
REPORT ZTEST1234_ALV_TOP MESSAGE-ID ZZ .
DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.
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: IT_ROW_NO TYPE LVC_T_ROID,
X_ROW_NO TYPE LVC_S_ROID.
DATA:BEGIN OF ITAB OCCURS 0,
VBELN LIKE LIKP-VBELN,
POSNR LIKE LIPS-POSNR,
CELLCOLOR TYPE LVC_T_SCOL, "required for color
DROP(10),
END OF ITAB.
"The Below Definitions Must.....
DATA:
* Reference to document
DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT,
* Reference to split container
DG_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
* Reference to grid container
DG_PARENT_GRID TYPE REF TO CL_GUI_CONTAINER,
* Reference to html container
DG_HTML_CNTRL TYPE REF TO CL_GUI_HTML_VIEWER,
* Reference to html container
DG_PARENT_HTML TYPE REF TO CL_GUI_CONTAINER.
"up to here
*---------------------------------------------------------------------*
* 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,
**Double Click Handler
HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN ES_ROW_NO,
TOP_OF_PAGE FOR EVENT TOP_OF_PAGE "event handler
OF CL_GUI_ALV_GRID
IMPORTING E_DYNDOC_ID.
*
* END_OF_LIST FOR EVENT end_of_list "event handler
* OF CL_GUI_ALV_GRID
* IMPORTING E_DYNDOC_ID.
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'.
CLEAR IT_ROW_NO[].
X_ROW_NO-ROW_ID = V_ROW.
APPEND X_ROW_NO TO IT_ROW_NO .
CALL METHOD G_GRID->SET_SELECTED_ROWS
EXPORTING
IT_ROW_NO = IT_ROW_NO.
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'.
SET PARAMETER ID 'VL' FIELD ITAB-VBELN.
CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN."
ENDIF.
ENDMETHOD. "handle_double_click
* METHOD END_OF_LIST. "implementation
** Top-of-page event
* PERFORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID.
* ENDMETHOD. "top_of_page
METHOD TOP_OF_PAGE. "implementation
* Top-of-page event
PERFORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID.
ENDMETHOD. "top_of_page
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
DATA: OK_CODE LIKE SY-UCOMM,
SAVE_OK LIKE SY-UCOMM,
G_CONTAINER1 TYPE SCRFNAME VALUE 'TEST',
GS_LAYOUT TYPE LVC_S_LAYO.
data: v_lines type i.
data: v_line(3) type c.
*- 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.
describe table itab lines v_lines.
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.
"attention.....from here
"split your container here...into two parts
"create the container
CREATE OBJECT G_CUSTOM_CONTAINER
EXPORTING CONTAINER_NAME = G_CONTAINER1.
"this is for top of page
* Create TOP-Document
CREATE OBJECT DG_DYNDOC_ID
EXPORTING STYLE = 'ALV_GRID'.<b>Reward points if it helps.</b>
Message was edited by: Amit Mishra
2006 May 31 8:40 AM
You need to set the handler for the event.
USER_COMMAND - To handle the clicks
TOOLBAR - To add buttons to the toolbar
You don't have to register, setting the handler will do the job. Take a look at BCALV_TEST_GRID_TOOLBAR. If you are editing the fields, then you will have to register the EDIT event.
Regards,
Ravi
Message was edited by: Ravikumar Allampallam
2006 May 31 8:42 AM
Hi,
You have to use
FORM handle_user_command USING i_ucomm TYPE syucomm .
CASE i_ucomm .
WHEN 'ADD' .
"Processing
ENDCASE.to perform operations for buttons.
2006 May 31 8:43 AM
Hi,
check this demo program<b> BCALV_EDIT_04</b>
no need to register the events as such , but you need to have a local event handler and you need to set the handler for the grid to respond.
Regards
vijay
2006 May 31 8:46 AM
Thanks all.
But what if my ALV toolbar button are the standard ones?
I don't mean creation of new buttons in the toolbar and handling the new button.
Rgds,
ET
2006 May 31 8:50 AM
Hi,
Check this program <b>BCALV_EDIT_04</b> it is explained very well. and your doubts will be cleared. here they handled insert and append rows fucntionality.
Regards
vijay
2006 May 31 8:50 AM
Hi,
For the standard ones you may have to process in:
FORM handle_before_user_command USING i_ucomm TYPE syucomm .
2006 May 31 9:01 AM
Hi,
Event before_user_command is not triggered when i click on the standard buttons of the ALV toolbar. Any idea?
Rgds,
ET
2006 May 31 9:05 AM
Hi,
The events will not fire for the standard toolbar buttons.
Regards,
Ravi
2006 May 31 9:16 AM
Hi Ravikumar,
The event before_user_command will get triggered when you click on any standard button.
Ps: Check whether you have added the handle for the event...
*In class declaration
METHODS handle_before_user_command FOR EVENT before_user_command
OF cl_gui_alv_grid.
*Class definition
METHOD handle_before_user_command.
PERFORM handle_before_user_command USING i_ucomm .
ENDMETHOD.
*Add handler
SET HANDLER g_handler->handle_before_user_command
FOR g_grid.
*The form that would get triggered
form handle_before_user_command using p_i_ucomm.
BREAK-POINT.
endform.
Try this code...
DATA: g_grid TYPE REF TO cl_gui_alv_grid.
DATA i_ucomm LIKE sy-ucomm.
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.
"The Below Definitions Must.....
DATA:
* Reference to document
dg_dyndoc_id TYPE REF TO cl_dd_document,
* Reference to split container
dg_splitter TYPE REF TO cl_gui_splitter_container,
* Reference to grid container
dg_parent_grid TYPE REF TO cl_gui_container,
* Reference to html container
dg_html_cntrl TYPE REF TO cl_gui_html_viewer,
* Reference to html container
dg_parent_html TYPE REF TO cl_gui_container.
"up to here
*---------------------------------------------------------------------*
* 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,
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column es_row_no,
top_of_page FOR EVENT top_of_page "event handler
OF cl_gui_alv_grid
IMPORTING e_dyndoc_id.
METHODS handle_before_user_command FOR EVENT before_user_command
OF cl_gui_alv_grid.
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.
ENDMETHOD. "handle_double_click
METHOD top_of_page. "implementation
* Top-of-page event
PERFORM event_top_of_page USING dg_dyndoc_id.
ENDMETHOD. "top_of_page
METHOD handle_before_user_command.
PERFORM handle_before_user_command USING i_ucomm .
ENDMETHOD.
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
DATA: ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm,
g_container1 TYPE scrfname VALUE 'TEST',
gs_layout TYPE lvc_s_layo.
*- 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.
DATA:BEGIN OF itab OCCURS 0,
vbeln LIKE likp-vbeln,
posnr LIKE lips-posnr,
cellcolor TYPE lvc_t_scol, "required for color
drop(10),
END OF itab.
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.
"attention.....from here
"split your container here...into two parts
"create the container
CREATE OBJECT g_custom_container
EXPORTING container_name = g_container1.
"this is for top of page
* Create TOP-Document
CREATE OBJECT dg_dyndoc_id
EXPORTING style = 'ALV_GRID'.
* Create Splitter for custom_container
CREATE OBJECT dg_splitter
EXPORTING parent = g_custom_container
rows = 2
columns = 1.
* Split the custom_container to two containers and move the reference
* to receiving containers g_parent_html and g_parent_grid
"i am allocating the space for grid and top of page
CALL METHOD dg_splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = dg_parent_html.
CALL METHOD dg_splitter->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = dg_parent_grid.
"you can set the height of it
* Set height for g_parent_html
CALL METHOD dg_splitter->set_row_height
EXPORTING
id = 1
height = 5.
"from here as usual..you need to specify parent as splitter part
"which we alloted for grid
CREATE OBJECT g_grid
EXPORTING i_parent = dg_parent_grid.
* 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-ctab_fname = 'CELLCOLOR'.
CALL METHOD g_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
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->top_of_page FOR g_grid.
SET HANDLER g_handler->handle_before_user_command
FOR g_grid.
DATA: ls_cellcolor TYPE lvc_s_scol. "required for color
DATA: l_index TYPE sy-tabix.
"Here i am changing the color of line 1,5,10...
"so you can change the color of font conditionally
LOOP AT itab.
l_index = sy-tabix.
IF l_index = 1 OR l_index = 5 OR l_index = 10.
ls_cellcolor-fname = 'VBELN'.
ls_cellcolor-color-col = '6'.
ls_cellcolor-color-int = '0'.
ls_cellcolor-color-inv = '1'.
APPEND ls_cellcolor TO itab-cellcolor.
MODIFY itab INDEX l_index TRANSPORTING cellcolor.
ls_cellcolor-fname = 'POSNR'.
ls_cellcolor-color-col = '6'.
ls_cellcolor-color-int = '0'.
ls_cellcolor-color-inv = '1'.
APPEND ls_cellcolor TO itab-cellcolor.
MODIFY itab INDEX l_index TRANSPORTING cellcolor.
ENDIF.
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.
PERFORM set_drdn_table.
* 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.
**Calling the Method for ALV output
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[].
"do these..{
* Initializing document
CALL METHOD dg_dyndoc_id->initialize_document.
* Processing events
CALL METHOD g_grid->list_processing_events
EXPORTING
i_event_name = 'TOP_OF_PAGE'
i_dyndoc_id = dg_dyndoc_id.
"end }
* 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 = 'IT_FINAL'.
x_fieldcat-col_pos = l_pos.
x_fieldcat-no_zero = 'X'.
x_fieldcat-outputlen = '10'.
x_fieldcat-hotspot = 'X'.
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 = 'IT_FINAL'.
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 = 'Drop'(025).
x_fieldcat-fieldname = 'DROP'.
x_fieldcat-tabname = 'IT_FINAL'.
x_fieldcat-col_pos = l_pos.
x_fieldcat-outputlen = '5'.
x_fieldcat-edit = 'X'.
x_fieldcat-drdn_hndl = '1'.
x_fieldcat-drdn_alias = 'X'.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.
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 INPUT
*&---------------------------------------------------------------------*
*& Form SET_DRDN_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM set_drdn_table.
DATA:lt_dral TYPE lvc_t_dral,
ls_dral TYPE lvc_s_dral.
LOOP AT itab .
* First listbox (handle '1').
IF sy-index = 1.
ls_dral-handle = '1'.
ls_dral-value = ' '.
ls_dral-int_value = ' '.
ELSE.
ls_dral-handle = '1'.
ls_dral-value = itab-posnr.
ls_dral-int_value = itab-posnr.
ENDIF.
APPEND ls_dral TO lt_dral.
ENDLOOP.
**Setting the Drop down table for Reason Code
CALL METHOD g_grid->set_drop_down_table
EXPORTING
it_drop_down_alias = lt_dral.
ENDFORM. " set_drdn_table
*&---------------------------------------------------------------------*
*& Form EVENT_TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->DG_DYNDOC_ID text
*----------------------------------------------------------------------*
FORM event_top_of_page USING dg_dyndoc_id TYPE REF TO cl_dd_document.
"this is more clear.....check it
"first add text, then pass it to comentry write fm
DATA : dl_text(255) TYPE c. "Text
* Populating header to top-of-page
CALL METHOD dg_dyndoc_id->add_text
EXPORTING
text = 'Test Report'
sap_style = cl_dd_area=>heading.
* Add new-line
CALL METHOD dg_dyndoc_id->new_line.
CLEAR : dl_text.
* Move program ID
CONCATENATE 'Program Name :' sy-repid
INTO dl_text SEPARATED BY space.
* Add Program Name to Document
PERFORM add_text USING dl_text.
* Add new-line
CALL METHOD dg_dyndoc_id->new_line.
CLEAR : dl_text.
* Move User ID
CONCATENATE 'User ID :' sy-uname INTO dl_text SEPARATED BY space .
* Add User ID to Document
PERFORM add_text USING dl_text.
* Add new-line
CALL METHOD dg_dyndoc_id->new_line.
CLEAR : dl_text.
* Move Client
CONCATENATE 'Client :' sy-mandt INTO dl_text SEPARATED BY space.
* Add Client to Document
PERFORM add_text USING dl_text.
* Add new-line
CALL METHOD dg_dyndoc_id->new_line.
CLEAR : dl_text.
* Move date
WRITE sy-datum TO dl_text.
CONCATENATE 'Date :' dl_text INTO dl_text SEPARATED BY space.
* Add Date to Document
PERFORM add_text USING dl_text.
* Add new-line
CALL METHOD dg_dyndoc_id->new_line.
CLEAR : dl_text.
* Move time
WRITE sy-uzeit TO dl_text.
CONCATENATE 'Time :' dl_text INTO dl_text SEPARATED BY space.
* Add Time to Document
PERFORM add_text USING dl_text.
* Add new-line
CALL METHOD dg_dyndoc_id->new_line.
* Populating data to html control
PERFORM html.
ENDFORM. " EVENT_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form ADD_TEXT
*&---------------------------------------------------------------------*
* To add Text
*----------------------------------------------------------------------*
FORM add_text USING p_text TYPE sdydo_text_element.
* Adding text
CALL METHOD dg_dyndoc_id->add_text
EXPORTING
text = p_text
sap_emphasis = cl_dd_area=>heading.
ENDFORM. " ADD_TEXT
*&---------------------------------------------------------------------*
*& Form HTML
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM html.
DATA : dl_length TYPE i, " Length
dl_background_id TYPE sdydo_key VALUE space. " Background_id
* Creating html control
IF dg_html_cntrl IS INITIAL.
CREATE OBJECT dg_html_cntrl
EXPORTING
parent = dg_parent_html.
ENDIF.
* Reuse_alv_grid_commentary_set
CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
EXPORTING
document = dg_dyndoc_id
bottom = space
IMPORTING
length = dl_length.
* Get TOP->HTML_TABLE ready
CALL METHOD dg_dyndoc_id->merge_document.
* Set wallpaper
CALL METHOD dg_dyndoc_id->set_document_background
EXPORTING
picture_id = dl_background_id.
* Connect TOP document to HTML-Control
dg_dyndoc_id->html_control = dg_html_cntrl.
* Display TOP document
CALL METHOD dg_dyndoc_id->display_document
EXPORTING
reuse_control = 'X'
parent = dg_parent_html
EXCEPTIONS
html_display_error = 1.
IF sy-subrc NE 0.
MESSAGE i999 WITH 'Error in displaying top-of-page'(036).
ENDIF.
ENDFORM. " HTML
*&---------------------------------------------------------------------*
*& Form handle_before_user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_I_UCOMM text
*----------------------------------------------------------------------*
form handle_before_user_command using p_i_ucomm.
BREAK-POINT.
endform. " handle_before_user_command
2006 May 31 8:47 AM
Hi Pei,
After the call to method set_table_for_first_display register the event as follows :
CALL METHOD o_alvgrid->set_table_for_first_display
EXPORTING
i_bypassing_buffer = space
i_save = gc_a
is_layout = xs_layout
CHANGING
it_outtab = git_activity_data[]
it_fieldcatalog = xt_fcat[]
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
.
IF sy-subrc <> 0.
MESSAGE ID gc_msg_class
TYPE gc_error
NUMBER gc_msgno_072
DISPLAY LIKE 'E'.
flg_err = gc_x.
EXIT.
ENDIF.
*Set the event handlers.
SET HANDLER o_evt_rcvr->double_click FOR o_alvgrid.<b>Reward points if it helps.</b>
2006 May 31 8:50 AM
Hi,
I guess there is not an event to directly add or delete row n class CL_GUI_ALV_GRID.
U need to add button for add/delete in toolbar using event toolbar.
Then check for usercommand.
U can do that in event USER_COMMAND.
Check for the sy-ucomm.
Then process and add or delete the row.
Regards,
Tanveer.
2006 May 31 9:07 AM
HI Tanveer,
You mean I need to exclude the standard toolbar buttons and I need to add in my new buttons in order to use the USER_COMMAND event?
Rgds,
ET
2006 May 31 9:10 AM
Yes you are right, if you want to use the USER_COMMAND event, you need to have your own buttons on the toolbar.
Regards,
Ravi
Note : Please mark all the helpful answers
2006 May 31 9:15 AM
2006 May 31 9:22 AM
Hi all,
I tried the event before_user_command but it is not triggered when i click the standard toolbar. i followed the steps as mentioned by some experts here (definition, implementation, set handler). what could i missed - registering the event?
I am trying to mark an indicator for deleted rows and inserted rows in a copy of internal table.
Rgds,
ET
2006 May 31 9:29 AM
Hi,
Did you try the code in my previous post...
It worked for me.
See page 35 in www.abap4.it/download/ALV.pdf
Overriding Standard Functions
2006 May 31 9:35 AM
Hi,
I did follow your codes. You could check my codes below too...
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: handle_changed_click FOR EVENT
data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed e_onf4
e_onf4_before
e_onf4_after e_ucomm,
<b> handle_before_user_command
FOR EVENT before_user_command OF
cl_gui_alv_grid IMPORTING e_ucomm.</b>
ENDCLASS. "lcl_event_receiver
CLASS lcl_event_receiver IMPLEMENTATION.
<b> METHOD handle_before_user_command.
break ffxc096.
CASE e_ucomm.
WHEN OTHERS.
ENDCASE.
ENDMETHOD. </b>
ENDCLASS. "lcl_event_receiver
In PBO.
<b> SET HANDLER lcl_event_receiver=>handle_before_user_command FOR grid.</b>
Rgds,
ET
2006 Nov 21 10:21 AM
Hi,
It works with most of the standard buttons (detail, order, filter) but, how can I handle the "delete row" or "new row" buttons?.
I'm trying to ask before delete a row.
The before_user_command is not shot.
I'm adding my own buttons fot it, but I think this is not good.
Thanks in advance.
2006 Nov 21 10:51 AM
hi there,
The event <b>before_user_command</b> will not be raised for 4 buttons....
they are<u> create, append, insert, delete..</u>.dont yet know the reason
so the only thing that can be done is to disable them and create new buttons
regards, vishal