cancel
Showing results for 
Search instead for 
Did you mean: 

Setting value of Context Attribute

Former Member
0 Kudos

Hi

New to Web Dynpros.

I have an attribute in my View (not under any node and of TYPE string).

I need to set its value in a method.

How to go about it?

I've tried set_attribute but it gives the error NULL reference.

Pushpraj

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

try with following code:

data lo_el_context type ref to if_wd_context_element.

lo_el_context = wd_context->get_element( ).

lo_el_element->set_attribute(

exporting

name = 'CITY'

value = 'DELHI'

).

Thanks,

Rahul

Answers (2)

Answers (2)

arjun_thakur
Active Contributor
0 Kudos

Hi,

Try using the help of code wizard (Ctrl+F7) to set the value in an attribute. The code will look like the one given in the earlier posts.

I hope it helps.

Regards

Arjun

Former Member
0 Kudos

Hi guys

problem solved thanks.

Hi Arjun

I did try using code wizard but all that I could see was Read Context and not 'Write Context'.

Could you specify?

Pushpraj

arjun_thakur
Active Contributor
0 Kudos

Hi,

If your code wizard generates the code for attribute then, simply use that code and make 2 changes as following:

1) in the code instead of get_attribute use set_attribute

2) simply remove the IMPORTING word. and in the value parameter, just pass the value that you want to set in that attribute.


  lo_el_node1->get_attribute( " change get to set
    EXPORTING
      name =  `TIME`
    IMPORTING " remove importing word
      value = lv_time "pass the value
 ).

Regards

Arjun

uday_gubbala2
Active Contributor
0 Kudos

Hi Pushpraj,

You just have to use the read context method. The system would then generate an get_attribute method saying as exporting name = ... and importing value =...

You would have to just change it to set_attribute from get_attribute and remove the importing type. So you would end up with something like:

" Code generated from wizard
wd_context->get_attribute exporting name  = 'NAME'
                                        mporting value  = lv_val.

" Code after you have modified
wd_context->set_attribute exporting name = 'NAME'
                                                     value = lv_val.

Hope this is clear for you now.

Regards,

Uday

Former Member
0 Kudos

Hi

one doubt

this

wd_context->set_attribute( name = 'MESSAGE' value = lv_message ).

works (no need to specify IMPORTING EXPORTING)

but this

wd_context->get_attribute( name = 'RADIO' value = lv_radio ).

doesn't (asks for IMPORTING)

Why?

Pushpraj

uday_gubbala2
Active Contributor
0 Kudos

Hi Pushpraj,

Well this is a simple thing. When you say set_attribute you are trying to assign a value to an context attribute. So you need to tell the system the name of the attribute (through exporting name) & the value with which you want to initialize (through exporting value). Hence you have these 2 exporting parameters.

But when you say get_attribute you want to read the value present in a context attribute. So you tell the system (through exporting name) what attributes value you want and into which variable (through importing value) you want the read value to be placed in.

Hope its clearer now.

Regards,

Uday

Former Member
0 Kudos

Hi Uday

ok so because set_attribute has both the parameters on export so no need to specify. But get_attribute has one to export and the other to import so we need to specify. Right?

But then shouldn't the system understand that we are going to export the name and import the value in get_attribute? I mean it's not like we'd export the value and expect it to return an attribute name.

Pushpraj

uday_gubbala2
Active Contributor
0 Kudos

Hi Pushpraj,

You can directly say as:

wd_context->set_attribute( name = 'ATTR1' value = 'TEST' ).

Regards,

Uday