03-17-2008 1:33 AM
Hi all,
i hava a problem in ALV button.ALV take button by self.
f.e: the button Append Row
cl_gui_alv_grid=>MC_FC_LOC_APPEND_ROW.
so how can i transfer this button event in program.
can anyone tell me.
Thanks in advance.
ali.
03-17-2008 10:26 PM
Hello Ali
It seems that standard ALV toolbar buttons are NOT triggering event list USER_COMMAND (or BEFORE_USER_COMMAND).
However, if you replace the standard function code for this toolbar button with a custom function code then the events are triggered.
Have a look at sample report ZUS_SDN_ALV_EDITABLE_1C. If you choose the first radiobutton (P_STDALV) the event handling for TOOLBAR is inactive. No events are triggered when you choose the "Append Row" button.
If you choose the second radiobutton (P_CUSTOM) the event handling for TOOLBAR is active. The standard function code is replaced and the event are triggered.
Obviously, you have to implement the standard functionality (here: append single row) yourself.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_ALV_EDITABLE_1C
*&
*&---------------------------------------------------------------------*
*&
*&
* Flow logic of screen '100' (no elements, ok-code => gd_okcode ):
**PROCESS BEFORE OUTPUT.
** MODULE STATUS_0100.
***
**PROCESS AFTER INPUT.
** MODULE USER_COMMAND_0100.
*&---------------------------------------------------------------------*
REPORT zus_sdn_alv_editable_1c.
TYPE-POOLS: abap.
CONSTANTS:
gc_tabname TYPE tabname VALUE 'KNB1'.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE knb1.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA:
gd_okcode TYPE ui_func,
*
gt_fcat TYPE lvc_t_fcat,
gs_layout TYPE lvc_s_layo,
gs_variant TYPE disvariant,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid TYPE REF TO cl_gui_alv_grid.
DATA:
gs_outtab TYPE ty_s_outtab,
gt_outtab TYPE ty_t_outtab.
PARAMETERS:
p_stdalv RADIOBUTTON GROUP radi DEFAULT 'X',
p_custom RADIOBUTTON GROUP radi.
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING
e_object
e_interactive
sender,
handle_before_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING
e_ucomm
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_toolbar.
DATA: ls_button TYPE stb_button.
LOOP AT e_object->mt_toolbar INTO ls_button
WHERE ( function = cl_gui_alv_grid=>mc_fc_loc_append_row ).
ls_button-function = 'APPEND_ROW'.
MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
ENDLOOP.
ENDMETHOD. "handle_toolbar
METHOD handle_before_user_command.
CASE e_ucomm.
WHEN cl_gui_alv_grid=>mc_fc_loc_append_row.
MESSAGE 'Standard ALV function called' TYPE 'I'.
WHEN 'APPEND_ROW'.
MESSAGE 'Customized ALV function called' TYPE 'I'.
WHEN OTHERS.
RETURN.
ENDCASE.
ENDMETHOD. "handle_before_user_command
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM (gc_tabname) INTO TABLE gt_outtab
UP TO 20 ROWS.
PERFORM init_controls.
" Set event handler
SET HANDLER:
lcl_eventhandler=>handle_toolbar FOR go_grid ACTIVATION p_custom.
SET HANDLER:
lcl_eventhandler=>handle_before_user_command FOR go_grid.
* Build fieldcatalog and set hotspot for field KUNNR
PERFORM build_fieldcatalog.
PERFORM set_layout_and_variant.
* Display data
CALL METHOD go_grid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
is_variant = gs_variant
i_save = 'A'
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = gt_fcat
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
" Modify toolbar function for "Append row" button
go_grid->set_toolbar_interactive( ).
* NOTE:
* Documenation of I_SAVE ("An Easy Reference for ALV Grid Control")
*I_SAVE
*Determines the options available to the user for saving a layout:
*? 'X': global saving only
*? 'U': user-specific saving only
*? 'A': corresponds to 'X' and 'U'
*? SPACE: no saving
* Link the docking container to the target dynpro
CALL METHOD go_docking->link
EXPORTING
repid = syst-repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* ok-code field = GD_OKCODE
CALL SCREEN '0100'.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
go_grid->check_changed_data( ).
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'SAVE'.
WHEN 'SAVE_DATA'.
** MODIFY (gc_tabname) FROM TABLE gt_outtab.
** IF ( syst-subrc = 0 ).
** COMMIT WORK AND WAIT.
MESSAGE 'Data successfully saved' TYPE 'S'.
** ELSE.
** ROLLBACK WORK.
** MESSAGE 'Saving data failed' TYPE 'E'.
** ENDIF.
WHEN 'DUMMY'.
" do nothing
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = gc_tabname
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ls_fcat-edit = abap_true.
MODIFY gt_fcat FROM ls_fcat
TRANSPORTING edit
WHERE ( key NE abap_true ).
ENDFORM. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM set_layout_and_variant .
CLEAR: gs_layout,
gs_variant.
gs_layout-cwidth_opt = abap_true.
gs_layout-zebra = abap_true.
gs_variant-report = syst-repid.
gs_variant-handle = 'GRID'.
ENDFORM. " SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
*& Form INIT_CONTROLS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_controls .
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD go_docking->set_extension
EXPORTING
extension = 99999 " full-size ALV
* EXCEPTIONS
* cntl_error = 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.
* Create ALV grid
CREATE OBJECT go_grid
EXPORTING
i_parent = go_docking
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " INIT_CONTROLS
Regards
Uwe
03-17-2008 3:34 AM
Hi,
Check this SAP Demo program BCALV_GRID_07 which explains clearly abt adding a button in toolbar....
Cheers,
jose.
03-17-2008 3:48 AM
ths.
i know how to add button and come true .
i just want transfer 'Append Row' event in program ,not mouse hit it in screen .
Edited by: Alicice Avril on Mar 17, 2008 4:49 AM
03-17-2008 4:24 AM
Hi,
This logic for adding a row can be implemented only upon a event is trigger. If you want to programatically do it what is the logical point at which want to trigger this. Can you be a bit more clear with your requirement.
Regards,
Sravan Varagani
03-17-2008 5:46 AM
(>_<)
i define a event 'handle_hotspot_click' ( single hit mouse).
i want make 'APPEND_ROW button' event in my
'handle_hotspot_click' event.
In simple:when 'handle_hotspot_click' event touch out .
i want transfer 'APPEND_ROW button' event.
so how can i transfer?
ths for Regards!
ali
03-17-2008 5:52 AM
Hi,
Use standard event button_click and register it in ur local class
Every button have a Fcode right
Use a case statement in the FM of the button_click event
It will check what button u have pressed and according to that it will performs it.
03-17-2008 6:22 AM
it looks not enough clear i write .
i know how to define and come true 'button_chick' event.
for e: when nouse chick ,i can save sth ,i can transfer sth.
bu i don't know how to add a line in alv .
alv have this event by self (the button Append Row) , i want transfer it.
Cheers all,
ali.
03-17-2008 11:13 AM
Hi,
Try implementing the event before_user_command. Set the user command to say ZAPP.
In the user_command event implementation, write your logic for ZAPP function code.
Hope this helps.
Thanks,
Balaji
03-17-2008 10:26 PM
Hello Ali
It seems that standard ALV toolbar buttons are NOT triggering event list USER_COMMAND (or BEFORE_USER_COMMAND).
However, if you replace the standard function code for this toolbar button with a custom function code then the events are triggered.
Have a look at sample report ZUS_SDN_ALV_EDITABLE_1C. If you choose the first radiobutton (P_STDALV) the event handling for TOOLBAR is inactive. No events are triggered when you choose the "Append Row" button.
If you choose the second radiobutton (P_CUSTOM) the event handling for TOOLBAR is active. The standard function code is replaced and the event are triggered.
Obviously, you have to implement the standard functionality (here: append single row) yourself.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_ALV_EDITABLE_1C
*&
*&---------------------------------------------------------------------*
*&
*&
* Flow logic of screen '100' (no elements, ok-code => gd_okcode ):
**PROCESS BEFORE OUTPUT.
** MODULE STATUS_0100.
***
**PROCESS AFTER INPUT.
** MODULE USER_COMMAND_0100.
*&---------------------------------------------------------------------*
REPORT zus_sdn_alv_editable_1c.
TYPE-POOLS: abap.
CONSTANTS:
gc_tabname TYPE tabname VALUE 'KNB1'.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE knb1.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA:
gd_okcode TYPE ui_func,
*
gt_fcat TYPE lvc_t_fcat,
gs_layout TYPE lvc_s_layo,
gs_variant TYPE disvariant,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid TYPE REF TO cl_gui_alv_grid.
DATA:
gs_outtab TYPE ty_s_outtab,
gt_outtab TYPE ty_t_outtab.
PARAMETERS:
p_stdalv RADIOBUTTON GROUP radi DEFAULT 'X',
p_custom RADIOBUTTON GROUP radi.
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING
e_object
e_interactive
sender,
handle_before_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING
e_ucomm
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_toolbar.
DATA: ls_button TYPE stb_button.
LOOP AT e_object->mt_toolbar INTO ls_button
WHERE ( function = cl_gui_alv_grid=>mc_fc_loc_append_row ).
ls_button-function = 'APPEND_ROW'.
MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
ENDLOOP.
ENDMETHOD. "handle_toolbar
METHOD handle_before_user_command.
CASE e_ucomm.
WHEN cl_gui_alv_grid=>mc_fc_loc_append_row.
MESSAGE 'Standard ALV function called' TYPE 'I'.
WHEN 'APPEND_ROW'.
MESSAGE 'Customized ALV function called' TYPE 'I'.
WHEN OTHERS.
RETURN.
ENDCASE.
ENDMETHOD. "handle_before_user_command
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM (gc_tabname) INTO TABLE gt_outtab
UP TO 20 ROWS.
PERFORM init_controls.
" Set event handler
SET HANDLER:
lcl_eventhandler=>handle_toolbar FOR go_grid ACTIVATION p_custom.
SET HANDLER:
lcl_eventhandler=>handle_before_user_command FOR go_grid.
* Build fieldcatalog and set hotspot for field KUNNR
PERFORM build_fieldcatalog.
PERFORM set_layout_and_variant.
* Display data
CALL METHOD go_grid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
is_variant = gs_variant
i_save = 'A'
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = gt_fcat
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
" Modify toolbar function for "Append row" button
go_grid->set_toolbar_interactive( ).
* NOTE:
* Documenation of I_SAVE ("An Easy Reference for ALV Grid Control")
*I_SAVE
*Determines the options available to the user for saving a layout:
*? 'X': global saving only
*? 'U': user-specific saving only
*? 'A': corresponds to 'X' and 'U'
*? SPACE: no saving
* Link the docking container to the target dynpro
CALL METHOD go_docking->link
EXPORTING
repid = syst-repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* ok-code field = GD_OKCODE
CALL SCREEN '0100'.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
go_grid->check_changed_data( ).
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'SAVE'.
WHEN 'SAVE_DATA'.
** MODIFY (gc_tabname) FROM TABLE gt_outtab.
** IF ( syst-subrc = 0 ).
** COMMIT WORK AND WAIT.
MESSAGE 'Data successfully saved' TYPE 'S'.
** ELSE.
** ROLLBACK WORK.
** MESSAGE 'Saving data failed' TYPE 'E'.
** ENDIF.
WHEN 'DUMMY'.
" do nothing
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = gc_tabname
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ls_fcat-edit = abap_true.
MODIFY gt_fcat FROM ls_fcat
TRANSPORTING edit
WHERE ( key NE abap_true ).
ENDFORM. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM set_layout_and_variant .
CLEAR: gs_layout,
gs_variant.
gs_layout-cwidth_opt = abap_true.
gs_layout-zebra = abap_true.
gs_variant-report = syst-repid.
gs_variant-handle = 'GRID'.
ENDFORM. " SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
*& Form INIT_CONTROLS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_controls .
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD go_docking->set_extension
EXPORTING
extension = 99999 " full-size ALV
* EXCEPTIONS
* cntl_error = 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.
* Create ALV grid
CREATE OBJECT go_grid
EXPORTING
i_parent = go_docking
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " INIT_CONTROLS
Regards
Uwe
03-18-2008 2:11 AM