SAP ABAP: Capturing CHECK BOX event in FM REUSE_ALV_GRID_DISPLAY / Cell Editing

Requirement: Show total number of rows selected as message whenever a user
    click on a check box column in REUSE_ALV_GRID_DISPLAY.

To accomplish this, we have to use EVENTS in REUSE_ALV_GRID_DISPLAY to capture changes made by the user.

In data declaration:
Data: gt_events  TYPE slis_t_event,
        wa_events  TYPE slis_alv_event.
*/------------------------------------------------------------------------
 FORM display_alv_report.
*/------------------------------------------------------------------------
gd_repid = sy-repid.
Refresh: gt_events.

wa_events-name = 'CALLER_EXIT'.
wa_events-form = 'CALLER_EXIT'.
APPEND wa_events TO gt_events.
wa_events-name = 'DATA_CHANGED'.
wa_events-form = 'DATA_CHANGED'.
APPEND wa_events TO gt_events.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
          i_callback_program       = l_repid
          I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
          I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
          is_layout                = wa_layout
          it_events                = gt_events
          it_fieldcat              = lt_fieldcat[]
          i_default                = 'X'
          i_save                    = 'A'
     TABLES
          t_outtab                 = i_Output
     EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
If sy-subrc <> 0.
   Message 'Error in ALV report display' type 'E'.
Endif.
ENDFORM.               "End of DISPLAY_ALV_REPORT
*/======================================================================


*/---------------------------------------------------------------------
FORM data_changed USING ir_data_changed TYPE REF TO cl_alv_changed_data_protocol.
*/---------------------------------------------------------------------
**// This module will be called every time changes made on the 'TAG' column.
**// If in the register_edit_event you use the MC_EVT_MODIFIED, any field
**// that has an EDIT mode will call this module whenever changes been made without capturing the ENTER event.

DATA ls_modi TYPE lvc_s_modi.
* Check each modification:
LOOP AT ir_data_changed->mt_mod_cells INTO ls_modi.
     CASE ls_modi-fieldname.
          WHEN 'TAG'.
*              break-point.
              Read table i_Output Index ls_modi-row_id.
              Check sy-subrc eq 0.
              If i_Output-tag eq 'X'.
                  gTagCtr = gTagCtr - 1.
              Else.
                  gTagCtr = gTagCtr + 1.
              Endif.
              Perform Mess_Info Using gTagCtr.
        ENDCASE.
ENDLOOP.
ENDFORM.                    "End of data_changed
*/=====================================================================

*/--------------------------------------------------------------------
  FORM Mess_Info Using gTagCtr.
*/--------------------------------------------------------------------
Data: cCtr(5) type c.
Data: Mess type string.
cCtr = gTagCtr.
Concatenate 'Total rows selected (' cCtr ')'
             Into Mess Separated by Space.
Message Mess Type 'S' Display Like 'I'.
ENDFORM.                    "End of Mess_Info
*/=====================================================================

*/---------------------------------------------------------------------
 FORM caller_exit USING is_data TYPE slis_data_caller_exit.
*/---------------------------------------------------------------------
**//This module will be fired up before displaying the ALV report.
DATA: lr_alv TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
     IMPORTING
        e_grid = lr_alv.
CALL METHOD lr_alv->register_edit_event
     EXPORTING
          i_event_id = cl_gui_alv_grid=>mc_evt_modified.
ENDFORM.       "End of CALLER_EXIT
*/=====================================================
Sample output displaying total number of rows selected in REAL TIME.

  SAP ABAP Capturing CHECK BOX REUSE_ALV_GRID_DISPLAY Cell Editing

SAP ABAP Capturing CHECK BOX REUSE_ALV_GRID_DISPLAY Cell Editing


 
Good luck and happy abaping!

Mabuhay, Philippines!

Comments

  1. Bet365 Casino Review and Bonus - VieCasino.com
    Check out Bet365 happyluke Casino's wide bet365 range クイーンカジノ of games, slots, table games, live betting, live dealer games, bingo and more. Join today and claim your welcome bonus.

    ReplyDelete
  2. Capturing checkbox events in SAP ABAP within function modules is an essential capability. It enhances the user experience by enabling dynamic responses to user interactions. How Stream Anime It is empowering developers for SAP systems solution.

    ReplyDelete

Post a Comment

Popular posts from this blog

SAP ABAP: Smartforms/SAPscript formatting

SAP ABAP: Adding leading zero to char or string.