Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Checkbox issue in OOALV

Former Member
0 Kudos

Hi Everybody,

In my output ALV table, i have two cloumns with checkboxes. At time, user cannot check both the checkboxes, how to do this validation?

In my code i have used

CALL METHOD w_ref_alv_grid->check_changed_data

IMPORTING

e_valid = w_valid.

IF w_valid EQ 'X'.

But it is not triggering, when the user checks the checkbox, how to capture this event? how to do the validation?

Needy help will be appreciated.

1 ACCEPTED SOLUTION

kesavadas_thekkillath
Active Contributor
0 Kudos

No need of validation. When clicked remove the check from other one and place it in the clicked one. Check the example below :


CLASS lcl DEFINITION DEFERRED.

TYPE-POOLS: slis.
TYPES:BEGIN OF t_data,
       chk1(4) TYPE c,
       chk2(4) TYPE c,
       matnr TYPE matnr,
       END OF t_data.
DATA: i_fcat TYPE slis_t_fieldcat_alv ,
      w_fcat LIKE LINE OF i_fcat,
      it_data TYPE TABLE OF t_data,
      wa TYPE t_data,
      i_cat TYPE lvc_t_fcat,
      w_cat TYPE lvc_s_fcat,
      cont TYPE REF TO cl_gui_custom_container,
      grid  TYPE REF TO cl_gui_alv_grid,
      receiver TYPE REF TO lcl.

CLASS lcl DEFINITION.
  PUBLIC SECTION.
    METHODS handle_hotspot_click FOR EVENT hotspot_click OF
               cl_gui_alv_grid IMPORTING e_row_id e_column_id es_row_no.
ENDCLASS.                    "lcl DEFINITION

CLASS lcl IMPLEMENTATION.
  METHOD handle_hotspot_click.
    READ TABLE it_data INTO wa INDEX e_row_id.
    CHECK sy-subrc = 0.
    CASE e_column_id-fieldname.
      WHEN 'CHK1'.
        IF wa-chk1 = icon_radiobutton.
          wa-chk1 = icon_wd_radio_button_empty.
          MODIFY it_data from wa INDEX e_row_id.
        ELSE.
          wa-chk1 = icon_radiobutton.
          wa-chk2 = icon_wd_radio_button_empty.
          MODIFY it_data from wa INDEX e_row_id.
        ENDIF.
      WHEN 'CHK2'.
        IF wa-chk2 = icon_radiobutton.
          wa-chk2  = icon_wd_radio_button_empty.
           MODIFY it_data from wa INDEX e_row_id.
        ELSE.
          wa-chk2 = icon_radiobutton.
          wa-chk1 = icon_wd_radio_button_empty.
           MODIFY it_data from wa INDEX e_row_id.
        ENDIF.
    ENDCASE.
    CALL METHOD grid->refresh_table_display.
  ENDMETHOD.                    "handle_hotspot_click
ENDCLASS.                    "lcl IMPLEMENTATION

START-OF-SELECTION.
  CALL SCREEN 100.

MODULE fill_data OUTPUT.
  IF i_cat IS INITIAL.
    w_cat-fieldname = 'CHK1'.
    w_cat-icon = 'X'.
    w_cat-hotspot = 'X'.
    APPEND w_cat TO i_cat.
    CLEAR w_cat.
    w_cat-fieldname = 'CHK2'.
    w_cat-hotspot = 'X'.
    w_cat-icon = 'X'.
    APPEND w_cat TO i_cat.
    CLEAR w_cat.
    w_cat-fieldname = 'MATNR'.
    APPEND w_cat TO i_cat.
  ENDIF.
  SELECT matnr FROM mara
  INTO CORRESPONDING FIELDS OF TABLE it_data
  UP TO 20 ROWS.

  LOOP AT it_data INTO wa.
    wa-chk1 = '@SR@'.
    wa-chk2 =  '@SR@'.
    MODIFY it_data FROM wa INDEX sy-tabix.
  ENDLOOP.
ENDMODULE.                 " fill_data  OUTPUT

MODULE display OUTPUT.
  IF cont IS INITIAL .
    CREATE OBJECT cont
      EXPORTING
        container_name = 'CON'.
    CREATE OBJECT grid
      EXPORTING
        i_parent = cont.
    CALL METHOD grid->set_table_for_first_display
      CHANGING
        it_outtab       = it_data[]
        it_fieldcatalog = i_cat[].
    CREATE OBJECT receiver.
    SET HANDLER receiver->handle_hotspot_click  FOR grid.
  ENDIF.
ENDMODULE.                    "DISPLAY OUTPUT

6 REPLIES 6

former_member184578
Active Contributor
0 Kudos

Hi,

Put hot spot for the check box, In the event of hot spot click ,..

call method check_changed _data of alv grid which updates your internal table,

then loop the internal table and check if both the check boxes are selected or not., If selected display error message..

else instead of hot spot, which calls the event each time., put a save button, In on click of save button and do the same as above.,

hope this helps u.,

Thanks & Regards,

Kiran

Former Member
0 Kudos

Hello friend,

