cancel
Showing results for 
Search instead for 
Did you mean: 

how to add dynamic checkbox to the dynamically created alv table.

former_member190689
Contributor
0 Kudos

Hello Gurus,

     

           I have created a dynamic alv table.Now due to some requirement I have to add a column for checkbox where user clicks on that checkbox and hit the button save then the complete row goes to the master table.Now my problem is how to add checkbox column to my dynamic created alv.Also when the user checks how can the data be saved in master table or internal table.

below is the code

wddoinit:

DATA lo_nd_change_number TYPE REF TO if_wd_context_node.

   DATA lt_change_number TYPE wd_this->Elements_change_number.

   DATA wa_change_number TYPE wd_this->Element_change_number.

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

   lo_nd_change_number = wd_context->get_child_node( name = wd_this->wdctx_change_number ).

* @TODO handle non existant child

* IF lo_nd_change_number IS INITIAL.

* ENDIF.

   lo_nd_change_number->get_static_attributes_table( importing table = lt_change_number ).

   CLEAR lt_change_number.

   wa_change_number-change_doc_no = '1'.

   APPEND wa_change_number To lt_change_number.

   lo_nd_change_number->bind_table( new_items = lt_change_number

                             set_initial_elements = abap_true ).

on_submit:-

DATA lo_nd_change_number TYPE REF TO if_wd_context_node.

   DATA lo_el_change_number TYPE REF TO if_wd_context_element.

   DATA ls_change_number TYPE wd_this->Element_change_number.

   DATA lv_change_doc_no TYPE wd_this->Element_change_number-change_doc_no.

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

   lo_nd_change_number = wd_context->get_child_node( name = wd_this->wdctx_change_number ).

* get element via lead selection

   lo_el_change_number = lo_nd_change_number->get_element( ).

* @TODO handle not set lead selection

   IF lo_el_change_number IS INITIAL.

   ENDIF.

   DATA cnt TYPE i.

   cnt = '1'.

* get single attribute

   lo_el_change_number->get_attribute(

     EXPORTING

       name =  `CHANGE_DOC_NO`

     IMPORTING

       value = lv_change_doc_no ).

   DATA lo_nd_ztable TYPE REF TO if_wd_context_node.

   DATA lt_ztable TYPE wd_this->Elements_ztable.

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

   lo_nd_ztable = wd_context->get_child_node( name = wd_this->wdctx_ztable ).

   lo_nd_ztable->get_static_attributes_table( importing table = lt_ztable ).

   IF sy-subrc IS INITIAL.

     SHIFT lv_change_doc_no LEFT DELETING LEADING '0'.

     select  * from zmaterial_descp INTO TABLE lt_ztable WHERE change_doc_no = lv_change_doc_no.

   ENDIF.

   lo_nd_ztable->bind_table( new_items = lt_ztable

                             set_initial_elements = abap_true ).

Now above code what I have written could you please tell where I should write the code for my Checkbox.If have gone thro a reference and it helped me to create checkbox dynamically but outside the alv table so please guide me in this

Thanks in advance

Gaurav Gautam

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Gaurav,

Please check the below code :

Check the below code....To make cell edit, check box and add image.

For check box create the node attribute as boolean i.e.,WDY_BOOLEAN for check box

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.

* Get reference to model

  lr_if_controller = wd_this->wd_cpifc_cmp_alv( ).

  lr_config        = lr_if_controller->get_model( ).

* Set the UI elements.

  lr_column_settings ?= lr_config.

  lt_columns = lr_column_settings->get_columns( ).

  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'.   " Ur Column name

        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.

I hoep this will help you.

Regards,

Nsingh

Answers (1)

Answers (1)

0 Kudos

Hi Gaurav,

You can use the class CL_SALV_WD_UIE_CHECKBOX to add the check box to the ALV.

For this you would have to have a field for the checkbox value in the structure of the ztabe that you are binding.

May I suggest, keep the ZTABLE seperate from the binding table, instead use structures to bind in the context as it allows facility to further extend the application.

Cheers,

Nihar

former_member190689
Contributor
0 Kudos

Hi Nihar,

    Could you please tell me in detail as how to use this class.Also will it work for dynamic alv.As my requirement is to show the ztable from a reference number.So i created a dynamic alv but now I have to add a checkbox column to that alv.Also when some1 checks then the data should be saved in the other table say master table or internal table.

Thanks

Gaurav Gautam