Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use hotspot click in an ALV grid?

Former Member
0 Kudos

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.

DATAoref_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!

11 REPLIES 11

Former Member
0 Kudos

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

former_member213851
Active Contributor
0 Kudos

Hi Rafael,

Please refer below link :

http://scn.sap.com/thread/923953

former_member282823
Active Participant

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.

former_member183224
Participant
0 Kudos

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

Former Member
0 Kudos

Hi,

Better to use START-OF-SELECTION event before passing the values into Field cat.

Regards,

Venkat.

Former Member
0 Kudos

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

0 Kudos

Perfect, Gaja!
It worked as I expected.

Thanks a lot.

0 Kudos

With Pleasure ,..

All the best ,...

Regards ,

Gaja

Former Member
0 Kudos

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....

Former Member
0 Kudos

hi Rafael,

Please check below way.

You need to code the following

1. Define a Handler method

  1. Methods: 
  2. handle_double_click  
  3.       FOR EVENT double_click OF cl_gui_alv_grid  
  4.         IMPORTING e_row e_column 
  5.  
  6.            i_fieldrows      TYPE lvc_t_row. 
  7.            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

Former Member
0 Kudos

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!