Monday 18 August 2014

HOTSPOT/SINGLE CLICK AREA IN Object Oriented ALV ( 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 ofif_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 :
*******************************************************************
*& Author      : Roushan Kumar
*& Data        : 15/06/2014
*& Description : Hotspot in OO ALV
*******************************************************************
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( ).
OUTPUT :
clip_image001
clip_image003
clip_image004

No comments:

Post a Comment