on ‎2011 Jan 12 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
Request clarification before answering.
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
| User | Count |
|---|---|
| 8 | |
| 7 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.