Friday 13 March 2015

HOTSPOT/SINGLE CLICK AREA IN ( OO ALV ) IN SAP ABAP .

In this SAP ABAP tutorial I will show you how to make hospot or single click area in Object Oriented ALV ( OO ALV ) using CL_SALV_TABLE.

To achieve this functionality you need to call the method set_cell_type of class cl_salv_column_table and pass the value as if_salv_c_cell_type=>hotspot . Now clicking on the checkbox will trigger the event LINK_CLICK , so we need to declare and event handler class here lcl_event_handler and declare a method m_link_click to handle the action . The LINK_CLICK event will give us the row and column value of the selected row , so that we can do further process based on the value of that field.
NB : Hotspot coding is similar to the checkbox one of.my previous tutorials except instead of if_salv_c_cell_type=>checkbox_hotspot we need to pass if_salv_c_cell_type=>hotspot .
At the end we need to call the REFRESH( ) method of class CL_SALV_TABLE .
In this SAP ABAP tutorial example we are making the column vbeln values as hotspot so that when the user single click on the value it will lead us to the transaction ‘VL03N’ with the corresponding VBELN value.
Please refer to the following source codes :

REPORT  ztestr_alv_10.
TYPES : BEGIN OF gy_vbap,
          vbeln TYPE vbeln_va,
          posnr TYPE posnr_va,
          matnr TYPE matnr,
END OF   gy_vbap.
DATA : gt_vbap TYPE STANDARD TABLE OF gy_vbap INITIAL SIZE 1.
DATA : lo_alv TYPE REF TO cl_salv_table.
REFRESH : gt_vbap[].
*----------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
      m_link_click FOR EVENT link_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS.                    "lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD m_link_click.
FIELD-SYMBOLS : <lfs_vbap> TYPE gy_vbap.
READ TABLE gt_vbap ASSIGNING <lfs_vbap> INDEX row.
IF sy-subrc IS INITIAL.
SET PARAMETER ID 'VL' FIELD <lfs_vbap>-vbeln.
CALL TRANSACTION 'VL03N'.
ENDIF.
    lo_alv->refresh( ).
ENDMETHOD.                    "m_link_click
"m_link_click
ENDCLASS.                    "lcl_event_handler IMPLEMENTATION
START-OF-SELECTION.
SELECT vbeln posnr matnr
FROM vbap
INTO TABLE gt_vbap
UP TO 10 ROWS.
IF sy-subrc IS INITIAL.
SORT gt_vbap BY vbeln posnr matnr  .
ENDIF.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
          r_salv_table = lo_alv
CHANGING
          t_table      = gt_vbap.
CATCH cx_salv_msg .
ENDTRY.
*-- Checkbox logic starts
DATA : lo_columns TYPE REF TO cl_salv_columns_table.
  lo_columns = lo_alv->get_columns( ).
  lo_columns->set_optimize( 'X' ).
DATA : lo_column TYPE REF TO cl_salv_column_table.
TRY.
      lo_column ?= lo_columns->get_column( 'VBELN' ).
      lo_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
      lo_column->set_output_length( 10 ).
CATCH cx_salv_not_found.
ENDTRY.
DATA: lo_events TYPE REF TO cl_salv_events_table.
  lo_events = lo_alv->get_event( ).
DATA: lo_event_handler TYPE REF TO lcl_event_handler.
CREATE OBJECT lo_event_handler.
SET HANDLER lo_event_handler->m_link_click FOR lo_events.
*-- Checkbox logic end
  lo_alv->display( ).









3 comments:

  1. As the admin of this web page is working, no hesitation very soon it will be
    renowned, due to its quality contents.

    Also visit my web site :: Louis Vuitton Outlet Store

    ReplyDelete
  2. If some one needs expert view on the topic of running a blog after that i
    suggest him/her to pay a quick visit this web site,
    Keep up the good work.

    Review my weblog ... Louis Vuitton Outlet

    ReplyDelete