Application Development 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: 

How to calculate the result of a string-based formula?

Former Member
0 Kudos

Hello,

I am wondering, if it might be possible to calculate the result of a formula stored in an string.

Two quick examples:

1.) The text in the formula-string might be: "2 * 2 + 2"

2.) The text in the formula-string might be: "( 2 + 2 * ( 2 + 2 ) )"

The first example can be solved by splitting the elements and calculate the result with some if-else-endif statements...this will just work, because the multiplication is located before the addition.

Such a simple (dumb) logic won't work for the second one, because things must be calculated in a different order to get the right result.

Is there a abap-functions that is able to convert such strings into "real" formulas or - even better - anything that passes the result back to me?

I was able to solve the issue within Excel by using the "evaluate" function...

Thanks in advance,

Chris

1 ACCEPTED SOLUTION

dev_parbutteea
Active Contributor
0 Kudos

Hi,

Actually there is a function module for your purpose:

CS_QU_EVALUATE_FORMULA

send the formula without brackets and set the field I_ROMEI.

I tried to run it from se37, it worked.

Revert back in case of questions,

Reward if this helps you,

Regards,

Sooness.

4 REPLIES 4

dev_parbutteea
Active Contributor
0 Kudos

Hi,

Actually there is a function module for your purpose:

CS_QU_EVALUATE_FORMULA

send the formula without brackets and set the field I_ROMEI.

I tried to run it from se37, it worked.

Revert back in case of questions,

Reward if this helps you,

Regards,

Sooness.

0 Kudos

Hi,

Sorry , I meant :

send the formula without qquotes(") and set the field I_ROMEI.

I tried to run it from se37, it worked.

Regards,

Sooness

Former Member
0 Kudos

Ok, that FM seems to work - unfortunately the FM does not exist in BW.

I will try to copy and paste it into an own FM.

@all:

Are there more solutions?

Meanwhile I tired to solve the issue by using a temp. generated program. Works fine, but seem to be slow...

Former Member
0 Kudos

While copy'n'pasting things form R3 to BW I saw, that the named FM used another FM called EVAL_FORMULA.

The last one (EVAL...) is also available in BW - therefore I can use this one. It works perfect...

Thanks,

Chris