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

formula parser

Former Member
0 Likes
609

Dear all,

does ABAP provide something like a formula parser to calculate for example:

2*(A+B)/(C-D) correctly?

Best regards,

Christoph Aschauer

4 REPLIES 4
Read only

jaideeps
Product and Topic Expert
Product and Topic Expert
0 Likes
531

hi,

When you combine arithmetic expressions, ABAP performs the calculation from left to right, with one exception: Powers are calculates from right to left. So <n> ** <m> ** <p> is the same as <n> ** ( <m> ** <p> ), not ( <n> ** <m> ) ** <p>.

DATA: pack TYPE p DECIMALS 0.

pack = 1 / 3 * 3.

WRITE pack.

ans: 1

i think it follows BODMAS rule

thanks

jaideep

*reward points if useful

Read only

Former Member
0 Likes
531

Sorry guys,

I did not post the issue clearly.

I get a formula as a string: 2*(A + B)/(C+D).

the values of A ... D are stored somewhere.

I like to have the possibility to calculate the value dynamically, but like to avoid "GENERATE SUBROUTINE POOL.

Christoph Aschauer

Read only

Former Member
0 Likes
531

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

Read only

Former Member
0 Likes
531

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

Christoph