cancel
Showing results for 
Search instead for 
Did you mean: 

Enhancing a standard component - Table Cell Variant

former_member184111
Active Contributor
0 Kudos

Hi Forum,

I am trying to enhance the standard WD component /SAPSRM/WDC_UI_SC_DOTC_BD view V_SC_DOTC_BASIC in SRM 7.0 .

The requierment that for certain condition the Quantity cell in a row should be read only.

Carried out the following steps:

1. Created an enhancement

2. In the standard table column ITEMS_TABLE_QUANTITY [Columns] , removed the standard inputfield.

3. Added two cell variants ZITEMS_TABLE_QUANTITY_CV1 [CellVariants] and ZITEMS_TABLE_QUANTITY_CV2 [CellVariants] first one contans a text view and second contains inputfield. Variant key for first one is DISPLAY and for second one is EDITABLE.

4. Enhanced the method WDDOMODIFYVIEW with below code:

**Read the ITEMS table
  DATA lo_nd_items TYPE REF TO if_wd_context_node.
  DATA lt_items TYPE wd_this->elements_items.
  DATA ls_item LIKE LINE OF lt_items.

  DATA lo_el_context TYPE REF TO if_wd_context_element.
  DATA ls_context TYPE wd_this->element_context.
  DATA lv_disable_quantity TYPE wd_this->element_context-enable_quantity.

  DATA lr_table_column TYPE REF TO cl_wd_table_column.
*
** navigate from <CONTEXT> to <ITEMS> via lead selection
  lo_nd_items = wd_context->path_get_node( path = `COMP_CONTEXT.ITEMS` ).
  lo_nd_items->get_static_attributes_table( IMPORTING table = lt_items ).

  lr_table_column ?= view->get_element( 'ITEMS_TABLE_QUANTITY' ).

  LOOP AT lt_items INTO ls_item .
    IF  ls_item-catalogid EQ 'VEP_Staples_D0'.
      lr_table_column->set_selected_cell_variant( value = 'DISPLAY' ).
    ELSE.
      lr_table_column->set_selected_cell_variant( value = 'EDITABLE' ).
    ENDIF.
  ENDLOOP.

But even after the condition is true ALL cell i.e. the complete column is DISABLED or when the condition is false the COMPLETE column is enabled instead of enabling disabling ONLY THE SPECIFIC CELL.

Is there a problem with the code in WDDOMODIFYVIEW or something else?

Thanks,

Anubhav

Accepted Solutions (1)

Accepted Solutions (1)

saravanan_narayanan
Active Contributor
0 Kudos

the Enable_quantity attribute should be part of the COMP_CONTEXT.ITEMS context node.

and for each item, this Enable_quantity should be set to abap_true or abap_false based on catalogid.

or the same can be achieved by cell variant.

create an attribute in node COMP_CONTEXT.ITEMS by name CELL_VARIANT.

loop at catalog_items and set the CELL_VARIANT value to either 'DISPLAY' or 'EDITABLE'.

and finally the CELL_VARIANT attribute in COMP_CONTEXT.ITEMS node should be bound to the selectedCellVariant property of the table column.

both the options will work.

BR, Saravanan

former_member184111
Active Contributor
0 Kudos

Hi Saravanan

Under ITEMS node I added one more Node(cv_quantity) and one attribute(cell_variant_quantity) with in this node.

And code in WDDOMODIFYVIEW :

DATA lo_nd_items TYPE REF TO if_wd_context_node.
  DATA lt_items TYPE wd_this->elements_items.
  DATA ls_item LIKE LINE OF lt_items.

  DATA lo_el_context TYPE REF TO if_wd_context_element.
  DATA ls_context TYPE wd_this->element_context.


  DATA lr_table_column TYPE REF TO cl_wd_table_column.
*
** navigate from <CONTEXT> to <ITEMS> via lead selection
  lo_nd_items = wd_context->path_get_node( path = `COMP_CONTEXT.ITEMS` ).
  lo_nd_items->get_static_attributes_table( IMPORTING table = lt_items ).

  lr_table_column ?= view->get_element( 'ITEMS_TABLE_QUANTITY' ).

  DATA lo_nd_cv_quantity TYPE REF TO if_wd_context_node.
  DATA lo_el_cv_quantity TYPE REF TO if_wd_context_element.
  DATA ls_cv_quantity TYPE wd_this->element_cv_quantity.


IF first_time EQ abap_true.
  lr_table_column->set_selected_cell_variant( value = 'EDITABLE' ).<--Initially ALL cells shoud be editable

ELSE.
  lr_table_column->bind_selected_cell_variant( path = 'COMP_CONTEXT.ITEMS.CV_QUANTITY.CELL_VARIANT_QUANTITY' )  .
