SET_TABLE_FOR_FIRST_DISPLAY and HotSpots
Posted onJun 17, 2008 at 06:30 PM | 1.8k Views
Follow
RSS Feed
Hello,
We have a report that uses SET_TABLE_FOR_FIRST_DISPLAY which works well but I have been asked to add a hotspot to call another screen. I see that a fieldcatalog can be passed but I have not found a method that corresponds to REUSE_ALV_FIELDCATALOG_MERGE.
I am a novice at method programming and did think that using the FM was the correct thing to do. Is there was a method that would do the same thing? Does anyone have some sample code?
Thank you in advance.
Regards, Dean.
Add a Comment
Alert Moderator
Assigned Tags
ABAP Development
Related questions
cl_gui_splitter_container and hotspots?
ByFormer Member Feb 18, 2011
Distinguish Hotspots
ByFormer Member Feb 19, 2014
5 Answers
Sort by:
Votes
|
Newest
|
Oldest
Best Answer
Chidanand Chauhan
Posted onJun 17, 2008 at 06:38 PM
2
Hi Dean,
There is no harm in OOALV, But I would suggest you to go for the OOALV.
Now a days a new feature has provided by SAP regarding ALV which is SALV.
I have created a sample program corresponding to almost all funcitonality.
just copy and paste this program you will see the difference how easy is OOALV (SALV).
*&---------------------------------------------------------------------*
*& Report ZCC_OOALV_CL_SALV_FUNCTIONS *
*& *
*&---------------------------------------------------------------------*
*& Developer Name: Chidanand Chauhan *
*& Date: 15/05/2008 *
*& Description: SALV for the Program for the functionality. *
*& *
*& *
*&---------------------------------------------------------------------*
report zcc_ooalv_cl_salv_functions.
data: ispfli type table of spfli.
field-symbols: <fs> type spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
data: gr_display type ref to cl_salv_display_settings.
data: gr_columns type ref to cl_salv_columns_table.
data: gr_column type ref to cl_salv_column_table.
data: color type lvc_s_colo.
data: gr_sorts type ref to cl_salv_sorts.
data: gr_agg type ref to cl_salv_aggregations.
data: gr_filter type ref to cl_salv_filters.
data: gr_layout type ref to cl_salv_layout.
data: key type salv_s_layout_key.
data: gr_selections type ref to cl_salv_selections.
data: xspfli type spfli.
data: gr_events type ref to cl_salv_events_table.
*----------------------------------------------------------------------*
* CLASS lcl_handle_events DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_handle_events definition.
public section.
methods:
on_user_command for event added_function of cl_salv_events
importing e_salv_function,
on_double_click for event double_click of cl_salv_events_table
importing row column,
on_link_click for event link_click of cl_salv_events_table
importing row column.
endclass. "lcl_handle_events DEFINITION
data: event_handler type ref to lcl_handle_events.
data: lt_celltype type salv_t_int4_column,
ls_celltype type salv_s_int4_column.
*&>>>>-----------------------------------------------------------------*
* START OF SELECTION
*&>>>>-----------------------------------------------------------------*
start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table
changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
*&>>>>-----------------------------------------------------------------*
* Next, add functions to the application toolbar. For this, use the
* CL_SALV_FUNCTIONS class. Create the object reference variable and
* receive the object using the GET_FUNCTIONS method of the GR_TABLE
* object. Call the method SET_ALL to force the ALV grid to show all
* standard functions.
*&---------------------------------------------------------------------*
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'Test Program for ZSALV By Chidanand' ).
*&<<<<-----------------------------------------------------------------*
*&----------------------------------------------------------------------
* change the Heading Text of a column as well as the color of a column.
*&----------------------------------------------------------------------
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'CITYTO' ).
gr_column->set_long_text( 'This is long text' ).
gr_column->set_medium_text( 'This is med text' ).
gr_column->set_short_text( 'This is sh' ).
gr_column ?= gr_columns->get_column( 'CITYFROM' ).
color-col = '6'.
color-int = '1'.
color-inv = '0'.
gr_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
gr_column->set_color( color ).
* data: val type SALV_DE_CONSTANT.
* val = 1.
* gr_column->SET_DROPDOWN_ENTRY( val ).
*&----------------------------------------------------------------------
*sorting to the ALV grid.
*&----------------------------------------------------------------------
gr_sorts = gr_table->get_sorts( ).
**&----------------------------------------------------------------------
** sorted by CITYTO, we can add an aggregation to subtotal the DISTANCE
** by CITYTO. Create the object reference variable and receive the object
** using the GET_AGGREGATIONS method of the GR_TABLE object. Next, add
** the aggregation by calling the ADD_AGGREGATION method of the GR_SORTS
** object. We also need to modify the call to ADD_SORT to set
** the SUBTOTAL = ABAP_TRUE.
**&----------------------------------------------------------------------
gr_sorts->add_sort( columnname = 'CITYTO' subtotal = abap_true ).
gr_agg = gr_table->get_aggregations( ).
gr_agg->add_aggregation( 'DISTANCE' ).
*&>>>>-----------------------------------------------------------------*
* Using the CL_SALV_FILTERS class setup some filters for the data
* in our ALV GRID. Create the object reference variable and receive the
* object using the GET_FILTERS method of the GR_TABLE object,and then
* simply called the method ADD_FILTER with the parameters.
*&>>>>-----------------------------------------------------------------*
gr_filter = gr_table->get_filters( ).
gr_filter->add_filter( columnname = 'CARRID' low = 'LH' ).
*&>>>>-----------------------------------------------------------------*
* If you want to allow the user to manage layouts of the ALV grid, you
* must use the class CL_SALV_LAYOUT.Create the object reference variable
* and receive the object using the GET_LAYOUT method of the GR_TABLE
* object. Then simply call the method SET_KEY with the parameters and
* set the save restriction using the SET_SAVE_RESTRICTION method.
*&>>>>-----------------------------------------------------------------*
gr_layout = gr_table->get_layout( ).
key-report = sy-repid.
gr_layout->set_key( key ).
gr_layout->set_save_restriction( cl_salv_layout=>restrict_none ).
*&>>>>-----------------------------------------------------------------*
*----------------------------SET GUI STATUS ---------------------------
* Go to function group SALV_METADATA_STATUS and copy the gui status
* ZSALV_TABLE_STANDARD into the ZCC_OOALV_CL_SALV_FUNCTIONS program.This
* is the standard gui status for the 2 Dimensional Table ALV grid. Once
* you have copied the status, set the screen status using the appropriate
* method of the object GR_TABLE. Go to the gui status and add a new
* button on the application toolbar and name it as u201CMYFUNCTIONu201D.
*&>>>>-----------------------------------------------------------------*
gr_table->set_screen_status(
pfstatus = 'ZSALV_TABLE_STANDARD'
report = sy-repid
set_functions = gr_table->c_functions_all ).
*&>>>>-----------------------------------------------------------------*
* -----------------Get Event Handler.----------------------------------*
* Define the event handler method for DOUBLE_CLICK event and add the
* implementation for the ON_DOUBLE_CLICK event handler method. Remember
* to set the handler for the event.
*&>>>>-----------------------------------------------------------------*
gr_events = gr_table->get_event( ).
create object event_handler.
set handler event_handler->on_user_command for gr_events.
set handler event_handler->on_double_click for gr_events.
set handler event_handler->on_link_click for gr_events.
* Set up selections.
gr_selections = gr_table->get_selections( ).
gr_selections->set_selection_mode( 1 ). "Single
gr_table->display( ).
*----------------------------------------------------------------------*
* CLASS lcl_handle_events IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_handle_events implementation.
method on_user_command.
* Get the selection rows
data: lr_selections type ref to cl_salv_selections.
data: lt_rows type salv_t_row.
data: ls_rows type i.
data: message type string.
case e_salv_function.
when '&FUNCTION'.
lr_selections = gr_table->get_selections( ).
lt_rows = lr_selections->get_selected_rows( ).
read table lt_rows into ls_rows index 1.
read table ispfli into xspfli index ls_rows.
concatenate xspfli-carrid xspfli-connid
xspfli-cityfrom xspfli-cityto
into message separated by space.
message i001(00) with 'You Clicked the button!' message.
endcase.
endmethod. "on_user_command
method on_double_click.
data: message type string.
data: row_c(4) type c.
row_c = row.
concatenate 'Row' row_c 'Column' column
into message separated by space.
message i001(00) with 'You double-clicked on ' message.
endmethod. "on_double_click
method on_link_click.
data: message type string.
data: row_c(4) type c.
row_c = row.
concatenate 'Row' row_c 'Column' column
into message separated by space.
message i001(00) with 'You link-clicked on ' message.
endmethod. "lcl_handle_events IMPLEMENTATION
endclass. "lcl_handle_events IMPLEMENTATION
Add a Comment
Alert Moderator
Share
Sourav Bhaduri
Posted onJun 17, 2008 at 07:27 PM
1
1) create a program with screen 100
2)copy - paste the code
3)declare a pf-status of "0100" with "EXIT"
REPORT ZTEST7 .
TYPE-POOLS slis.
TABLES: sflight.
*--------------------------------------------------------------------
* G L O B A L I N T E R N A L T A B L E S
*--------------------------------------------------------------------
DATA: gi_sflight TYPE STANDARD TABLE OF sflight.
*--------------------------------------------------------------------
* G L O B A L D A T A
*--------------------------------------------------------------------
DATA: ok_code LIKE sy-ucomm,
g_wa_sflight LIKE sflight.
* Declare reference variables to the ALV grid and the container
DATA:
go_grid TYPE REF TO cl_gui_alv_grid,
go_custom_container TYPE REF TO cl_gui_custom_container.
*--------------------------------------------------------------------
* S T A R T - O F - S E L E C T I O N.
*--------------------------------------------------------------------
START-OF-SELECTION.
SET SCREEN '100'.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS '0100'.
* Create objects
IF go_custom_container IS INITIAL.
CREATE OBJECT go_custom_container
EXPORTING
container_name = 'ALV_CONTAINER'.
CREATE OBJECT go_grid
EXPORTING
i_parent = go_custom_container.
PERFORM load_data_into_grid.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Form load_data_into_grid
*&---------------------------------------------------------------------*
FORM load_data_into_grid.
DATA:l_i_fieldcat_alv TYPE slis_t_fieldcat_alv,
l_wa_fieldcat_alv TYPE slis_fieldcat_alv,
l_i_fcat TYPE lvc_t_fcat,
l_wa_fcat TYPE lvc_s_fcat.
* Read data from table SFLIGHT
SELECT *
FROM sflight
INTO TABLE gi_sflight UP TO 100 ROWS.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
* I_PROGRAM_NAME =
* I_INTERNAL_TABNAME =
i_structure_name = 'SFLIGHT'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_INCLNAME =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
ct_fieldcat = l_i_fieldcat_alv
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3
.
IF sy-subrc = 0.
LOOP AT l_i_fieldcat_alv INTO l_wa_fieldcat_alv.
MOVE-CORRESPONDING l_wa_fieldcat_alv TO l_wa_fcat.
IF l_wa_fcat-fieldname = 'CARRID'.
l_wa_fcat-hotspot = 'X'.
ENDIF.
APPEND l_wa_fcat TO l_i_fcat.
ENDLOOP.
* Load data into the grid and display them
* CALL METHOD go_grid->set_table_for_first_display
* EXPORTING i_structure_name = 'SFLIGHT'
* CHANGING it_outtab = gi_sflight.
CALL METHOD go_grid->set_table_for_first_display
* EXPORTING
* i_buffer_active =
* i_bypassing_buffer =
* i_consistency_check =
* i_structure_name =
* is_variant =
* i_save =
* i_default = 'X'
* is_layout =
* is_print =
* it_special_groups =
* it_toolbar_excluding =
* it_hyperlink =
* it_alv_graphics =
* it_except_qinfo =
* ir_salv_adapter =
CHANGING
it_outtab = gi_sflight
it_fieldcatalog = l_i_fcat
* it_sort =
* it_filter =
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
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.
ENDIF.
ENDFORM. " load_data_into_grid
Add a Comment
Alert Moderator
Share
Former Member
Posted onJun 17, 2008 at 06:35 PM
0
Hi,
n Fieldcatalog We have a option to make a HOTSPOT
Example
fcat-fieldname = 'TRECEP'.
fcat-hotspot = 'X'. " For that Particular screen field assigned with Hotsot
Thanks
Vikranth
Add a Comment
Alert Moderator
Share
Former Member
Posted onJun 17, 2008 at 06:36 PM
0
Hi,
Check this example..You have to change the field catalog internal table with the hopspot..
TYPE-POOLS: slis.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv.
DATA: BEGIN OF wa_ekko,
ebeln like ekko-ebeln,
ekorg like ekko-ekorg,
ekgrp like ekko-ekgrp,
END OF wa_ekko.
DATA: v_repid TYPE syrepid.
v_repid = sy-repid.
DATA it_ekko LIKE STANDARD TABLE OF wa_ekko WITH HEADER LINE.
SELECT * UP TO 100 ROWS
FROM ekko
INTO CORRESPONDING FIELDS OF TABLE it_ekko.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'WA_EKKO'
i_inclname = v_repid
CHANGING
ct_fieldcat = gt_fieldcat.
* have hotspot for a PO.
DATA: s_fieldcat LIKE LINE OF gt_fieldcat.
s_fieldcat-hotspot = 'X'.
MODIFY gt_fieldcat FROM s_fieldcat TRANSPORTING hotspot
WHERE fieldname = 'EBELN'.
* Pass the program.
v_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = v_repid
it_fieldcat = gt_fieldcat
i_callback_user_command = 'USER_COMMAND'
TABLES
t_outtab = it_ekko.
---------------------------------------------------------------------
* FORM display_detail *
---------------------------------------------------------------------
* ........ *
---------------------------------------------------------------------
* --> UCOMM *
* --> SELFIELD *
---------------------------------------------------------------------
FORM user_command USING ucomm LIKE sy-ucomm
selfield TYPE slis_selfield.
IF ucomm = '&IC1'.
READ TABLE it_ekko INDEX selfield-tabindex.
IF sy-subrc = 0.
SET PARAMETER ID 'BES' FIELD it_ekko-ebeln.
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
ENDIF.
ENDIF.
ENDFORM.
Thanks
Vikranth
Add a Comment
Alert Moderator
Share
Clemens Li
Posted onJun 17, 2008 at 08:38 PM
0
Hi Dean,
you can convert the field catalog created with REUSE_ALV_FIELCATALOG_MERGE:
CALL FUNCTION 'LVC_TRANSFER_FROM_SLIS'
EXPORTING
it_fieldcat_alv = lt_fcat " TYPE slis_t_fieldcat_alv.
IMPORTING
et_fieldcat_lvc = pt_alv_fieldcat "TYPE lvc_t_fcat.
TABLES
it_data = pt_outtab
EXCEPTIONS
it_data_missing = 1
OTHERS = 2
.
Regards,
Clemens
Add a Comment
Alert Moderator
How can I use hotspot click in an ALV grid?
Posted onApr 11, 2013 at 08:28 PM | 6.2k Views
Follow
RSS Feed
Hello,
I have a table that is displayed in an ALV grid and I would like to have one of the columns as clickable icons.
For example:
Print | Doc. Type | Name
--------------------------------------
(icon) | .docx | first
(icon) | .pdf | second ... and so on.
I would like to click in the icon (Print column) and execute an action, but no matter what I do I can't set the action.
I know that is not just setting "fieldcatalog-hotspot='X'", but I don't know how to use a hotspot handler.
Here's some of the code I have:
TYPES: BEGIN OF ty_docs, print LIKE ICON-ID,
doc_type LIKE table_doc-TYPE, name LIKE table_doc-NAME,
END OF ty_docs. DATA: oref_dock TYPE REF TO cl_gui_docking_container, oref_alv TYPE REF TO cl_gui_alv_grid, i_fieldcat TYPE lvc_t_fcat, aux_fieldcat TYPE lvc_s_fcat, aux_lay TYPE lvc_s_layo, i_exclude TYPE TABLE OF syucomm, i_docs TYPE ty_docs, t_docs LIKE TABLE OF i_docs.
AT SELECTION-SCREEN OUTPUT. APPEND 'ONLI' TO i_exclude. APPEND 'SJOB' TO i_exclude. APPEND 'PRIN' TO i_exclude. CALL FUNCTION 'RS_SET_SELSCREEN_STATUS' EXPORTING p_status = sy-pfkey p_program = sy-repid TABLES p_exclude = i_exclude. AT SELECTION-SCREEN.
CHECK sy-ucomm = space. SELECT icon~ID AS print
doc~TYPE AS doc_type doc~NAME as name INTO CORRESPONDING FIELDS OF TABLE t_docs FROM table_doc AS doc INNER JOIN ICON AS icon ON icon~NAME EQ 'ICON_PRINT' GROUP BY icon~ID doc~TYPE doc~NAME.
IF sy-subrc = 0. IF oref_dock IS NOT BOUND. CREATE OBJECT oref_dock EXPORTING repid = sy-repid dynnr = sy-dynnr side = cl_gui_docking_container=>dock_at_bottom ratio = 90 EXCEPTIONS OTHERS = 1. ENDIF. IF oref_alv IS NOT BOUND. CHECK oref_dock IS BOUND. CREATE OBJECT oref_alv EXPORTING i_parent = oref_dock EXCEPTIONS OTHERS = 1. CHECK oref_alv IS BOUND. aux_fieldcat-fieldname = 'PRINT'. aux_fieldcat-coltext = 'Print'. aux_fieldcat-ref_table = 't_docs'. aux_fieldcat-ref_field = 't_docs-print'. aux_fieldcat-edit = ''. aux_fieldcat-just = 'C'. aux_fieldcat-hotspot = 'X'. aux_fieldcat-outputlen = 10. aux_fieldcat-col_pos = 0. APPEND aux_fieldcat TO i_fieldcat. CLEAR aux_fieldcat. aux_fieldcat-fieldname = 'TYPE'. aux_fieldcat-coltext = 'Doc. Type'. aux_fieldcat-ref_table = 't_docs'. aux_fieldcat-ref_field = 't_docs-doc_type'. aux_fieldcat-edit = ''. aux_fieldcat-outputlen = 15. aux_fieldcat-col_pos = 1. APPEND aux_fieldcat TO i_fieldcat. CLEAR aux_fieldcat. aux_fieldcat-fieldname = 'NAME'. aux_fieldcat-coltext = 'Name'. aux_fieldcat-ref_table = 't_docs'. aux_fieldcat-ref_field = 't_docs-name'. aux_fieldcat-edit = ''. aux_fieldcat-outputlen = 12. aux_fieldcat-col_pos = 2. APPEND aux_fieldcat TO i_fieldcat. CLEAR aux_fieldcat. aux_lay-grid_title = 'Docs'. aux_lay-edit = ''. CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING i_structure_name = 'ty_docs' i_internal_tabname = 't_docs' CHANGING ct_fieldcat = i_fieldcat EXCEPTIONS OTHERS = 3. CALL METHOD oref_alv->set_table_for_first_display EXPORTING i_structure_name = 'ty_docs' is_layout = aux_lay CHANGING it_fieldcatalog = i_fieldcat it_outtab = t_docs EXCEPTIONS OTHERS = 1. ELSE. CALL METHOD oref_alv->refresh_table_display EXCEPTIONS OTHERS = 1. ENDIF. ENDIF.
Thank you so much in advance!
Add a Comment
Alert Moderator
Assigned Tags
ABAP Development
Related questions
Problem in ALV Grid with select all and hotspot
BySridhar Meesala Oct 02, 2012
How to handle two hot spot clicks on one screen
ByFormer Member Mar 22, 2007
9 Answers
Sort by:
Votes
|
Newest
|
Oldest
Gourav Kumar Jena
Posted onApr 12, 2013 at 04:02 AM
1
Hi,
Please try to do like this. Check the below code.
This is just an example. Kindly do the same, I hope it will work out.
t_fieldcat is the table to be displayed in alv_grid
*" activating the hotspot
LOOP AT t_fieldcat INTO w_fieldcat .
IF w_fieldcat-fieldname = 'MATNR'.
w_fieldcat-hotspot = 'X'.
MODIFY t_fieldcat FROM w_fieldcat.
ENDIF.
ENDLOOP.
*" FORMS USERCMND
FORM usercmnd USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield .
set parameter id 'MAT' field rs_selfield-value.
LEAVE to TRANSACTION 'MM03'.
ENDFORM.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_user_command = 'USERCMND'
it_fieldcat = t_fieldcat
it_events = t_event
TABLES
t_outtab = t_mattab.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Regards,
Gourav
Message was edited by: Gourav Kumar Jena
Add a Comment
Alert Moderator
Share
Former Member
Posted onApr 12, 2013 at 02:35 AM
0
Hi Rafael,
You need to use the event handler fro hotspot click in this scenario.
You can refer to the below thread:
http://scn.sap.com/thread/1585156
Regards,
Sonal
Add a Comment
Alert Moderator
Share
Sachin Adak
Posted onApr 12, 2013 at 03:53 AM
0
Hi Rafael,
Please refer below link :
http://scn.sap.com/thread/923953
Add a Comment
Alert Moderator
Share
ramesh krishnamani
Posted onApr 12, 2013 at 03:57 AM
0
Hi Rafael,
You need to use the set event handler for the hot spot, then only when you click on the hotspot it will trigger.
Regards,
ramesh.
Add a Comment
Alert Moderator
Share
Former Member
Posted onApr 12, 2013 at 04:17 AM
0
Hi,
Better to use START-OF-SELECTION event before passing the values into Field cat.
Regards,
Venkat.
Add a Comment
Alert Moderator
Share
Former Member
Posted onApr 12, 2013 at 04:43 AM
0
Hello Rafael ,
Good day.
Hope this helps .
1. IN DATA DECLERATION:
********************Class Declaration********************* CLASS ZCL_GT_EVENT_RECEIVER DEFINITION DEFERRED. DATA : O_EVENT_RECEIVER TYPE REF TO ZCL_GT_EVENT_RECEIVER.
DATA: I_ROWS TYPE LVC_T_ROW, I_ROWNO TYPE LVC_T_ROID.
CLASS ZCL_GT_EVENT_RECEIVER DEFINITION. PUBLIC SECTION. METHODS : HANDLE_HOTSPOT for event HOTSPOT_CLICK of CL_GUI_ALV_GRID importing e_row_id e_column_id es_row_no. ENDCLASS.
CLASS ZCL_GT_EVENT_RECEIVER IMPLEMENTATION. METHOD HANDLE_HOTSPOT. IF E_COLUMN_ID-FIELDNAME = 'ICON’. *(As per your Requirement)
READ TABLE ALV_TABLE INTO STRUCTURE INDEX es_row_no-ROW_ID.
** You will get the line you have selected.
ENDIF.
ENDMETHOD.
ENDCLASS.
2. PBO of ALV Screen :
CREATE OBJECT O_EVENT_RECEIVER. SET HANDLER O_EVENT_RECEIVER->HANDLE_HOTSPOT for O_GRID. CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
Regards,
Gaja
Add a Comment
Alert Moderator
Share
2 Comments
Former Member Former Member
Apr 27, 2013 at 02:32 PM
With Pleasure ,..
All the best ,...
Regards ,
Gaja
Like 0
Share
Alert Moderator
Show all
Comment on This Answer
Former Member
Posted onApr 12, 2013 at 04:55 AM
0
Hi,
After creating grid set the even handler for hot spot.
SET HANDLER lcl_event_receiver=>handle_hotspot_click FOR alv_grid.
Try this code:
TABLES: mara,t001l.
DATA: BEGIN OF i_alv OCCURS 0,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
groes TYPE mara-groes,
maktx TYPE makt-maktx,
END OF i_alv.
DATA: wa_alv LIKE LINE OF i_alv.
DATA: alv_container TYPE REF TO cl_gui_docking_container.
DATA: alv_grid TYPE REF TO cl_gui_alv_grid.
DATA: layout TYPE lvc_s_layo.
DATA: fieldcat TYPE lvc_t_fcat.
DATA: gt_t001l TYPE STANDARD TABLE OF t001l.
CLASS lcl_event_receiver DEFINITION.
*---------------------------------------------------------------------*
* *
*---------------------------------------------------------------------*
PUBLIC SECTION.
*-->Method for User command
CLASS-METHODS :
handle_hotspot_click FOR EVENT hotspot_click OF
cl_gui_alv_grid
IMPORTING E_ROW_ID e_column_id.
ENDCLASS. "lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
* *
*---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_hotspot_click.
READ TABLE i_alv INTO wa_alv
INDEX e_row_id-index
TRANSPORTING matnr.
SET PARAMETER ID 'MAT' FIELD wa_alv-matnr.
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
ENDMETHOD. "handle_double_click
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
PARAMETERS: p_check TYPE matnr.
INITIALIZATION.
PERFORM get_data.
AT SELECTION-SCREEN OUTPUT.
* START-OF-SELECTION.
DATA: variant TYPE disvariant.
DATA: repid TYPE sy-repid.
repid = sy-repid.
variant-report = sy-repid.
variant-username = sy-uname.
layout-zebra = 'X'.
layout-edit_mode = 'X'.
CHECK alv_container IS INITIAL.
CREATE OBJECT alv_container
EXPORTING repid = repid
dynnr = sy-dynnr
side = alv_container->dock_at_right
extension = 350.
CREATE OBJECT alv_grid
EXPORTING
i_parent = alv_container.
* Set event handler
SET HANDLER lcl_event_receiver=>handle_hotspot_click FOR alv_grid.
* ALV Specific. Data selection.
* Populate Field Catalog
PERFORM get_fieldcatalog.
CALL METHOD alv_grid->set_table_for_first_display
EXPORTING
is_layout = layout
is_variant = variant
i_save = 'U'
i_structure_name = 'I_ALV'
CHANGING
it_outtab = i_alv[]
it_fieldcatalog = fieldcat[].
START-OF-SELECTION.
*************************************************************
* FORM GET_DATA
*************************************************************
FORM get_data.
SELECT * INTO CORRESPONDING FIELDS OF TABLE i_alv
FROM mara
INNER JOIN makt
ON mara~matnr = makt~matnr
UP TO 100 ROWS
WHERE makt~spras = sy-langu.
SORT i_alv ASCENDING BY matnr.
ENDFORM. "get_data
***************************************************************
* Form Get_Fieldcatalog - Set Up Columns/Headers
****************************************************************
FORM get_fieldcatalog.
DATA: ls_fcat TYPE lvc_s_fcat.
REFRESH: fieldcat.
CLEAR: ls_fcat.
ls_fcat-reptext = 'Material Number'.
ls_fcat-fieldname = 'MATNR'.
ls_fcat-ref_table = 'I_ALV'.
ls_fcat-outputlen = '18'.
ls_fcat-fix_column = 'X'.
ls_fcat-key = 'X'.
ls_fcat-hotspot = 'X'.
ls_fcat-col_pos = '1'.
APPEND ls_fcat TO fieldcat.
CLEAR: ls_fcat.
ls_fcat-reptext = 'Material Type'.
ls_fcat-fieldname = 'MTART'.
ls_fcat-ref_table = 'I_ALV'.
ls_fcat-outputlen = '10'.
ls_fcat-fix_column = 'X'.
ls_fcat-key = 'X'.
ls_fcat-col_pos = '2'.
APPEND ls_fcat TO fieldcat.
CLEAR: ls_fcat.
ls_fcat-reptext = 'Material Group'.
ls_fcat-fieldname = 'MATKL'.
ls_fcat-ref_table = 'I_ALV'.
ls_fcat-outputlen = '12'.
ls_fcat-col_pos = '3'.
APPEND ls_fcat TO fieldcat.
CLEAR: ls_fcat.
ls_fcat-reptext = 'Size'.
ls_fcat-fieldname = 'GROES'.
ls_fcat-ref_table = 'I_ALV'.
ls_fcat-outputlen = '30'.
ls_fcat-col_pos = '4'.
APPEND ls_fcat TO fieldcat.
CLEAR: ls_fcat.
ls_fcat-reptext = 'Material Description'.
ls_fcat-fieldname = 'MAKTX'.
ls_fcat-ref_table = 'I_ALV'.
ls_fcat-outputlen = '40'.
ls_fcat-col_pos = '5'.
APPEND ls_fcat TO fieldcat.
ENDFORM. "get_fieldcatalog
Hope this solves your problem....
Add a Comment
Alert Moderator
Share
Former Member
Posted onApr 12, 2013 at 07:04 AM
0
hi Rafael,
Please check below way.
You need to code the following
1. Define a Handler method
Methods:
handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column
i_fieldrows TYPE lvc_t_row.
w_fieldrows LIKE LINE OF i_fieldrows,
2. Implement the Handler Method
<< Your custom code to implement the action whenever it occurs >>
3. Register the handler method to listen to the event and act accordingly.
SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid .
The event is automatically raised by the runtime environment.
U can take help of this link also.
http://scn.sap.com/thread/1118242
Thanks
Tarak
Add a Comment
Alert Moderator
Share
Former Member
Posted onApr 12, 2013 at 11:58 AM
0
I would like to thank you all for the replies. They all helped me understand a little bit more of ABAP and event handlers.
Thanks so much!
Add a Comment
Alert Moderator