CHECKBOX IN Object Oriented ALV ( OO ALV ) IN SAP ABAP .
In this SAP ABAP tutorial I will show you how to make editable checkbox 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=>checkbox_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 checkbox row , to we need to change the value to ‘X’ or 1 to mark it as checked .
At the end we need to call the REFRESH( ) method of class CL_SALV_TABLE .
We cannot activate the checkbox in classic ABAP list as in this case we cannot change the value of the
At the end we need to call the REFRESH( ) method of class CL_SALV_TABLE .
We cannot activate the checkbox in classic ABAP list as in this case we cannot change the value of the
checkbox.
Please refer to the following source codes :
*******************************************************************
*& Author : Roushan Kumar
*& Data : 14/06/2014
*& Description : Checkbox in OO ALV
*******************************************************************
REPORT ztestr_alv_10.
TYPES : BEGIN OF gy_bseg,
check TYPE xfeld,
bukrs TYPE bukrs,
belnr TYPE belnr_d,
gjahr TYPE gjahr,
buzei TYPE buzei,
wrbtr TYPE wrbtr,
END OF gy_bseg.
DATA : gt_bseg TYPE STANDARD TABLE OF gy_bseg INITIAL SIZE 1.
DATA : lo_alv TYPE REF TO cl_salv_table.
REFRESH : gt_bseg[].
*----------------------------------------------------------------------*
* 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_bseg> TYPE gy_bseg.
READ TABLE gt_bseg ASSIGNING <lfs_bseg> INDEX row.
IF sy-subrc IS INITIAL.
IF <lfs_bseg>-check IS INITIAL.
<lfs_bseg>-check = 'X'.
ELSE.
CLEAR <lfs_bseg>-check.
ENDIF.
ENDIF.
lo_alv->refresh( ).
ENDMETHOD.
"m_link_click
ENDCLASS. "lcl_event_handler IMPLEMENTATION
START-OF-SELECTION.
SELECT bukrs belnr gjahr buzei wrbtr
FROM bseg
INTO CORRESPONDING FIELDS OF TABLE gt_bseg
UP TO 10 ROWS.
IF sy-subrc IS INITIAL.
SORT gt_bseg BY bukrs belnr gjahr buzei .
ENDIF.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = gt_bseg.
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( 'CHECK' ).
lo_column->set_cell_type( if_salv_c_cell_type=>checkbox_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 :
Please refer to the following source codes :
*******************************************************************
*& Author : Roushan Kumar
*& Data : 14/06/2014
*& Description : Checkbox in OO ALV
*******************************************************************
REPORT ztestr_alv_10.
TYPES : BEGIN OF gy_bseg,
check TYPE xfeld,
bukrs TYPE bukrs,
belnr TYPE belnr_d,
gjahr TYPE gjahr,
buzei TYPE buzei,
wrbtr TYPE wrbtr,
END OF gy_bseg.
DATA : gt_bseg TYPE STANDARD TABLE OF gy_bseg INITIAL SIZE 1.
DATA : lo_alv TYPE REF TO cl_salv_table.
REFRESH : gt_bseg[].
*----------------------------------------------------------------------*
* 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_bseg> TYPE gy_bseg.
READ TABLE gt_bseg ASSIGNING <lfs_bseg> INDEX row.
IF sy-subrc IS INITIAL.
IF <lfs_bseg>-check IS INITIAL.
<lfs_bseg>-check = 'X'.
ELSE.
CLEAR <lfs_bseg>-check.
ENDIF.
ENDIF.
lo_alv->refresh( ).
ENDMETHOD.
"m_link_click
ENDCLASS. "lcl_event_handler IMPLEMENTATION
START-OF-SELECTION.
SELECT bukrs belnr gjahr buzei wrbtr
FROM bseg
INTO CORRESPONDING FIELDS OF TABLE gt_bseg
UP TO 10 ROWS.
IF sy-subrc IS INITIAL.
SORT gt_bseg BY bukrs belnr gjahr buzei .
ENDIF.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = gt_bseg.
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( 'CHECK' ).
lo_column->set_cell_type( if_salv_c_cell_type=>checkbox_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 :
CHECKBOX IN Object Oriented ALV ( OO ALV ) IN SAP ABAP |
CHECKBOX IN Object Oriented ALV ( OO ALV ) IN SAP ABAP |
working ! 23.05.2019
ReplyDeleteWynn Plaza Hotel - MapYRO
ReplyDeleteWynn Plaza Hotel. 인천광역 출장안마 3131 Las Vegas Blvd. South Las Vegas, NV 89109. Directions 거제 출장안마 · (702) 거제 출장마사지 770-7000. Call Now · More Info. Hours, 계룡 출장안마 Accepts Credit Cards, 사천 출장샵 Rating: 3 · 3,131 reviews