* navigate from <CONTEXT> to <CV_QUANTITY> via lead selection
  lo_nd_cv_quantity = wd_context->path_get_node( path = `COMP_CONTEXT.ITEMS.CV_QUANTITY` ).
  IF lo_nd_cv_quantity is BOUND.

  lo_el_cv_quantity = lo_nd_cv_quantity->get_element( ).

      LOOP AT lt_items INTO ls_item .
        IF  ls_item-catalogid EQ 'VEP_Staples_D0' AND ls_item-number_int IS NOT INITIAL AND ls_item-description IS NOT INITIAL. 
          lo_el_cv_quantity->set_attribute(
                                            name =  `CELL_VARIANT_QUANTITY`
                                            value = 'DISPLAY' ).
        ELSEIF ls_item-catalogid NE 'VEP_Staples_D0' OR ( ls_item-number_int  IS INITIAL AND ls_item-description IS INITIAL ) ."If the condition is not satisfied OR no item is added to that line
          lo_el_cv_quantity->set_attribute(
                                            name =  `CELL_VARIANT_QUANTITY`
                                            value = 'EDITABLE' ).
        ENDIF.
      ENDLOOP.

ENDIF.
ENDIF.

Now If I add an item that DO NOT satisfy the comdition to be read only, for that row the quantity is enabled but for all the rows below it quantity cells are DISABLED.

Hope my issue is clear?

Thanks a lot,

Anubhav

saravanan_narayanan
Active Contributor
0 Kudos

since the cv_quantity is under the ITEMS node you need to set the value of cell_variant_quantity for each item..

please change your code like this and check.

data: lo_el_item type ref to if_wd_context_element,
         lv_item_index  type i.


LOOP AT lt_items INTO ls_item .

        lv_index = sy-tabix.
        lo_el_item = lo_nd_items->get_element( lv_index ).
        lo_nd_cv_quantity = lo_el_item->get_child_node( 'CV_QUANTITY' ).
        lo_el_cv_quantity = lo_nd_cv_quantity->get_element( ).
        
        IF  ls_item-catalogid EQ 'VEP_Staples_D0' AND ls_item-number_int IS NOT INITIAL AND ls_item-description IS NOT INITIAL. 
          lo_el_cv_quantity->set_attribute(
                                            name =  `CELL_VARIANT_QUANTITY`
                                            value = 'DISPLAY' ).
        ELSEIF ls_item-catalogid NE 'VEP_Staples_D0' OR ( ls_item-number_int  IS INITIAL AND ls_item-description IS INITIAL ) ."If the condition is not satisfied OR no item is added to that line
          lo_el_cv_quantity->set_attribute(
                                            name =  `CELL_VARIANT_QUANTITY`
                                            value = 'EDITABLE' ).
        ENDIF.
ENDLOOP.

hope this helps.

BR, Saravanan

former_member184111
Active Contributor
0 Kudos

HI Saravanan,

That fixed the issue. Thanks a ton for help.

Just a FYI...I also tried creating a node and attribute under the ITEMS node and binding it to the read only property of the input field in table column but could not make it work. I will try again with the modifications you said in the last reply and update the thread.

Thanks Again,

Anubhav

Answers (1)

Answers (1)

Former Member
0 Kudos

Test this out -

LOOP AT lt_items INTO ls_item .
    IF  ls_item-catalogid EQ 'VEP_Staples_D0'.
      lr_table_column->set_selected_cell_variant( value = 'TEXT_VIEW' ).  "Chnage
    ELSE.
      lr_table_column->set_selected_cell_variant( value = 'INPUT_FIELD' ). "Change
    ENDIF.
  ENDLOOP.

or

Why have you removed the Input field and added two other variants..

You can do this way right...

Create a context attribute of type READ_ONLY programatically and bind the INPUT FIELD READ_ONLY property to this ATTRIBUTE..

As per the condition you can enable or disable that cell right...

Will you requirement be set using this...

Edited by: Lekha on Jul 6, 2011 12:43 PM

former_member184111
Active Contributor
0 Kudos

Hi Lekha,

I removed the cell variants and added the standard input field in table column. Also added a context attribute of type WDY_BOOLEAN and below code in WDDOMODIFYVIEW:

DATA qty_ip TYPE REF TO cl_wd_input_field.

  qty_ip ?= view->get_element( 'ITEMS_TABLE_QUANTITY_EDITOR' ).

  qty_ip->bind_read_only( path = 'ENABLE_QUANTITY' ).

 LOOP AT lt_items INTO ls_item .
    IF  ls_item-catalogid EQ 'VEP_Staples_D0'.
      lo_el_context->set_attribute(
                                    name =  `ENABLE_QUANTITY`
                                    value = abap_true ).
    ELSE.
      lo_el_context->set_attribute(
                                    name =  `ENABLE_QUANTITY`
                                    value = abap_false ).
    ENDIF.
  ENDLOOP.

But still the result is same as before, complete column is enabled or disabled instead of specific cells.

I think for controlling individual cells the only option is cell variants.

Check [this thread|] , it talks about the same issue.

Thanks for the reply,

Anubhav

former_member199125
Active Contributor
0 Kudos

Hi Anubhav,

cell controlling is possible only through cell variants only, and use the below link , it will help you in understanding cell variant concepts.

http://wiki.sdn.sap.com/wiki/display/WDABAP/WebDynproforABAPCellVariants

And if you bind wdy_boolean attribute to column readonly property, it means that you are operating for entire column not single cell. So you have to go for cell variants only.

And in cell variants bing the above wdy_boolean attribute to readonly property of inputfield .

then it will solve.

Regards

Srinivas

Former Member
0 Kudos

Have you changed the code in the LOOP as stated in my previous thread..