cancel
Showing results for 
Search instead for 
Did you mean: 

select all, deselect all for checkboxes in webdynpro alv

Former Member
0 Kudos

First column of my alv report has checkboxes, and i have placed two buttons  SELECT ALL and DESELECT ALL , if i click on SELECT ALL button, all the checboxes should check, if i click on DESELECT ALL  button  all the checboxes should un check, could any one please explain how to do this with an example program

please check the below screen shot of my alv report

Thanks in advance

Accepted Solutions (1)

Accepted Solutions (1)

former_member210804
Active Participant
0 Kudos

Hi Laxmi,

please do the below steps.

1. for creating buttons in ALV WDA.

CREATE OBJECT lr_button.

  CALL METHOD lr_button->set_text

    EXPORTING

      value = 'SELECT ALL'.

    lr_button->set_image_source( 'ICON_SELECT_ALL' ).

  CALL METHOD lv_value->if_salv_wd_function_settings~create_function   " Trigger the ALV buttons using ON_FUNCTION event

    EXPORTING

      id    = '

CREATE OBJECT lr_button.

  CALL METHOD lr_button->set_text

    EXPORTING

      value = 'SELECT ALL'.

    lr_button->set_image_source( 'ICON_SELECT_ALL' ).

  CALL METHOD lv_value->if_salv_wd_function_settings~create_function   " Trigger the ALV buttons using ON_FUNCTION event

    EXPORTING

      id    = 'SELECT_ALL'

    RECEIVING

      value = button1.

  button1->set_editor( lr_button ).

  CLEAR lr_button.

  CREATE OBJECT lr_button.

  CALL METHOD lr_button->set_text

    EXPORTING

      value = 'DESELECT ALL'.

    lr_button->set_image_source( 'ICON_DESELECT_ALL' ).

  CALL METHOD lv_value->if_salv_wd_function_settings~create_function

    EXPORTING

      id    = 'DESELECT_ALL'

    RECEIVING

      value = button1.

  button1->set_editor( lr_button ).

  CLEAR lr_button.

    RECEIVING

      value = button1.

  button1->set_editor( lr_button ).

  CLEAR lr_button.

  CREATE OBJECT lr_button.

  CALL METHOD lr_button->set_text

    EXPORTING

      value = 'DESELECT ALL'.

    lr_button->set_image_source( 'ICON_DESELECT_ALL' ).

  CALL METHOD lv_value->if_salv_wd_function_settings~create_function

    EXPORTING

      id    = 'DESELECT_ALL'

    RECEIVING

      value = button1.

  button1->set_editor( lr_button ).

  CLEAR lr_button.

2. In order to trigger the buttons, we have to create the event handler method

( using ON_FUNCTION event ) with the name metioned above .

3. write the code in the corresponding method as below

for SELECT_ALL method

  DATA lo_nd_output TYPE REF TO if_wd_context_node.

  DATA lo_el_output TYPE REF TO if_wd_context_element.

  DATA ls_output TYPE wd_this->element_output.

  DATA lt_output TYPE wd_this->elements_output.

*  navigate from <CONTEXT> to <OUTPUT> via lead selection

  lo_nd_output = wd_context->get_child_node( name = wd_this->wdctx_output ).

*  get element via lead selection

  lo_el_output = lo_nd_output->get_element( ).

  lo_nd_output->get_static_attributes_table(

*    EXPORTING

*      from  = 1    " Web Dynpro: Index of Context Element

*      to    = 2147483647    " Web Dynpro: Index of Context Element

    IMPORTING

      table =  lt_output

  ).

  DATA l_button TYPE string.

  l_button = r_param->id.

*---------checking if the function is set to 'button' ---------*

  IF l_button = 'SELECT_ALL'.                                        " Replace to DESELECT_ALL

    LOOP AT lt_output INTO ls_output.

      ls_output-chkbox = 'X'.                                              " replace 'X' to '  ' for DESELECT_ALL

      MODIFY lt_output FROM ls_output TRANSPORTING chkbox.

    ENDLOOP.

    lo_nd_output->bind_table(

      EXPORTING

        new_items            =  lt_output ).

  ENDIF.

Hope it will be useful .

Best regards,

Rao.

Former Member
0 Kudos

Thanks Narsimha its working now

Answers (2)

Answers (2)

former_member210804
Active Participant
0 Kudos

Welcome...

former_member222068
Active Participant
0 Kudos

Hi Vijaya,

1. Read the data of the table using the method GET_STATIC_ATTRIBUTES_TABLE( ) into a internal table ( eg: lt_checkbox )

2. Loop the lt_checkbox and set checkbox = 'X'  and use modify or append statement.

sample code:

Data : lt_checkbox type wd_this->elements_<name of the node>,

          ls_chekcbox like line of lt_checkbox.

loop at lt_checkbox into ls_checkbox.

ls_checkbox-checkbox = 'X'.

MODIFY lt_checkbox from ls_checkbox TRANSPORTING checkbox.

endloop.

Hope this should solve your issue

Thanks & Regards,

Sankar Gelivi

Former Member
0 Kudos

Thanks Sankar for ur reply,

both Buttons are triggering  same method ( ON_ALV_FUNC)  , pls check the screen shot, can u pls let me know how to differentiate two buttons  in the method

pls see the screen shot

former_member222068
Active Participant
0 Kudos

Hi Vijaya,

Copy the following code in the WDBOFOREACTION( ).

    data lo_api_controller type ref to if_wd_view_controller.
  data lo_action         type ref to if_wd_action.

  lo_api_controller = wd_this->wd_get_api( ).
  lo_action = lo_api_controller->get_current_action( ).

  if lo_action is bound.
    case lo_action->name.
      when 'SELECT_ALL'.   ( Name of the action )
         Logic to be performed
    endcase.
  endif.

Thanks & Regards,

Sankar Gelivi