rendered paste body*-----------------------------------------------------------------------
* Program Name : ZPPR00I3
* Title : ALV Grid Control Events for report ZPPR00B0
* Module : PP
* Gap ID : PP_ADV7.00_004 (Western Hemisphere)
* Author : Aniruddha Ghosh
* SAP Release : ECC 6.0
* Description : Event Handlers for the ALV Grid
*-----------------------------------------------------------------------
* Change History
*-----------------------------------------------------------------------
* DATE(DMY) TP Request# Programmer Description
* -------- ----------- ------------- ---------------------------------
* 16032011 ED2K911516 GHOSHA Initial Development
*-----------------------------------------------------------------------
*----------------------------------------------------------------------*
* Class cl_event_handler used to handle events for hot spot click
*----------------------------------------------------------------------*
* Definition of cl_event_handler class
CLASS cl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
* Constructor
constructor,
* Public Method to capture the row_id of the selected row
on_hotspot_click
FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING es_row_no,
* Public Method to read the captured row_id
get_row_id
EXPORTING row_id TYPE syindex.
PRIVATE SECTION.
* Private variable containing the row_id
DATA: lv_row_id TYPE syindex.
ENDCLASS. "End of cl_event_handler DEFINITION
* Implementation of cl_event_handler methods
CLASS cl_event_handler IMPLEMENTATION.
* Constructor
METHOD constructor.
* Default row_id is assumed to be 1
lv_row_id = 1.
ENDMETHOD. "End of constructor
* Method to capture the row_id of the selected row
METHOD on_hotspot_click.
CLEAR: lv_row_id.
* Check whether a proper ALV row was clicked or not
IF es_row_no-row_id > 0.
* Capture the row_id of the selected row into private variable
lv_row_id = es_row_no-row_id.
ENDIF.
ENDMETHOD. "End of method on_hotspot_click
* Method to read the captured row_id
METHOD get_row_id.
* Send row_id via export parameter
row_id = lv_row_id.
ENDMETHOD. "End of method GET_ROW_ID
ENDCLASS. "cl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
* CLASS cl_alv_toolbar DEFINITION
*---------------------------------------------------------------------*
* Class cl_alv_toolbar used to handle events for toolbar
*---------------------------------------------------------------------*
CLASS cl_alv_toolbar DEFINITION.
PUBLIC SECTION.
* Constructor
METHODS: constructor
IMPORTING
io_alv_grid TYPE REF TO cl_gui_alv_grid,
* Public Method to display customized toolbar
on_toolbar
FOR EVENT toolbar
OF cl_gui_alv_grid
IMPORTING
e_object,
* Public Method to implement toolbar commands
handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
PRIVATE SECTION.
* Private type declaration
TYPES: BEGIN OF ty_toolbar.
INCLUDE TYPE stb_button.
TYPES: level TYPE flag,
END OF ty_toolbar.
* Private constants declaration
CONSTANTS:
lc_detail TYPE ui_func VALUE '&DETAIL',
lc_asc TYPE ui_func VALUE '&SORT_ASC',
lc_des TYPE ui_func VALUE '&SORT_DSC',
lc_find TYPE ui_func VALUE '&FIND',
lc_find_more TYPE ui_func VALUE '&FIND_MORE',
lc_sum TYPE ui_func VALUE '&MB_SUM',
lc_filter TYPE ui_func VALUE '&MB_FILTER',
lc_subtot TYPE ui_func VALUE '&MB_SUBTOT',
lc_print TYPE ui_func VALUE '&PRINT_BACK',
lc_view TYPE ui_func VALUE '&MB_VIEW',
lc_export TYPE ui_func VALUE '&MB_EXPORT',
lc_col TYPE ui_func VALUE '&COL0',
lc_graph TYPE ui_func VALUE '&GRAPH',
lc_info TYPE ui_func VALUE '&INFO',
lc_note TYPE ui_func VALUE 'NOTE',
lc_modi TYPE ui_func VALUE 'MODI',
lc_show TYPE ui_func VALUE 'SHOW',
lc_normal_button TYPE tb_btype VALUE 0,
lc_menu_default TYPE tb_btype VALUE 1,
lc_menu TYPE tb_btype VALUE 2,
lc_separator TYPE tb_btype VALUE 3.
* Private Method to populate toolbar
METHODS: populate_toolbar
IMPORTING
function TYPE ui_func
butn_type TYPE tb_btype
quickinfo TYPE iconquick
disabled TYPE flag
CHANGING
toolbar TYPE STANDARD TABLE.
ENDCLASS. "End of cl_alv_toolbar DEFINITION
* Implementation of cl_alv_toolbar methods
CLASS cl_alv_toolbar IMPLEMENTATION.
* Constructor
METHOD constructor.
* Create ALV toolbar manager instance
CREATE OBJECT o_alv_toolbarmanager
EXPORTING
io_alv_grid = io_alv_grid.
ENDMETHOD. "End of constructor
* Method to populate toolbar
METHOD populate_toolbar.
* Local workarea declaration
DATA : lw_toolbar TYPE ty_toolbar.
CLEAR: lw_toolbar.
* Assign icon as per the function code
CASE function.
WHEN lc_detail.
lw_toolbar-icon = icon_select_detail.
WHEN lc_asc.
lw_toolbar-icon = icon_sort_up.
WHEN lc_des.
lw_toolbar-icon = icon_sort_down.
WHEN lc_find.
lw_toolbar-icon = icon_search.
WHEN lc_find_more.
lw_toolbar-icon = icon_search_next.
WHEN lc_filter.
lw_toolbar-icon = icon_filter.
WHEN lc_sum.
lw_toolbar-icon = icon_sum.
WHEN lc_subtot.
lw_toolbar-icon = icon_intermediate_sum.
WHEN lc_print.
lw_toolbar-icon = icon_print.
WHEN lc_view.
lw_toolbar-icon = icon_layout_control.
WHEN lc_export.
lw_toolbar-icon = icon_export.
WHEN lc_col.
lw_toolbar-icon = icon_alv_variants.
WHEN lc_graph.
lw_toolbar-icon = icon_graphics.
WHEN lc_info.
lw_toolbar-icon = icon_information.
WHEN lc_note.
lw_toolbar-icon = icon_change_text.
WHEN lc_show.
lw_toolbar-icon = icon_display.
WHEN lc_modi.
lw_toolbar-icon = icon_change.
ENDCASE.
lw_toolbar-function = function.
lw_toolbar-butn_type = butn_type.
lw_toolbar-quickinfo = quickinfo.
lw_toolbar-disabled = disabled.
APPEND lw_toolbar TO toolbar.
ENDMETHOD. "populate_toolbar
* Method to display customized toolbar
METHOD on_toolbar.
* Call method of toolbar manager to display the toolbar
TRY.
CALL METHOD o_alv_toolbarmanager->reorganize
EXPORTING
io_alv_toolbar = e_object.
* Remove the standard toolbar
REFRESH: e_object->mt_toolbar.
* Now add customized toolbar buttons
* Detail
CALL METHOD populate_toolbar
EXPORTING
function = lc_detail
butn_type = lc_normal_button
quickinfo = 'Details'(019)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
*Separator
CALL METHOD populate_toolbar
EXPORTING
function = space
butn_type = lc_separator
quickinfo = space
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Sort Ascending
CALL METHOD populate_toolbar
EXPORTING
function = lc_asc
butn_type = lc_normal_button
quickinfo = 'Sort in Ascending Order'(020)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Sort Descending
CALL METHOD populate_toolbar
EXPORTING
function = lc_des
butn_type = lc_normal_button
quickinfo = 'Sort in Descending Order'(021)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Search button
CALL METHOD populate_toolbar
EXPORTING
function = lc_find
butn_type = lc_normal_button
quickinfo = 'Find'(022)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Search again button
CALL METHOD populate_toolbar
EXPORTING
function = lc_find_more
butn_type = lc_normal_button
quickinfo = 'Find Next'(023)
disabled = 'X'
CHANGING
toolbar = e_object->mt_toolbar.
* Filter button
CALL METHOD populate_toolbar
EXPORTING
function = lc_filter
butn_type = lc_normal_button
quickinfo = 'Set Filter...'(024)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Separator
CALL METHOD populate_toolbar
EXPORTING
function = space
butn_type = lc_separator
quickinfo = space
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Summation button
CALL METHOD populate_toolbar
EXPORTING
function = lc_sum
butn_type = lc_menu_default
quickinfo = 'Total'(026)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Subtotal summation button
CALL METHOD populate_toolbar
EXPORTING
function = lc_subtot
butn_type = lc_menu_default
quickinfo = 'Subtotals'(025)
disabled = 'X'
CHANGING
toolbar = e_object->mt_toolbar.
* Separator
CALL METHOD populate_toolbar
EXPORTING
function = space
butn_type = lc_separator
quickinfo = space
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Print button
CALL METHOD populate_toolbar
EXPORTING
function = lc_print
butn_type = lc_normal_button
quickinfo = 'Print'(027)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* View button
CALL METHOD populate_toolbar
EXPORTING
function = lc_view
butn_type = lc_menu
quickinfo = 'Views'(028)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Export button
CALL METHOD populate_toolbar
EXPORTING
function = lc_export
butn_type = lc_menu
quickinfo = 'Export'(029)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Change layout button
CALL METHOD populate_toolbar
EXPORTING
function = lc_col
butn_type = lc_normal_button
quickinfo = 'Change Layout...'(030)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Separator
CALL METHOD populate_toolbar
EXPORTING
function = space
butn_type = lc_separator
quickinfo = space
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Graphics button
CALL METHOD populate_toolbar
EXPORTING
function = lc_graph
butn_type = lc_normal_button
quickinfo = 'Display Graphic'(031)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Separator
CALL METHOD populate_toolbar
EXPORTING
function = space
butn_type = lc_separator
quickinfo = space
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Information button
CALL METHOD populate_toolbar
EXPORTING
function = lc_info
butn_type = lc_normal_button
quickinfo = 'End User Docu.'(032)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Separator
CALL METHOD populate_toolbar
EXPORTING
function = space
butn_type = lc_separator
quickinfo = space
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Material memo button
CALL METHOD populate_toolbar
EXPORTING
function = lc_note
butn_type = lc_normal_button
quickinfo = 'Material memo'(015)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Display element button
CALL METHOD populate_toolbar
EXPORTING
function = lc_show
butn_type = lc_normal_button
quickinfo = 'Display Element'(033)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
* Change element button
CALL METHOD populate_toolbar
EXPORTING
function = lc_modi
butn_type = lc_normal_button
quickinfo = 'Change Element'(034)
disabled = space
CHANGING
toolbar = e_object->mt_toolbar.
CATCH cx_sy_dyn_call_excp_not_found
cx_sy_dyn_call_illegal_class
cx_sy_dyn_call_illegal_method
cx_sy_dyn_call_illegal_type
cx_sy_dyn_call_param_missing
cx_sy_dyn_call_param_not_found
cx_sy_ref_is_initial.
LEAVE PROGRAM.
CLEANUP.
LEAVE PROGRAM.
ENDTRY.
ENDMETHOD. "End of on_toolbar method
* Method to handle user command on toolbar
METHOD handle_user_command.
* Assign function code of toolbar to sy-ucomm
sy-ucomm = e_ucomm.
* Send control to PAI Module of screen 9000
SUPPRESS DIALOG.
ENDMETHOD. "End of handle_user_command method
ENDCLASS. "cl_alv_toolbar IMPLEMENTATION