Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
fathiriq
Discoverer

Hey there, in this article, I’ll be talking about using checkbox hotspots in OO-ALV. Let’s dive into the scenario I faced.

So, my functional team had a request to create a report in ALV Grid format with a column layout like in the image. Each “ID” has one or more items, and each item has a repeating view formation:

  1. Basic
  2. Plant
  3. Purchasing

Here are the scenarios that needed to be handled:

  1. Editable checkboxes are only available on the first item, non-editable checkboxes are available on subsequent item rows.
  2. Changes in value (tick/untick) in editable checkboxes should also be reflected in non-editable checkboxes, on the same IDs.

This is the (expected) result. The animated version will be at the end of the article :)This is the (expected) result. The animated version will be at the end of the article 🙂

Initially, I tried using the hotspot setting with just the SET_CELL_TYPE_COLUMN method by dynamically filling the T_CELLTYPE table for each row.

 

FORM f_build_data.

  DO 3 TIMES.
    DATA(id_idx) = sy-index. "--ID

    LOOP AT gi_mara ASSIGNING FIELD-SYMBOL(<fs_mara>).
      DATA(seq_idx) = sy-tabix. "-- item number

      DATA(view) = SWITCH char10( seq_idx
        WHEN 1 THEN 'BASIC'
        WHEN 2 THEN 'PLANT'
        WHEN 3 THEN 'PURCHASING' ).

      gw_report = VALUE #(
        no = id_idx
        item = seq_idx
        matnr = <fs_mara>-matnr
        view = view
        status = icon_incomplete ).  
      
      "-- fill the T_CELLTYPE column for each row,
      "-- based on ITEM NUMBER
      DATA(ctype) = SWITCH salv_s_int4_column( seq_idx
        WHEN 1 THEN VALUE #( columnname = 'SEL' value = if_salv_c_cell_type=>checkbox_hotspot )
        ELSE VALUE #( columnname = 'SEL' value = if_salv_c_cell_type=>checkbox ) ).

      APPEND ctype TO gw_report-t_celltype.

      APPEND gw_report TO gi_report.

    ENDLOOP.

  ENDDO.

ENDFORM.

 

Unfortunately, this attempt didn’t work out. The click event (tick/untick) could be handled, but the presentation of the editable checkbox icon couldn’t be displayed.

So close, yet so farSo close, yet so far

 After trying various approaches, I found that the requested scenario could be achieved by setting the “Checkbox” column using two methods altogether, SET_CELL_TYPE and SET_CELL_TYPE_COLUMN.

 

FORM f_display_data.

  DATA lo_collist TYPE REF TO cl_salv_column_list.

  cl_salv_table=>factory(
    IMPORTING
      r_salv_table = go_alv
    CHANGING
      t_table      = gi_report
  ).

  DATA(lo_cols) = go_alv->get_columns( ).
  lo_cols->set_optimize(
    value = abap_true
  ).

*-- Set CHECKBOX_HOTSPOT first
  lo_collist ?= lo_cols->get_column( columnname = 'SEL' ).
  lo_collist->set_cell_type(
    value = if_salv_c_cell_type=>checkbox_hotspot
  ).

*-- Then, setting up cell type, based on value in T_CELLTYPE
  lo_cols->set_cell_type_column( value = 'T_CELLTYPE' ).

*-- events
  DATA(lo_events) = go_alv->get_event( ).

  CREATE OBJECT go_handler.
  SET HANDLER go_handler->on_click FOR lo_events.

  go_alv->display( ).

ENDFORM.

 

First, I used the SET_CELL_TYPE method to define the CHECKBOX_HOTSPOT on the “Checkbox” field. Then, the SET_CELL_TYPE_COLUMN method was also called to change the cell type according to the value in the T_CELLTYPE table.

And here’s the result: 

FinallyFinally

I might not have been diligent enough in finding the right solution on the SAP forum, but I feel fortunate that I was able to fulfill the requested scenario with a slightly unexpected workaround like the one above.

For the complete code, check on this link. 

Hope this helps fellow ABAPers out there. See you around!

Labels in this area