on 01-12-2011 3:41 AM
I am a newbie to dynpro. From whatever programs i have written till now i have observed that whenever we call functions like GET_ATTRIBUTES or SET_ATTRIBUTES in the following way
1) X -> GET_ATTRIBUTE
......................................
2) CALL METHOD X->SET_ATTRIBUTE
..................................
Now in place of X , if i write the NODE variable name (of type IF_WD_CONTEXT_NODE) or ELEMENT TYPE( by using GET_ELEMENT for a node) it works for both of them.
So what is the difference between the two and which is better to use.I understand that node contains an element which refers to the attributes but in this example I am not able to figure out the difference
THANKS
hi amber,
take a scenario wher eyou have a screen having some input field now those input fields are binded to a node rite?......since they are the input field you must be expecting user to write or enter values in it rite?......so now based on the values he entered you have tto do some calculations .....so you will read that node and when you will read that node you will be using get_attributes.....
similarly at times we have to give some values to a node/attributes by ourselves in the code like if option 1 set node 2 as value = 100 ....for ex...here you will be using the set_attribute....
hope you got what i told ...if needed any further help inform.
thanks and regards,
sahai.s
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks sahai for your answer
I know the difference between get_attribute and set_attribute. What my question was that these methods should be invoked by objects of NODE type or ELEMENT type since they work correctly with both
So i am basically asking the difference between calling these methods through a NODE object and ELEMENT object.
Whats the difference in them and which one is better to use
THanks
hi,
when ever you read or set value for whole node you get that node in the form of an internal table...you can check it using the debugger....so using that internal table for reaching the attributes will be like....*internal_table->attribute_name = _________.
but whenever we read or set value to a particular element in the node we can directly reach the atribute like ..attribute_name = _____.
thanks and regards,
sahai.s
DATA LO_ND_FORM TYPE REF TO IF_WD_CONTEXT_NODE.
DATA LO_EL_FORM TYPE REF TO IF_WD_CONTEXT_ELEMENT.
DATA LS_FORM TYPE WD_THIS->ELEMENT_FORM.
navigate from <CONTEXT> to <FORM> via lead selection*
LO_ND_FORM = WD_CONTEXT->PATH_GET_NODE( PATH = `ND_TREE.FORM` ).
@TODO handle non existant child*
IF lo_nd_form IS INITIAL.*
ENDIF.*
get element via lead selection*
LO_EL_FORM = LO_ND_FORM->GET_ELEMENT( ).
alternative access via index*
lo_el_form = lo_nd_form->get_element( index = 1 ).*
@TODO handle not set lead selection*
IF LO_EL_FORM IS INITIAL.
ENDIF.
get all declared attributes*
LO_EL_FORM->GET_STATIC_ATTRIBUTES(
IMPORTING
STATIC_ATTRIBUTES = LS_FORM ).
so here is the code generated when i read the node ....here when i use debugger and watch for ls_form i will find that it has all the attributes in it....and to reach the attributes i will have to write like...ls_form-aircraft_type = _______.
DATA LO_ND_FORM TYPE REF TO IF_WD_CONTEXT_NODE.
DATA LO_EL_FORM TYPE REF TO IF_WD_CONTEXT_ELEMENT.
DATA LS_FORM TYPE WD_THIS->ELEMENT_FORM.
DATA LV_AIRCARFT_TYPE TYPE WD_THIS->ELEMENT_FORM-AIRCARFT_TYPE.
navigate from <CONTEXT> to <FORM> via lead selection*
LO_ND_FORM = WD_CONTEXT->PATH_GET_NODE( PATH = `ND_TREE.FORM` ).
@TODO handle non existant child*
IF lo_nd_form IS INITIAL.*
ENDIF.*
get element via lead selection*
LO_EL_FORM = LO_ND_FORM->GET_ELEMENT( ).
alternative access via index*
lo_el_form = lo_nd_form->get_element( index = 1 ).*
@TODO handle not set lead selection*
IF LO_EL_FORM IS INITIAL.
ENDIF.
get single attribute*
LO_EL_FORM->GET_ATTRIBUTE(
EXPORTING
NAME = `AIRCARFT_TYPE`
IMPORTING
VALUE = LV_AIRCARFT_TYPE ).
above is the code generated when i read the attribute/element directly...so i will be getting that particular element only this tym and to refer to this i wil have to write only LV_AIRCARFT_TYPE = ___________.
hope you got it now.
thanks and regards,
sahai.s
Just one last question
If both methods r doing the same thing isn't it more convinient to call these methods using by NODE rather than ELEMENT because then we wont have to declare an ELEMENT type in our program and wont hv to use the GET_ELEMENT function.
But i have seen many examples in books and sites they call these methods using ELEMENT rather than NODES directly.SO out of curiosity I am asking the reason.I hope it is not considered a BAD PROGRAMMING PRACTICE to call these functions using NODE directly instead of elements
THANKS
hi,
as far as i know it depends on the requirement for which you are working....if we have to get only one attribute in the node we will go by reading that particular attribute only...whereas if we have to read say 3 to 4 attribute in our code then it will nt be wise to read it one by one...rite? so we will read it by node....
also tell me have you noticed the checkbox "read as atble operation"? which comes when you use code wizard findout the usage of it also.
thanks,
sahai.s
Yea its same,
you can use the node also for getting the element, it wont be considered as bad programming.
but general practise is to go by element method because it make more clear picture that you are fetching the selected element
of the node.
in the node method this element thing becomes little abstracted.
node method is used when you want to read the same attribute for all the elements in a loop.
thanks
sarbjeet singh
hi amber....
there is a diff betwn GET_ATTRIBUTE.....and... GET_STATIC_ATTRIBUTE.....and this can be only noticed incase of INTERFACE NODE(used for passin values from one WDA program to other WDA program)
in this case if u use GET_STATIC_ATTRIBUTE....then u wil notic tht values are not passin...
in such cases GET_ATTRIBUTE wil help u....
bcoz static...points to a memory location which is lost whn next program is called....
if u require more ellaboration kindly let me know
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I guess you are clear with get and set and you are asking the difference between their use with a element and node.
1. Using with element..
when you use get or set attribute with the element then the values for that element you can get and set.
see a node has many element and attribute value for all the elements will be different.
now when you use get_attribute you give parameteres as name of the attribute and value.
so you can see it as one collection of elements and directly you are taking some values from some specific element.
same is the case of set _element.
2. using with the node
then both these mehtods set and get will have one more parameter called index.
by giving the index you can specify which element you want to fetch.
if you donot give any value for the index , lead selection will be used by default.
-
so in a way both are same you are fetching the value of an attribute only but by using node you specifly which element by using the parameter index.
let me know if you still have doubt on this.
thanks
sarbjeet
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi amber,
IInterface F_WD_CONTEXT_NODE enables a single Context Node to be filled or
data to be fetched from a context node.
By declaring this you can access various elements of your context node.
SET_ATTRIBUTE :- This method assignes a value to an individual field of context element.
CALL METHOD ME->SET_ATTRIBUTE
EXPORTING
INDEX = USE_LEAD_SELECTION
NAME =
IMPORTING
VALUE =
.
GET_ATTRIBUTE :- This method used to get the value of an indivisual field of context element.
CALL METHOD ME->SET_ATTRIBUTE
EXPORTING
INDEX = USE_LEAD_SELECTION
NAME =
IMPORTING
VALUE =
.
Go to code wizard ( magic wand ) and there you can find alll the context node and attribute you can use the SET and GET method directly from there. Even you dont have to change the NODE variable name also. The code will be auto generated.
Thanks & Regards,
Monishankar C
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.