cancel
Showing results for 
Search instead for 
Did you mean: 

To make table cell as read-only based on some condition

Former Member
0 Kudos

Hello ABAPers,

I have a requirement to make the cell in the table of a Web Dynpro component read-only. There are 4 fields in the Table of a view which is mapped to the Context attribute, i.e. function, Number, Description etc. When the value of the Field 'Function' is

'0000016', I have to make the Number field as READ-ONLY(non-editable).

As suggested in SDN forums, I have created the sub-node to the main node in Context and added an attribute 'READ_ONLY'. I have made the cardinality as 1:1. I have also created the Supply Function Method(ZREADONLY) for sub-node that I have created and also set the context binding to the Read only property of the field 'Number' in the View Layout.

PFB the coding I have done in supply function method for setting the read-only attribute for the number field, but it is not working. Could anyone let me know what is the change I have to make this work?

DATA ls_parent_attributes TYPE wd_this->element_partner_h.

DATA l_partner LIKE ls_parent_attributes-partner _fct

Constants c_parent LIKE ls_parent_attributes-partner_fct VALUE '000016'.

DATA ls_zread_only TYPE wd_this->element_zreadonly

parent_element->get_static_attributes(

IMPORTING

static_attributes = ls_parent_attributes).

CLEAR l_partner.

l_partner = ls_parent_attributes-partner_fct.

IF l_partner = c_partner.

ls_zread_only-readonly = abap_true.

node->bind_structure(

new_item = ls_zread_only

set_initial_elements = abap_true ).

ELSE.

CLEAR ls_zread_only-readonly.

ls_zread_only-readonly = abap_false.

node->bind_structure(

new_item = ls_zread_only

set_initial_elements = abap_false ).

ENDIF.

Thanks for your time!

Regards,

M M Jaffer

Accepted Solutions (1)

Accepted Solutions (1)

Madhu2004
Active Contributor
0 Kudos

HI,

Try this approach:

1) In the node which you are binding to the table create one more attribute as "Variant" type char1.

2) In the Number table column,create 2 cell variants. Right click on first cell variant and insert a input field.Give the variant name as 'I"

3) Right click on second cell variant and insert a textview.Give the variant name as "T".

4) Bind both input field and text view to the number attribute in the node.

5) bind the new attribute i.e."VARIANT" to the "selectcellvariant " property of the number table column.

6) now in the code based on the condition populate VARIANT as I if you need input field and T if you need text view

Regards,

Madhu

Answers (2)

Answers (2)

Former Member
0 Kudos

Dear Friend,

if your table is only read only mode, then add an extra attribute (extra_attribute) in the same context node which of type wdy_boolean,

bind the thevisibility property of table column( whcih u want to make read only based on condition) with the newly added attribute (extra_attribute) of the node.

in the coding place ( in side loop of internal table) based on your requirement make extra_attribute = 'X' or ' '.

and the bind this internal table to table, and in gui side hide the extra_attribute.

it solves your issue!!!

Regards,

Kranthi

Former Member
0 Kudos

hi Mohammed,

Try like this...

create one context attribute in your context node bind it to the table control

context attribute - 'READONLY' of type WDY_BOOLEAN

bind this attribute to the readonly property of the cell editors which you want as read ony.

depending upon your condition for which you want your row as read only, set the value of attribute as readonly.

it will make desirable rows as readonly.

e.g

LOOP AT lt_vbak INTO wa_vbak.

IF wa_vbak-erdat = 'sys-date'.

wa_vbak-readonly = abap_true.

ELSE.

wa_vbak-readonly = abap_false.

ENDIF.

OR you can use CELL_VARIANTS.

go through this...

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

Cheers,

Kris.

Former Member
0 Kudos

Hello Kissnas,

Thanks for your reply. I am trying above code in Supply Method of the new Node created for the context node where the cardinality is set to 1:1. I have declared the readonly attribute of type WDY_BOOLEAN'. Based on the value of one field, I am setting read-only property for the number field. I have used the below 2 methods for setting/ binding read-only.

1. Bind structure

For setting not read-only

node->bind_structure(

new_item = ls_zread_only

set_initial_elements = abap_false ).

For setting Read-only

node->bind_structure(

new_item = ls_zread_only

set_initial_elements = abap_true ).

2. Set attribute:

l_readonly-ronly = abap_true. "Read-only

l_readonly-ronly = abap_false. "Not read-only

lv_read_only->set_attribute(

name = 'RONLY'

value = l_readonly )

Could you tell me, is there any other way with which we can bind the read-only value or any change I have to make for my code since both these does'nt work?

Regards,

M M Jaffer.

Former Member
0 Kudos

Hi,

Based on certain condition you are going to make read only right..

try this,...

If conditon..

set_attribute( read only ).

Cheers,

Kris.

Former Member
0 Kudos

Kris.I have tried the first way.The problem is all the rows of the table for the field are getting either Read-Only or Enabled.

We need only one row to be read-only and the rest as editable. Also kindly suggest me how to set it using set_attribute since I have just started learning web dynpro.

Thanks in Advance!

M M Jaffer.

Former Member
0 Kudos

HI..

Try somthing like this.

DATA : lo_nd_main TYPE REF TO IF_WD_CONTEXT_NODE.
DATA : lo_el_main TYPE REF TO IF_WD_CONTEXT_ELEMENT.

lo_nd_main = wd_context->get_child_node( name = wd_this->wdctx_main )."Name of the node to be passed

lo_el_main = lo_nd_main->GET_ELEMENT( INDEX = 2 )."Provide the index of the row                                                             

lo_el_main->SET_ATTRIBUTE( name = 'RONLY'
                                                 value = l_readonly ).

Thanks,

Aditya.

Former Member
0 Kudos

sorry, that was a posing error

Edited by: Matthias Drescher on Apr 8, 2011 4:56 PM

Former Member
0 Kudos

Hi,

the solution is quite simple.

Bind the property reaonly in the layout editor to the property readonly of the context-attribute.

Therfore you have to click at the binding button of the celleditor of the property read-only.

Then you select the radiobutton in front of Bind to the property of the selected Attribute and choose Property R.

In you coding you have to fo the following in case you do that after binding the itab to the context:


node->bind_table( .... ).

data lt_elements type wdr_context_element_set.

lt_elements = node->get_elements( ).
LOOP at lt_elements into element.
 element->get_attribute(
      exporting
        name = 'PARTNERFCT'
      importing
        value = lv_partnerfct
    ).

  if lv_partnerfct eq c_partner.
    call method lo_el_position->set_attribute_property
      exporting
        attribute_name = 'PARTNERFCT'
        property       = element->e_property-required
        value            = 'X'.
  else.
    call method lo_el_position->set_attribute_property
      exporting
        attribute_name = 'PARTNERFCT'
        property       = element->e_property-read_only
        value            = ''.
  endif.

endloop.

Of corse you have to modify the coding and i didn´t checked the syntax, baut this should help.

Best regards, Matthias

Former Member
0 Kudos

Hello Mohammed,

is your problem solved ?

Best regards, Matthias

Former Member
0 Kudos

Hello All,

Yes ! I have solved my problem. I have used a combination of Supply function method, Variants and read-only attribute

property.

Thanks a lot for the different approaches given to me.

Regards,

M M Jaffer