cancel
Showing results for 
Search instead for 
Did you mean: 

Developing a calculator

Former Member
0 Kudos

Dear Experts

I'm new in abap webdynpro. For a school project, I want to create a simple BMI (Body Mass Index) Calculator in a webdynpro. For calculating the index, i need to read in the weight and height of the person. Now my problem: I couldn't figure out how to do that. I made a view with an input field on it. But I'm only able to read in strings. I can't calculate with strings. If i use the datatype F, it says that this type isn't supported by the input field. So my first question: How can I read in numbers?

Then for the calculation: Where am I going to do that? In a method? I mean, if I would be able to read in e.g. the weight, where is this value then? In which variable will it be stored in?

So long, I made it to read in a string on a first view and then, on a second view, showing this string after clicking a button on the first view. But I have no clue how to do this with a number.

In the end it should be possible to fill in weight, height and choosing the gender by a radio button. After that, the user will click on a submit button and the webdynpro will calculate it's BMI. On a second view, it will show the result and a message about it.

I hope, someone could help me. I tried now for nearly 6 hours with no success

Kind regards from Switzerland

Michael Schmid

Accepted Solutions (1)

Accepted Solutions (1)

former_member186750
Contributor
0 Kudos

Gruetzi Michael,

Please could you ask any further questions you may have in a new thread.

Please also bare in mind that only one question per thread is allowed per the forum rules.

Please don't let this put you off from asking questions though.

Cheers,

Neil.

Former Member
0 Kudos

Hello

Ok, sorry, I didn't notice that. I thought it would be clearer to keep all in one thread.

Thanks for that info. I will start a new thread.

Regards

Michael

Answers (2)

Answers (2)

Former Member
0 Kudos

Dear Experts

I have a new question.

Please see edited post above.

Thank you.

Kind Regards

Michael

Edited by: drum4zirrus on Nov 8, 2010 4:07 PM

ChrisPaine
Active Contributor
0 Kudos

Dear Michael,

if you have a read of the SCN Forum rules of engagement you see that we ask forum user to restrict each thread to a single question.

You should ideally mark this thread as closed, thank Thomas again for his great patience and huge amount of online eLearnings and then post a new thread with your new question.

Hopefully, then some people will come to help you - if you question isn't one where the answer can be found by searching through SCN

Cheers,

Chris

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>So my first question: How can I read in numbers?

Use type I (Integer). You shouldn't need the percision of Float anyway. Are you working with whole numbers only? If so Integer should work. Otherwise a decimal data type would work.

>In which variable will it be stored in?

Its stored in the context. Use the Context APIs to read the values back into normal ABAP variables. All of this would genearlly append in an ABAP method that is the event handler for one of the UI actions (like a button press).

These are extremely basic questions. You should perhaps consider starting by running through some of the beginners tutorials or eLearnings that are available here on SCN for Web Dynpro. They will teach you some of the basics of things like the Context.

Former Member
0 Kudos

Hello Thomas

Thanks a lot for your quick reply. I know, those questions were basic, but somehow I overlooked the datatype 'I' and I got stuck with this.

I also didn't notice your grate tutorials. I'll watch them now.

I may have to come back when I'll stuck in the method's for the calculation, but for now, my question is answered.

Thank You

Kind Regards

Michael

EDIT:

As I allready thougt I have now another question:

After watching your tutorials for beginners, 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 your tutorials. I heard something of binding the element with a method, but I have no idea how to do that.

    
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.

Kind Regards

Michael

Edited by: drum4zirrus on Nov 8, 2010 3:40 PM