09-22-2010 4:25 PM
I am trying to find how to trigger an event on double click similar to using Event Double_Click in Class CL_GUI_ALV_GRID I am fresh out of the ABAP OO class and everything is a blur. This is what I did. I created a program that with
Data: r_grid TYPE REF TO cl_salv_table.
CALL METHOD CL_SALV_TABLE=>FACTORY
Importing R_SALV_TABLE = r_grid
Changing ITAB.
I then tried to create an Include program to define a Local Class
&----
*& Include ZSD_DISPLAY_CUSTOMER
&----
class lcl_event_handler definition.
PUBLIC SECTION.
METHODS: on_double_click for event double_click of cl_gui_alv_grid
METHODS: on_double_click for event double_click of cl_salv_table
IMPORTING es_row_no e_column.
ENDCLASS.
class lcl_event_handler IMPLEMENTATION.
METHOD on_double_click.
Data: IT_CUSTHIER type ZSD11_CUST_HIER_TABLE_TYPE.
Data: WK_CUSTHIER LIKE LINE OF IT_CUSTHIER.
types: BEGIN OF custhier_x,
custhier like WK_CUSTHIER,
number TYPE int4,
quantity type MENGE_D,
dollars_n_cents type DMBTR,
END OF custhier_x.
data: it_custhier_x type STANDARD TABLE OF custhier_x.
data: wk_custhier_x like LINE OF it_custhier_x.
read table it_custhier_x into wk_custhier_x
index es_row_no-row_id.
data: wk_vkorg type vkorg.
data: wk_vtweg type vtweg.
data: wk_spart type spart.
wk_vkorg = '3290'.
wk_vtweg = '00'.
wk_spart = '00'.
SET PARAMETER ID: 'KUN' field wk_custhier_x-custhier-kunnr.
SET PARAMETER ID: 'VKO' field wk_vkorg.
SET PARAMETER ID: 'VTW' field wk_vtweg.
SET PARAMETER ID: 'SPA' field wk_spart.
call TRANSACTION 'VD03' AND SKIP FIRST SCREEN.
ENDMETHOD.
ENDCLASS.
When I try to do a syntax check I get this error
The Handler Method ON_DOUBLE_CLICK is only defined for trigger objects of CL_GUI_ALV_GRID, but the system tried to register a trigger object of CL_SALV_TABLE
Any suggestions on what I need to do in order to trigger a event for double click ?
Thanks
Edited by: Bob Ackerman on Sep 22, 2010 11:25 AM
09-22-2010 5:06 PM
Since you are using the CL_SALV_TABLE, you need to register the event which is known to CL_SALV_TABLE.
* event handler
METHODS:
on_DOUBLE_CLICK
FOR EVENT DOUBLE_CLICK OF cl_salv_events_table
IMPORTING
row
column .
*...
*... register to the events of cl_salv_table
data: gr_events type ref to lcl_handle_events.
data: lr_events type ref to cl_salv_events_table.
lr_events = gr_table->get_event( ).
create object gr_events.
set handler gr_events->on_double_click for lr_events.
Check my blog post http://help-abap.blogspot.com/2008/09/salv-model-8-add-handle-hotspot.html. This gives you an idea how to handle the event.
You can also check the std test program SALV_DEMO_TABLE_COLUMNS.
Regards,
Naimesh Patel
09-22-2010 5:41 PM
I changed/added the code per your example, but am getting a syntax error "Field GR_TABLE" is unknown on this statement in my main program lr_events = gr_table->get_event( ).
09-22-2010 5:48 PM
Hi Bob,
Have you declared GR_TABLE ?
DATA : GR_TABLE TYPE REF TO cl_salv_table.
Are you using r_grid or gr_table. In the initial code you have used r_grid.
so it should be
lr_events = r_grid->get_event( )
Regards
Edited by: Rajvansh Ravi on Sep 22, 2010 6:51 PM
09-22-2010 10:10 PM
I am not getting anything to happen on double click. In debug mode, I see that it calls program SAPLSLVC_FULLSCREEN and gets to FORM SELFIELD_GET which gets the row, column, and value of the field that was double clicked. But, nothing seems to be returned to my program. I am fresh out of the ABAP OO class and everything is a blur. My test program is listed below, if you would be so kind as to take a look and maybe see what I am missing.
Include program ZSD_DISPLAY_CUSTOMER
class lcl_event_handler definition.
PUBLIC SECTION.
** METHODS: on_double_click for event double_click of cl_gui_alv_grid
** IMPORTING es_row_no e_column.
METHODS:
on_DOUBLE_CLICK
FOR EVENT DOUBLE_CLICK OF cl_salv_events_table
IMPORTING
row
column .
ENDCLASS.
class lcl_event_handler IMPLEMENTATION.
METHOD on_double_click.
** data: it_sflight type TABLE OF sflight,
** wa_spfli type spfli.
Data: IT_CUSTHIER type ZSD11_CUST_HIER_TABLE_TYPE.
Data: WK_CUSTHIER LIKE LINE OF IT_CUSTHIER.
types: BEGIN OF custhier_x,
custhier like WK_CUSTHIER,
number TYPE int4,
quantity type MENGE_D,
dollars_n_cents type DMBTR,
END OF custhier_x.
data: it_custhier_x type STANDARD TABLE OF custhier_x.
data: wk_custhier_x like LINE OF it_custhier_x.
* ...
data: ls_row_id type lvc_s_row.
data: ls_col_id type lvc_s_col.
data: l_value type lvc_s_data-value.
data: ls_selfield type lvc_s_self.
data: ls_fieldcat type slis_fieldcat_alv.
data: ls_fieldcat_lvc type lvc_s_fcat.
data: wk_vkorg type vkorg.
data: wk_vtweg type vtweg.
data: wk_spart type spart.
wk_vkorg = '3290'.
wk_vtweg = '00'.
wk_spart = '00'.
SET PARAMETER ID: 'KUN' field wk_custhier_x-custhier-kunnr.
SET PARAMETER ID: 'VKO' field wk_vkorg.
SET PARAMETER ID: 'VTW' field wk_vtweg.
SET PARAMETER ID: 'SPA' field wk_spart.
call TRANSACTION 'VD03' AND SKIP FIRST SCREEN.
ENDMETHOD.
ENDCLASS.
In the main program :
CREATE OBJECT CUST_HIER
EXPORTING
IM_HIERARCHY_TYPE = 'A'
* IM_CUSTOMER_NUMBER =
IM_SALES_ORG = '3290'
IM_DIST_CHANNEL = '00'
IM_DIVISION = '00'
IM_VALIDITY_DATE = '99991215'.
**
**
CALL METHOD CUST_HIER->GET_CUSTHIER_NODES
IMPORTING EX_CUSTHIER = IT_CUSTHIER.
it_custhier_x = IT_CUSTHIER.
TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
* EXPORTING
* LIST_DISPLAY = IF_SALV_C_BOOL_SAP=>FALSE
* R_CONTAINER =
* CONTAINER_NAME =
IMPORTING
R_SALV_TABLE = r_grid
CHANGING
T_TABLE = IT_CUSTHIER_X.
CATCH CX_SALV_MSG .
ENDTRY.
*... §3 Functions
*... §3.1 activate ALV generic Functions
data: lr_functions type ref to cl_salv_functions_list.
lr_functions = r_grid->get_functions( ).
lr_functions->set_default( abap_true ).
*... set the columns technical
data: lr_columns type ref to cl_salv_columns.
lr_columns = r_grid->get_columns( ).
lr_columns->set_optimize( abap_true ).
perform set_columns_technical using lr_columns.
r_grid->display( ).
lr_events = r_grid->get_event( ).
create object gr_events.
set handler gr_events->on_double_click for lr_events.
Edited by: Bob Ackerman on Sep 22, 2010 5:30 PM
Edited by: Bob Ackerman on Sep 22, 2010 5:35 PM
Edited by: Bob Ackerman on Sep 22, 2010 5:37 PM
09-23-2010 6:48 AM
Hi Bob,
I was not able to execute your code due to the Z objects involved.
Set your Handler before you use the display method
lr_events = r_grid->get_event( ).
create object gr_events.
set handler gr_events->on_double_click for lr_events.
r_grid->display( ).
I tested with my sample code below, so that should be the problem
TYPES:
BEGIN OF TY_T000,
X_SEL TYPE CHAR1, " NEW
MANDT TYPE CHAR5,
MTEXT TYPE MTEXT_D,
ORT01 TYPE ORT01,
MWAER TYPE MWAER,
ADRNR TYPE CHAR10,
CCCATEGORY TYPE CCCATEGORY,
CCCORACTIV TYPE CCCORACTIV,
CCNOCLIIND TYPE CCNOCLIIND,
CCCOPYLOCK TYPE CCCOPYLOCK,
CCNOCASCAD TYPE CCNOCASCAD,
CCSOFTLOCK TYPE CCSOFTLOCK,
CCORIGCONT TYPE CCORIGCONT,
CCIMAILDIS TYPE CCIMAILDIS,
CCTEMPLOCK TYPE CCTEMPLOCK,
CHANGEUSER TYPE AS4USER,
CHANGEDATE TYPE AS4DATE,
LOGSYS TYPE LOGSYS,
END OF TY_T000.
DATA : ITAB TYPE TABLE OF TY_T000,
WA TYPE TY_T000.
FIELD-SYMBOLS : <FS> TYPE TY_T000.
DATA :
GO_EVENTS TYPE REF TO CL_SALV_EVENTS_TABLE.
DATA GR_SALV_TABLE TYPE REF TO CL_SALV_TABLE.
*----------------------------------------------------------------------*
* CLASS lcl_eventhandler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENTHANDLER DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
HANDLE_LINK_CLICK FOR EVENT
LINK_CLICK OF CL_SALV_EVENTS_TABLE
IMPORTING
ROW
COLUMN.
ENDCLASS.
*----------------------------------------------------------------------*
* CLASS lcl_eventhandler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENTHANDLER IMPLEMENTATION.
METHOD HANDLE_LINK_CLICK.
* LOOP AT ITAB ASSIGNING <FS>.
* <FS>-X_SEL = 'X'.
* ENDLOOP.
READ TABLE ITAB ASSIGNING <FS> INDEX ROW.
IF SY-SUBRC IS INITIAL.
IF <FS>-X_SEL <> 'X'.
<FS>-X_SEL = 'X'.
ELSE.
<FS>-X_SEL = ' '.
ENDIF.
ENDIF.
GR_SALV_TABLE->REFRESH( ).
ENDMETHOD. "handle_top_of_page
ENDCLASS.
DATA: GR_EVENTS TYPE REF TO LCL_EVENTHANDLER.
START-OF-SELECTION.
SELECT * FROM T000 INTO CORRESPONDING FIELDS OF TABLE ITAB.
CL_SALV_TABLE=>FACTORY( IMPORTING R_SALV_TABLE = GR_SALV_TABLE
CHANGING T_TABLE = ITAB ).
DATA LR_COLUMNS TYPE REF TO CL_SALV_COLUMNS.
LR_COLUMNS = GR_SALV_TABLE->GET_COLUMNS( ).
* ----- NEW ----- *
DATA LR_COLUMN TYPE REF TO CL_SALV_COLUMN_TABLE.
LR_COLUMN ?= LR_COLUMNS->GET_COLUMN( 'X_SEL' ).
LR_COLUMN->SET_TOOLTIP( 'Some tooltip' ).
LR_COLUMN->SET_CELL_TYPE( CL_SALV_COLUMN_TABLE=>IF_SALV_C_CELL_TYPE~CHECKBOX_HOTSPOT ).
LR_COLUMN->SET_OUTPUT_LENGTH( 3 ).
LR_COLUMN->SET_VISIBLE( 'X' ).
* ----- NEW ----- *
DATA : LVC_OUTLEN TYPE LVC_OUTLEN.
LR_COLUMNS->SET_OPTIMIZE( 'X' ). "--> Optimise all columns
GO_EVENTS = GR_SALV_TABLE->GET_EVENT( ).
CREATE OBJECT GR_EVENTS.
SET HANDLER GR_EVENTS->HANDLE_LINK_CLICK FOR GO_EVENTS.
GR_SALV_TABLE->DISPLAY( ).
*
* GO_EVENTS = GR_SALV_TABLE->GET_EVENT( ).
*
* CREATE OBJECT GR_EVENTS.
* SET HANDLER GR_EVENTS->HANDLE_LINK_CLICK FOR GO_EVENTS.
Regards
09-23-2010 3:06 PM
Hi Rajvansh,
Thanks. That got the on_double_click event to be triggered. The problem I am now having is that my internal table is empty when I come into the on_double_click method. I see in your example it looks like you are doing something very similar but you defined your local class in the main program. I am pretty sure in class we did an example with the class defined in a Include program.
Inside my lcl_event_handler implementation for my method on_double_click the Row ( number ) and Column ( field name ) are coming in correctly.
*&---------------------------------------------------------------------*
*& Include ZSD_DISPLAY_CUSTOMER
*&---------------------------------------------------------------------*
class lcl_event_handler definition.
PUBLIC SECTION.
METHODS:
on_DOUBLE_CLICK
FOR EVENT DOUBLE_CLICK OF cl_salv_events_table
IMPORTING
row
column .
ENDCLASS.
class lcl_event_handler IMPLEMENTATION.
METHOD on_double_click.
** data: it_sflight type TABLE OF sflight,
** wa_spfli type spfli.
Data: IT_CUSTHIER type ZSD11_CUST_HIER_TABLE_TYPE.
Data: WK_CUSTHIER LIKE LINE OF IT_CUSTHIER.
types: BEGIN OF custhier_x,
custhier like WK_CUSTHIER,
number TYPE int4,
quantity type MENGE_D,
dollars_n_cents type DMBTR,
END OF custhier_x.
data: it_custhier_x type STANDARD TABLE OF custhier_x.
data: wk_custhier_x like LINE OF it_custhier_x.
READ TABLE IT_CUSTHIER_X into wk_custhier_x
index row.
In my main program I create the ALV
TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
* EXPORTING
* LIST_DISPLAY = IF_SALV_C_BOOL_SAP=>FALSE
* R_CONTAINER =
* CONTAINER_NAME =
IMPORTING
R_SALV_TABLE = r_grid
CHANGING
T_TABLE = IT_CUSTHIER_X.
CATCH CX_SALV_MSG .
ENDTRY.
lr_events = r_grid->get_event( ).
create object gr_events.
set handler gr_events->on_double_click for lr_events.
r_grid->display( ).
09-23-2010 3:38 PM
Then, the internal table is also empty when you call the factory method, right? Did you populate data into IT_CUSTHIER_X, since it's apparently the table to be displayed?
09-23-2010 4:04 PM
I found the problem. I was defining the internal table again in the class implementation for method on_double_click. So the class was trying to read the local class version of the internal table. When I took out the definition of the internal table in the class, the internal table showed values.
The internal table is filled when the Factory method is called. The ALV screen is populated when it is displayed. Double clicking on a line in the internal table returns the Row and Column of the line that was double clicked on when the on_double_click event is called
Edited by: Bob Ackerman on Sep 23, 2010 11:32 AM
09-22-2010 5:13 PM
METHODS: on_double_click for event double_click of cl_gui_alv_grid
Obviously you are trying to register handler for class cl_gui_alv_grid which has nothing to do with cl_salv_table .
It should be registered like
methods: on_double_click for event double_click of cl_salv_events_table
importing row column.
Please refer standard program SALV_DEMO_TABLE_EVENTS for more information on this.
Regards
Marcin