cancel
Showing results for 
Search instead for 
Did you mean: 

Setting a value back to a node

Former Member
0 Kudos

Dear Experts

My goal is to develop a BMI calculator. After watching the great tutorials from Thomas Jung, things are much clearer now. Thanks for those tutorials, Thomas.

Now, I made a context node 'INPUT' with the attributes 'WEIGHT' and 'HEIGHT' in it and another node 'OUTPUT' with a attribute called 'RESULT'.

Then I set up a ACTION named 'calc' who is assigned to the button 'calc BMI' This action triggers a method named 'ONACTIONCALC'. In this method I used the wizzard to read the attributes 'WEIGHT' and 'HEIGHT' from the node 'INPUT'. Then I did the calculation in the same method (see code below). Now I have the following problem:

How can I set the value which is stored in 'RESULT' to the attribute 'RESULT' in the 'OUTPUT' node? Unfortunately, my SAPGUI doesn't support an 'set' wizzard as in Thomas tutorials. I heard something of binding the element with a method, but I have no idea how to do that. In the tutorials, Thomas is setting more than one value back in a table. My goal is only to set one value back in one attribute called 'RESULT'. I've been searching the forum, but somehow I didn't get the answers I was looking for.



method ONACTIONCALC .
 
  DATA lo_nd_input TYPE REF TO if_wd_context_node.
  DATA lo_el_input TYPE REF TO if_wd_context_element.
  DATA ls_input TYPE wd_this->element_input.
  DATA lv_weight LIKE ls_input-weight.
* navigate from <CONTEXT> to <INPUT> via lead selection
  lo_nd_input = wd_context->get_child_node( name = wd_this->wdctx_input ).
 
* get element via lead selection
  lo_el_input = lo_nd_input->get_element(  ).
 
* get single attribute
  lo_el_input->get_attribute(
    EXPORTING
      name =  `WEIGHT`
    IMPORTING
      value = lv_weight ).
 
  DATA lv_height LIKE ls_input-height.
* navigate from <CONTEXT> to <INPUT> via lead selection
  lo_nd_input = wd_context->get_child_node( name = wd_this->wdctx_input ).
 
* get element via lead selection
  lo_el_input = lo_nd_input->get_element(  ).
 
* get single attribute
  lo_el_input->get_attribute(
    EXPORTING
      name =  `HEIGHT`
    IMPORTING
      value = lv_height ).
 
****CALCULATE******
 
DATA result TYPE i.
DATA tempw TYPE i.
DATA temph TYPE i.
 
tempw = lv_weight * 10000.
temph = lv_height * lv_height.
 
result = tempw / temph.
 
*******OUTPUT******

??
 
endmethod.

Thank you in advance for helping me

Kind Regards

Michael Schmid

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

you can use the code generator Ctrl + F7 to get the result attribute. Use the same Ctrl + F7 to set the Result attribute from Result node.

Former Member
0 Kudos

Hi

OK, but in my SAPGUI for JAVA (I use a mac) there is no option to actually SET a value back. I'm able to use Win XP, so can you tell me which Version you use? As far as I know, the Netweaver 7.02 Thomas uses in his tutorials isn't yet available for public users?

Greetings

Michael

Former Member
0 Kudos

Hi,

it is available in 7.01.

Considering you want to read result attribute from OUTPUT node and to set result attribute from RESULT node, the code should be something like this.

i assume the OUTPUT and RESULT nodes are direct child of the root node (CONTEXT).

DATA lo_nd_output TYPE REF TO if_wd_context_node.
  DATA lo_el_output TYPE REF TO if_wd_context_element.
  DATA lv_result TYPE wd_this->element_output-result.
  DATA lo_nd_result TYPE REF TO if_wd_context_node.
  DATA lo_el_result TYPE REF TO if_wd_context_element.


*  Output node
  lo_nd_output = wd_context->get_child_node( name = wd_this->wdctx_output ).
*   get element via lead selection
  lo_el_output = lo_nd_output->get_element( ).
*   get single attribute
  lo_el_output->get_attribute(
    EXPORTING
      name =  `RESULT`
    IMPORTING
      value = lv_result ).

*   Result node
  lo_nd_result = wd_context->get_child_node( name = wd_this->wdctx_result ).
*   get element via lead selection
  lo_el_result = lo_nd_result->get_element( ).
*   get single attribute
  lo_el_result->set_attribute(
    EXPORTING
      name =  `RESULT`
      value = lv_result ).

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

The extension to the Wizards to support SET and table operations has nothing to do with your SAPGUI type or version. This is functionality of the backend. The wizards were extended in NetWeaver 7.0 Enhancement Package 1. I assume if you don't have them, then you are on 7.0. You can still acomplish the same thing, you just don't have wizards to write the code for you. I suggest that you invest some time in learning the Context APIs regardless. The wizards are a time saver, not an excuse not to learn the underlying APIs.

http://help.sap.com/saphelp_nw70ehp1/helpdata/en/43/9f02d3e1062883e10000000a422035/frameset.htm

Former Member
0 Kudos

Hello Guys

Thank you so much for your suggestions. I now made it work.

Thanks for the API-Link, Thomas. I know, working with a wizzard is not "the true way". But in school we just scratched the surface of abap. And I know from JAVA that it takes much time to get into a new language. But the API is very useful.

Regards

Michael

Answers (0)