Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

convert string to arithmatic expression

Former Member
0 Likes
807

Dear Gurus,

Is there any function module that can convert a string containing Formula into arithmatic expression?

example :

if I have string "( A + B ) * 100"

and

A = 1

B = 2

so that by entering both A and B value, I can get the result of 300 .

Thanks and Regards,

William Prawira

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
783

Dear Valter Oliveira.

Thanks for the reply.

It could be done using that, but since there are a lot of formulas, and they are really complex, I'm thinking of creating a table to store those formulas, and then read it using the formula.

Hoping to save time if in the near future, i need to change the formula, I don't need to change the form.

Regards,

William Prawira.

5 REPLIES 5
Read only

valter_oliveira
Active Contributor
0 Likes
783

Hello.

For that you don't need a FM.


FORM f_formula USING a TYPE i b TYPE i CHANGING res TYPE i.
  res = ( a + b ) * 100.
ENDFORM.
PERFORM f_formula USING var1 var2 CHANGING result.

Regards.

Valter Oliveira.

Read only

Former Member
0 Likes
784

Dear Valter Oliveira.

Thanks for the reply.

It could be done using that, but since there are a lot of formulas, and they are really complex, I'm thinking of creating a table to store those formulas, and then read it using the formula.

Hoping to save time if in the near future, i need to change the formula, I don't need to change the form.

Regards,

William Prawira.

Read only

0 Likes
783

reading the formula from the table will be very tricky...

as You'll need your field values i.e. A and B's values in following g format...

Itab-fld_name = 'A'

itab-fld_val = '1'

in this case.. you can read the string from the custom table and then divide it into

fld1 operator fld2...

and then crosscheck these values with the itab values...

and perform arithmetic function specified by operator.. which you need to compare manually...

e.g.

string = 'A + B'

itab-fld_name itab-fld_val

A 1

B 2

after segregating the screen

fld1 = 'A'

operator = '+'

fld2 = 'B'

now take the values of these fields from itab

and do the calculation

*this logic will work if all your formulates are of fixed format

Read only

0 Likes
783

check if FIMA_FORMULA_CREATE helps you

Read only

Former Member
0 Likes
783

Dear Sharayu Kumatkar ,

Thanks. I think I can use this.

just need to try using it ^^.

Regards,

William Prawira.