I think this link will be useful for you to solve your issue.

You can use the method o_grid->check_changed_data( ). and capture the values for the check box.

Still have the same problem revert back to me.

Thanks,

Sri Hari

Edited by: srihari.kumar on Dec 21, 2011 10:36 AM

Former Member
0 Kudos

Hi,

Go through the following Link,

http://wiki.sdn.sap.com/wiki/display/ABAP/ALVGridReport-withObjectOrientedSALVClasses

I hope it will give idea to you.

Warm Regards,

PavanKumar.G

Former Member
0 Kudos

Hi,

Try using ALV event 'DATA_CHANGED' for both the checkbox entry (checked/unchecked)

In the implementation method, update the internal table with the checkbox value and place the validation code for chkbox.

When the event is triggered for 1st chkbox, update the internal table. Now when the event gets triggered for 2nd checkbox, validation code executes as per your requirement.

Regards,

Sharin

kesavadas_thekkillath
Active Contributor
0 Kudos

No need of validation. When clicked remove the check from other one and place it in the clicked one. Check the example below :


CLASS lcl DEFINITION DEFERRED.

TYPE-POOLS: slis.
TYPES:BEGIN OF t_data,
       chk1(4) TYPE c,
       chk2(4) TYPE c,
       matnr TYPE matnr,
       END OF t_data.
DATA: i_fcat TYPE slis_t_fieldcat_alv ,
      w_fcat LIKE LINE OF i_fcat,
      it_data TYPE TABLE OF t_data,
      wa TYPE t_data,
      i_cat TYPE lvc_t_fcat,
      w_cat TYPE lvc_s_fcat,
      cont TYPE REF TO cl_gui_custom_container,
      grid  TYPE REF TO cl_gui_alv_grid,
      receiver TYPE REF TO lcl.

CLASS lcl DEFINITION.
  PUBLIC SECTION.
    METHODS handle_hotspot_click FOR EVENT hotspot_click OF
               cl_gui_alv_grid IMPORTING e_row_id e_column_id es_row_no.
ENDCLASS.                    "lcl DEFINITION

CLASS lcl IMPLEMENTATION.
  METHOD handle_hotspot_click.
    READ TABLE it_data INTO wa INDEX e_row_id.
    CHECK sy-subrc = 0.
    CASE e_column_id-fieldname.
      WHEN 'CHK1'.
        IF wa-chk1 = icon_radiobutton.
          wa-chk1 = icon_wd_radio_button_empty.
          MODIFY it_data from wa INDEX e_row_id.
        ELSE.
          wa-chk1 = icon_radiobutton.
          wa-chk2 = icon_wd_radio_button_empty.
          MODIFY it_data from wa INDEX e_row_id.
        ENDIF.
      WHEN 'CHK2'.
        IF wa-chk2 = icon_radiobutton.
          wa-chk2  = icon_wd_radio_button_empty.
           MODIFY it_data from wa INDEX e_row_id.
        ELSE.
          wa-chk2 = icon_radiobutton.
          wa-chk1 = icon_wd_radio_button_empty.
           MODIFY it_data from wa INDEX e_row_id.
        ENDIF.
    ENDCASE.
    CALL METHOD grid->refresh_table_display.
  ENDMETHOD.                    "handle_hotspot_click
ENDCLASS.                    "lcl IMPLEMENTATION

START-OF-SELECTION.
  CALL SCREEN 100.

MODULE fill_data OUTPUT.
  IF i_cat IS INITIAL.
    w_cat-fieldname = 'CHK1'.
    w_cat-icon = 'X'.
    w_cat-hotspot = 'X'.
    APPEND w_cat TO i_cat.
    CLEAR w_cat.
    w_cat-fieldname = 'CHK2'.
    w_cat-hotspot = 'X'.
    w_cat-icon = 'X'.
    APPEND w_cat TO i_cat.
    CLEAR w_cat.
    w_cat-fieldname = 'MATNR'.
    APPEND w_cat TO i_cat.
  ENDIF.
  SELECT matnr FROM mara
  INTO CORRESPONDING FIELDS OF TABLE it_data
  UP TO 20 ROWS.

  LOOP AT it_data INTO wa.
    wa-chk1 = '@SR@'.
    wa-chk2 =  '@SR@'.
    MODIFY it_data FROM wa INDEX sy-tabix.
  ENDLOOP.
ENDMODULE.                 " fill_data  OUTPUT

MODULE display OUTPUT.
  IF cont IS INITIAL .
    CREATE OBJECT cont
      EXPORTING
        container_name = 'CON'.
    CREATE OBJECT grid
      EXPORTING
        i_parent = cont.
    CALL METHOD grid->set_table_for_first_display
      CHANGING
        it_outtab       = it_data[]
        it_fieldcatalog = i_cat[].
    CREATE OBJECT receiver.
    SET HANDLER receiver->handle_hotspot_click  FOR grid.
  ENDIF.
ENDMODULE.                    "DISPLAY OUTPUT

Former Member
0 Kudos

Hi Keshav,

Thanks a lot for the quick response. Youe logic worked for my scenario. Thanks Everybody.