‎2008 Jul 11 9:46 AM
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
‎2008 Jul 11 10:45 AM
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.
‎2008 Jul 11 9:56 AM
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.
‎2008 Jul 11 10:45 AM
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.
‎2008 Jul 11 11:01 AM
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
‎2008 Jul 11 11:06 AM
‎2008 Jul 11 11:24 AM
Dear Sharayu Kumatkar ,
Thanks. I think I can use this.
just need to try using it ^^.
Regards,
William Prawira.