Skip to Content
avatar image
Former Member

re: creating check boxes in ALV grid using web dynpro

Hi Techies,

I need to have a check box column in alv grid, and it should allow me to select the check box and the selected row has to be updated in the database.

Kindly assist me with the steps to handle the above mentioned scenario

Thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • avatar image
    Former Member
    May 12, 2009 at 07:05 AM

    Check this link on ALV

    [alv]

    Hope it helps.

    Regards,

    Radhika.

    Add comment
    10|10000 characters needed characters exceeded

  • May 12, 2009 at 07:12 AM

    Hi,

    Code for creating check box in one of the column in ALV

     DATA lo_column_settings TYPE REF TO if_salv_wd_column_settings.
      DATA lo_column          TYPE REF TO cl_salv_wd_column.
      DATA lo_column_hdr      TYPE REF TO cl_salv_wd_column_header. 
      DATA lr_checkbox TYPE REF TO cl_salv_wd_uie_checkbox.
    
      lo_column = lo_column_settings->get_column( 'SELECTION' ).
      lo_column->set_h_align( cl_wd_table_column=>e_h_align-center ).
      lo_column->set_width( value = '75' ) .
      lo_column_hdr = lo_column->create_header( ).
      lo_column->set_fixed_position( cl_wd_abstr_table_column=>e_fixed_position-left ).
    
    
      CREATE OBJECT lr_checkbox
        EXPORTING
          checked_fieldname = 'SELECTION'.
    
      wd_comp_controller->lo_alv_chk = lr_checkbox.
      lo_column->set_cell_editor( lr_checkbox ).
      lr_checkbox->set_enabled( value = abap_true ).    "abap_false ).
      lr_checkbox->set_enabled_fieldname( value = 'STOKZ' ).
      lo_column_hdr->set_text( 'Select' ).
    

    For Updating the database value for this particular row, you need to create method of type 2 (Event Handler) link this with Event 'ON_CELL_ACTION' of Component Usage of ALV.

    In this method using import parameter R_Param (r_param->index) you will be able to get the which row has been selected, fetch the values of this row and update the database values for same.

    Regards

    Vishal.

    Add comment
    10|10000 characters needed characters exceeded

  • May 12, 2009 at 02:56 PM

    Hi Harini,

    Suppose I want to display data from a customer table (by name ZTEST) which has 3 fields. I create a context node by name TABLE & add the 3 fields as its children. I now create a 4th attribute under this node (by name say APPROVE) of type WDY_BOOLEAN. (I would be displaying this attribute as a checkbox within my ALV.) I have also given an initial value of false for this attribute. (i.e, just a blank space..) Now I proceed with all the necessary mappings & bindings to display the data in my ALV.

    Now basically I need to performt he below tasks:

    1) Make the last column of my ALV as a checkbox

    2) Place a button on my layout upon pressing which i would want to look out for checked checkboxes. (Basically within this buttons action handler I would call the standard DATA_CHECK method of the ALV which would look out for any changes made to the ALV.)

    3) Create an event handler method for the event ON_DATA_CHECK of the ALV. (If the DATA_CHECK method detects any changes in the data it would raise the event ON_DATA_CHECK. So within our eventhandler method for ON_DATA_CHECK we can obtain the information about the row from which the checkbox was selected & accordingly update our database table)

    Add comment
    10|10000 characters needed characters exceeded

  • May 12, 2009 at 02:56 PM
    Now to first make the last column of my ALV as a checkbox:
    ----------------------------------------------------------
    
    method BUILD_ALV .
      data: l_ref_cmp_usage type ref to if_wd_component_usage.
    
    " Instantiate the ALV usage
      l_ref_cmp_usage =   wd_This->wd_CpUse_My_Alv( ).
    
      if l_ref_cmp_usage->has_active_component( ) is initial.
        l_ref_cmp_usage->create_component( ).
      endif.
    
    " Get reference to the model
      DATA: l_ref_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
      l_ref_INTERFACECONTROLLER =   wd_This->wd_CpIfc_My_Alv( ).
    
      data: lr_config type ref to Cl_Salv_Wd_Config_Table.
    
      lr_config = l_ref_INTERFACECONTROLLER->Get_Model( ).
    
    
    |" Set read only mode to false (and display edit toolbar)
      lr_config->if_salv_wd_table_settings~set_read_only( abap_false ).
    
      data: lr_table_settings type ref to if_salv_wd_table_settings.
      lr_table_settings ?= lr_config.
      lr_table_settings->set_read_only( abap_false ).
    
    
      data: lr_column_settings TYPE REF TO if_salv_wd_column_settings,
            lt_columns         TYPE        salv_wd_t_column_ref,
            lr_checkbox1        TYPE REF TO cl_salv_wd_uie_checkbox,
            lr_checkbox2        TYPE REF TO cl_salv_wd_uie_checkbox.
    
      FIELD-SYMBOLS <fs_column> LIKE LINE OF lt_columns.
    
    
    "  Embed the UI elements within the ALV
      lr_column_settings ?= lr_config.
      lt_columns = lr_column_settings->get_columns( ).
    " Embed an checkbox within the column APPROVE
      LOOP AT lt_columns ASSIGNING <fs_column>.
        CASE <fs_column>-id.
          WHEN 'APPROVE'.
            CREATE OBJECT lr_checkbox1
              EXPORTING
                checked_fieldname = <fs_column>-id.
            <fs_column>-r_column->set_cell_editor( lr_checkbox1 ).
            FREE lr_checkbox1.
        ENDCASE.
      ENDLOOP.
    ENDMETHOD.                    "BUILD_ALV
    Add comment
    10|10000 characters needed characters exceeded

  • May 12, 2009 at 02:57 PM
    Coding inside my buttons action handler:
    ----------------------------------------
    
    method ONACTIONCHECK_ALV_CHECKBOXES .
      DATA: l_ref_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
      l_ref_INTERFACECONTROLLER =   wd_This->wd_CpIfc_My_Alv( ).
      l_ref_INTERFACECONTROLLER->Data_Check( ).
    endmethod.
    Add comment
    10|10000 characters needed characters exceeded

  • May 12, 2009 at 02:57 PM
    Coding inside my event handler method for the event ON_DATA_CHECK of the ALV:
    -----------------------------------------------------------------------------
    
    method ON_DATA_CHECK .
      DATA: lr_node TYPE REF TO if_wd_context_node,
            lr_element TYPE REF TO if_wd_context_element,
            ls_modified_cells TYPE salv_wd_s_table_mod_cell,
            wa_data type wd_this->element_table,
            wd_node type ref to if_wd_context_node.
    
      FIELD-SYMBOLS <temp> TYPE data.
    
      wd_node = wd_context->get_child_node( name = 'TABLE' ).
    
    " get message manager
      DATA lo_api_controller     TYPE REF TO if_wd_controller.
      DATA lo_message_manager    TYPE REF TO if_wd_message_manager.
    
      lo_api_controller ?= wd_this->wd_get_api( ).
    
      CALL METHOD lo_api_controller->get_message_manager
        RECEIVING
          message_manager = lo_message_manager.
    
      lr_node = wd_context->get_child_node( name = 'TABLE' ).
    
      LOOP AT r_param->t_modified_cells INTO ls_modified_cells.
        lr_element = lr_node->get_element( index = ls_modified_cells-index ).
    
        IF ls_modified_cells-attribute = 'APPROVE'.
          wd_node->get_static_attributes( exporting index             = ls_modified_cells-index
                                          importing static_attributes = wa_data ).
    " Finally update the database table from the workarea
    " Here I am updating a customer table by name ZTEST
          modify ztest from wa_data.
          commit work.
        endif.
      endloop.
    endmethod.
    Add comment
    10|10000 characters needed characters exceeded

  • May 12, 2009 at 02:59 PM

    If you perform all these steps you should be able to realize your desired functionality. However keep in mind that the suggested approach of using :

    MODIFY <dbtab> from <wa>

    should be avoided in real time. You would ideally be making use of a BAPI or assistance class for performing the database update. I have just used MODIFY for simplifying the explanation.

    Regards,

    Uday

    Add comment
    10|10000 characters needed characters exceeded