on 05-28-2009 3:51 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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
Hi Pushpraj,
You can directly say as:
wd_context->set_attribute( name = 'ATTR1' value = 'TEST' ).
Regards,
Uday
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.