cancel
Showing results for 
Search instead for 
Did you mean: 

formula parser

Former Member
0 Kudos

Dear all,

does ABAP provide something like a formula parser?

I'd like to have the possibility to calculate correctly something like:

2*(AB) /(CD)

the formula is given as a string dynamically, and the parameters' values are stored somewhere.

Is there any parser which helps me to calculate correctly?

Except from using GENERATE SUBROUTINE POOL?

Best Regards,

Christoph Aschauer

Message was edited by:

Christoph Aschauer

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

solved the problem on my own. Please see the comment above or feel free to ask.

Christoph

Former Member
0 Kudos

Hi all,

I solved the problems as follows:

- limitation of 36 subroutines: SUBMIT program. (this program generates the generic subroutine pools (communication via DB or shared objects possible)

- limitation of subroutine pool line ( 255 chars ).

also this is an executable calculation:

calc =

(

3

+

7

)

*

2

.

So no longer line restriction when having a very long formula string to be generically processed.

Christoph

Former Member
0 Kudos

Hi,

The following code sample uses javascript to evaluate the expression, you have to replace the variables in the expression with the actual values. You can also use BIND method of CL_JAVA_SCRIPT to bind abap variables to js variables.

===============================

REPORT evaluate_formula.

DATA source TYPE string.

DATA return_value TYPE string.

DATA js_processor TYPE REF TO cl_java_script.

js_processor = cl_java_script=>create( ).

CONCATENATE

'var result = '

' 2*(2 + 6)/4 '

';'

'result; '

INTO source SEPARATED BY cl_abap_char_utilities=>cr_lf.

return_value = js_processor->evaluate( source ).

WRITE return_value.

==================================

Best Regards,

Rao A

Message was edited by:

Rao Arimilli