cancel
Showing results for 
Search instead for 
Did you mean: 

mathematical operation search help

Former Member
0 Kudos

Hello Experts,

I am currently developing a calculator. With great helps and support of SAP Mentor Thomas Jung.

I get the numbers displayed in the display. But it is not possible to perform

mathematical operation like multiplicating or dividing etc.

How can I implement this part in the below method or generally ?

Thx a lot in advance.

method ONACTIONBUTTONPRESS .


  DATA lo_nd_calculator TYPE REF TO if_wd_context_node.
  DATA lo_el_calculator TYPE REF TO if_wd_context_element.
  data lr_value type ref to data.
  data l_string type c LENGTH 60.
  data: val type string.



  lo_nd_calculator = wd_context->get_child_node( name = wd_this->wdctx_calculator ).
  lo_el_calculator = lo_nd_calculator->get_element( ).


  lr_value = lo_el_calculator->get_attribute_ref( WD_COMP_CONTROLLER->value_help_listener->f4_attribute_info-name ).
  FIELD-SYMBOLS <wa_numeric> type numeric.
  ASSIGN lr_value->* to <wa_numeric>.
  val = wdevent->GET_string( 'ID' ).

  CASE val.
    WHEN 'BTN_1'.
      move <wa_numeric> to l_string.
      CONCATENATE l_string `1` into l_string. CONDENSE l_string NO-GAPS.
      <wa_numeric> = l_string.
      lo_el_calculator->set_attribute(
        EXPORTING
          value = <wa_numeric>
          name  = WD_COMP_CONTROLLER->value_help_listener->f4_attribute_info-name ).
.....

Regards

ertas

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

thanks a lot.

The problem is when someone e.g. wants add 45 to 95 by the calculator.

How can I store the first value 45 and second value 95 seperately since he will klick between these

steps the button for addition.

I am concatenating the first value unless he klicks any aritmethic button and afterwards I must continue

concatenate while he did not klick the button for =l or + in order to perform the addtion.

Did you understand what I have ment

Regards

ertas ilhan

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Whenever someone presses one of the arithmetic buttons, you just need to store the current value of the calculation field in a component attribute and store which aritehmetic operation they want to perform in a component attribute. You are storing it away into global memory of your component. That way the next number they press can build the second operand in your calculation. When they press the equals button you can perform operation they wanted with the currently displayed operand and the one stored in memory.

Answers (1)

Answers (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

ABAP has all the key words you would need to perform mathimatical operations. Lookup the documentation on the keyword COMPUTE.

You can use the keywork COMPUTE like this:

COMPUTE var1 = 2 + 3.

Or you can use the short form of Arithmetic expression directly (more common):

var1 = 2 + 3.

For basic operations we have +, -, *, /, DIV, MOD, **

For more complex calucations ABAP also has Mathematical functions built in: abs, sign, ceil, floor, trunc, frac, acos, asin, atan, cos, sin, tan, cosh, sinh, tanh, exp, log, log10, sqrt.