cancel
Showing results for 
Search instead for 
Did you mean: 

Check box in alv grid

Former Member
0 Kudos

Hai All,

I have created one AVL grid in that i want to display check box. how to add check box in alv grid .

Please help me.

Regards,

Arun

Accepted Solutions (0)

Answers (3)

Answers (3)

uday_gubbala2
Active Contributor
0 Kudos

Hi Arun,

You can try go through this [blog |https://wiki.sdn.sap.com/wiki/display/Snippets/Web%20Dynpro%20ABAP%20-%20Using%20UI%20elements%20in%20ALV%20component%20cells]by David within which he explains as to how you can embed an checkbox, image & LinkToAction within the cells of the ALV. This should help resolve your problem.

Regards,

Uday

Former Member
0 Kudos

Thanks,

Its working,

In that ALV Grid i insert one row using append button. I want to get the data from that row and insert in the data base.

how to do that? Could you please tell me .

Regards,

Arun

Former Member
0 Kudos

You want the contents of the entire table or only of the row that was newly inserted ????

Regards,

Radhika.

uday_gubbala2
Active Contributor
0 Kudos

Hello Arun,

You can obtain the information corresponding to that row by using the GET_STATIC_ATTRIBUTES method. Just pass in the index of your newly added row & you would be able to fetch the data into a structure variable. Now you can use this structure to update on to your database using an approach of your choise. If you are wondering as to how you can get the index of your newly appended row then you can try do it as follows. Do an GET_ELEMENT_COUNT up on the context node which is bound to your ALV. The count of total number of elements would correspond to the index of your ALV's last row.

However if you intend to read the entire table UI element and then save it on to your database then you can make use of the GET_STATIC_ATTRIBUTES_TABLE method to read the entire tables data into an internal table. So now you can use this internal table along with your database updation logic.

However a word of caution here.... SAP doesn't ever recommend directly modifying the database through an SQL query. You would preferably make use of a BAPI for updating your database. Try go through Thomas Jung's comments in [here|;.

Regards,

Uday

uday_gubbala2
Active Contributor
0 Kudos
" Get reference to model
  lr_if_controller = wd_this->wd_cpifc_cmp_alv( ).
  lr_config        = lr_if_controller->get_model( ).

" Get references of all the ALV columns
  lr_column_settings ?= lr_config.
  lt_columns = lr_column_settings->get_columns( ).

" Loop through the columns & change the cell editors of the columns accordingly
" In this example I want to change the cell editor for more than 1 column because of which
" I am obtaining the references of all columsn & then looping through them
" If you intend to change the cell editor of just 1 column then you can get the reference of just that column
" using GET_COLUMN & directly change its cell editor to the desired UI element using SET_CELL_EDITOR( )
  LOOP AT lt_columns ASSIGNING <fs_column>.
    CASE <fs_column>-id.
      WHEN 'BOOKINGID'.
        CREATE OBJECT lr_link.
        lr_link->set_text_fieldname( <fs_column>-id ).
        <fs_column>-r_column->set_cell_editor( lr_link ).
      WHEN 'RESERVED'.
        CREATE OBJECT lr_checkbox
          EXPORTING
            checked_fieldname = <fs_column>-id.
        <fs_column>-r_column->set_cell_editor( lr_checkbox ).
        FREE lr_checkbox.
      WHEN 'CANCELLED'.
        CREATE OBJECT lr_image.
        lr_image->set_source_fieldname( <fs_column>-id ).
        <fs_column>-r_column->set_cell_editor( lr_image ).
        FREE lr_image.
    ENDCASE.
  ENDLOOP.
ENDMETHOD.
uday_gubbala2
Active Contributor
0 Kudos

Hi Arun,

If you intend to embed a checkbox within the cells of the ALV then you need to perform the below tasks:

1) Obtain the reference of the desired column within which you want to embed the checkbox.

2) Create an object of the checkbox class & fetch its reference into a local reference variable.

3) Change the cell editor of the desired column to a checkbox.

METHOD build_alv.
  DATA:
    lr_alv_usage       TYPE REF TO if_wd_component_usage,
    lr_if_controller   TYPE REF TO iwci_salv_wd_table,
    lr_config          TYPE REF TO cl_salv_wd_config_table,
    lr_column_settings TYPE REF TO if_salv_wd_column_settings,
    lt_columns         TYPE        salv_wd_t_column_ref,
    lr_link            TYPE REF TO cl_salv_wd_uie_link_to_action,
    lr_checkbox        TYPE REF TO cl_salv_wd_uie_checkbox,
    lr_image           type ref to cl_salv_wd_uie_image.
  FIELD-SYMBOLS
    <fs_column> LIKE LINE OF lt_columns.

" Instantiate the ALV Component
  lr_alv_usage = wd_this->wd_cpuse_cmp_alv( ).
  IF lr_alv_usage->has_active_component( ) IS INITIAL.
    lr_alv_usage->create_component( ).
  ENDIF.