IV. Depending upon control object, you might need to register an event in PBO & capture it in PAI
Register an event - first define & implement local class for event handling in top module (below is a static method)
Code:
*---------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: catch_dblclick FOR EVENT dblclick
OF cl_gui_textedit IMPORTING sender.
ENDCLASS.
Code:
* w_event_handler never referenced in the tutorial!
* I thought I would be able to use it if I changed the handler method
* from a static method (CLASS-MEHTODS) to an instance method by
* removing the CLASS- and by instantiating the object w_event_handler
* but this did not work!
DATA w_event_handler TYPE REF TO lcl_event_handler.
*---------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
* When dblclick is captured g_event_type is populated with text *
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD catch_dblclick.
g_event_type = text-002. " input/output field on screen
ENDMETHOD.
ENDCLASS.
Link the local static method to the event in the control object once from PBO within If initial statement
Code:
SET HANDLER lcl_event_handler=>catch_dblclick FOR w_editor.
Register event as an application event
- declare internal table for events of interest & structure for one line in internal table
Code:
DATA t_events TYPE cntl_simple_events.
DATA st_events TYPE cntl_simple_event.
- assign static attribute for event to eventid & define as application event from PBO within If initial statement
st_events-eventid = cl_gui_textedit=>event_double_click.
st_events-appl_event = 'X'.
APPEND st_events TO t_events.
- register event once (within the if initial statement) in PBO
CALL METHOD w_editor->set_registered_events
EXPORTING
events = t_events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Call Method & error &
MESSAGE i494(zz) WITH 'cl_gui_textedit=>set_registered_events'
sy-subrc.
ENDIF.
Capture the event in the PAI by calling method DISPATCH in class cl_gui_cfw (Control Framework Basic Class)
Code:
CASE ok_code.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
WHEN 'IMP'.
PERFORM load_tab.
WHEN OTHERS.
CALL METHOD cl_gui_cfw=>dispatch
IMPORTING
return_code = w_return_code.
IF w_return_code <> 0.
MESSAGE i999(zz) WITH 'Bad return code from DISPATCH'
w_return_code ok_code.
ENDIF.
ENDCASE.
Switch from Application Event to System Event
Code:
*---------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
* When dblclick is captured g_event_type is populated with text *
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD catch_dblclick.
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING new_code = 'SHOW'.
ENDMETHOD.
ENDCLASS.
In pbo
Code:
st_events-appl_event = space.
In pai
Code:
CASE ok_code.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
WHEN 'IMP'.
PERFORM load_tab.
WHEN 'SHOW'.
event_type = text-003. " Doubleclick
ENDCASE.
V. Depending upon control object, you might need to populate it in PBO
First define & implement local class for event handling in top module (below is an instance method)
Code:
*- Predefine a local class for event handling to allow the
* declaration of a reference variable before the class is defined.
CLASS lcl_w_event_receiver DEFINITION DEFERRED.
DATA w_event_receiver TYPE REF TO lcl_w_event_receiver.
*---------------------------------------------------------------------*
* CLASS lcl_w_event_receiver DEFINITION
*---------------------------------------------------------------------*
* local event receiver definition *
*---------------------------------------------------------------------*
class lcl_w_event_receiver definition.
public section.
*- define toolbar handler
methods:
handle_toolbar
for event toolbar of cl_gui_alv_grid
importing e_object e_interactive,
*- define user event handler
handle_user_command
for event user_command of cl_gui_alv_grid
importing e_ucomm.
private section.
endclass.
*---------------------------------------------------------------------*
* CLASS lcl_w_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
* local event receiver implementation *
*---------------------------------------------------------------------*
class lcl_w_event_receiver implementation.
*- add additional functions to toolbar
METHOD handle_toolbar.
DATA: ls_toolbar TYPE stb_button. " Toolbar Button (mt_toolbar)
*- add a separator to normal toolbar
CLEAR ls_toolbar.
MOVE 3 TO ls_toolbar-butn_type. " 3 is Separator
APPEND ls_toolbar TO e_object->mt_toolbar.
* append an icon for displaying work order
CLEAR ls_toolbar.
MOVE c_displaywo TO ls_toolbar-function. " ZPMORD3 is transaction
MOVE icon_select_detail TO ls_toolbar-icon.
MOVE 'Display WO'(003) TO ls_toolbar-quickinfo.
MOVE 'Display WO'(003) TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled. " not disabled
APPEND ls_toolbar TO e_object->mt_toolbar.
* append an icon for displaying billed services (display JVs)
MOVE c_displayjv TO ls_toolbar-function. " FB03 is transaction
MOVE icon_display TO ls_toolbar-icon.
MOVE 'Display JV'(004) TO ls_toolbar-quickinfo.
MOVE 'Display JV'(004) TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
* append an icon for displaying computer equipment
MOVE c_displaypc TO ls_toolbar-function. " IE03 is transaction
MOVE icon_biw_monitor TO ls_toolbar-icon.
MOVE 'Display Computer'(005) TO ls_toolbar-quickinfo.
MOVE 'Display Computer'(005) TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
* append an icon for printing work order
MOVE c_print TO ls_toolbar-function. " PRINT is command
MOVE icon_print TO ls_toolbar-icon.
MOVE 'Print WO'(007) TO ls_toolbar-quickinfo.
MOVE 'Print WO'(007) TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
METHOD handle_user_command.
*- user event handling, react to users selection on toolbar
DATA: lt_rows TYPE lvc_t_row. " ALV control: Table rows
CASE e_ucomm.
WHEN c_displaywo. " ZPMORD3 display wo
CALL METHOD w_grid->get_selected_rows
IMPORTING et_index_rows = lt_rows.
* no exceptions
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
PERFORM error_in_flush.
ELSE.
PERFORM display_workorder TABLES lt_rows.
ENDIF.
WHEN c_displaypc. " IE03 display computer
CALL METHOD w_grid->get_selected_rows
IMPORTING et_index_rows = lt_rows.
* no exceptions
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
PERFORM error_in_flush.
ELSE.
PERFORM display_equipment TABLES lt_rows.
ENDIF.
WHEN c_displayjv. " FB03 display billing doc
CALL METHOD w_grid->get_selected_rows
IMPORTING et_index_rows = lt_rows.
* no exceptions
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
PERFORM error_in_flush.
ELSE.
PERFORM display_jv TABLES lt_rows.
ENDIF.
WHEN c_print. " print work order
CALL METHOD w_grid->get_selected_rows
IMPORTING et_index_rows = lt_rows.
* no exceptions
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
PERFORM error_in_flush.
ELSE.
PERFORM print_workorder TABLES lt_rows.
ENDIF.
ENDCASE.
ENDMETHOD.
ENDCLASS.
Define structure for ALV Layout & Display Variant
Code:
DATA st_layout type lvc_s_layo.
DATA st_variant type disvariant.
Within PBO set the grid attributes, the display variant report name & call the method to display report
Code:
* if I don't implement multiple row selection functionality then
* selection mode 'B' would make more sense! See page 320 in Controls
* Technology book for definition of different values
* Page 274 explains the exception field name & outputing exceptions
*- set general grid attributes
st_layout-zebra = 'X'. " Alternating line color
st_layout-cwidth_opt = 'X'. " Optimize column width
st_layout-sel_mode = c_multrows. " Selection Mode D cell selection
st_layout-excp_fname = c_traffic. " exceptions field name
* set up the ability for them to create variants
st_variant-report = c_zpmworpt. " layout variants for this report
*- call the method to display the GRID
CALL METHOD w_grid->set_table_for_first_display
EXPORTING
i_structure_name = c_structure " dict struc ZPMWOALL
is_variant = st_variant " display variant
i_save = c_all " user can save variants
is_layout = st_layout " grid attributes
CHANGING
it_outtab = t_zpmwoall[] " table with data
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE a171. " Error with grid display generation
ENDIF.
CHECK w_event_receiver IS INITIAL. " instantiate once & only once!
*- create object to receive events and link them to handler methods.
CREATE OBJECT w_event_receiver.
* When the ALV Control raises the event for the specified instance
* the corresponding method is automatically called.
SET HANDLER w_event_receiver->handle_user_command FOR w_grid.
SET HANDLER w_event_receiver->handle_toolbar FOR w_grid.
*- call method 'set_toolbar_interactive' to raise event TOOLBAR.
CALL METHOD w_grid->set_toolbar_interactive.
* no exceptions
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.