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

Calculating math expression

Former Member
0 Likes
687

Hi all.

does anyone know any function or class that calculates math expressions in ABAP (such as (210+(53)/2) )?

Or, if you don't, can you tell me if there is any standard class to handle stacks, so I can build my own expression calculator?

Thanks in advance.

Hermes.

points will be rewarded.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
550

Hi ,

Here is a sample code

data: it type i value 4 ,
      it_2 type i value 2.
      data : it_3  type i.
start-of-selection.

it_3 = (  it  *  it_2  +  (  (  it  *  it_2  )  /  it_2  )  ).
write: it_3.

just rem to keep a space after ever open bracket and before every close bracket.

Reagrds

aRUN

3 REPLIES 3
Read only

Former Member
0 Likes
551

Hi ,

Here is a sample code

data: it type i value 4 ,
      it_2 type i value 2.
      data : it_3  type i.
start-of-selection.

it_3 = (  it  *  it_2  +  (  (  it  *  it_2  )  /  it_2  )  ).
write: it_3.

just rem to keep a space after ever open bracket and before every close bracket.

Reagrds

aRUN

Read only

0 Likes
550

Thank you very much, Arun.

Sometimes the answer is way simpler than we are looking for...

Read only

Former Member
0 Likes
550

u can do small tasks like math caluclations using macros.

eg:

declare ur macro 'calc', like this.

suppose ur task is to add var1 and var2 into var3.

define calc.

&3 = &1 + &2.

end-of-definition.

Now u can call the macro and pass the variables, where ever required in the code, like this.

calc var1 var2 var3.

now var3 will have sum of var1 and var2.

But be careful some people do not accept macros for performance issue.

Still as a fact of time, I have been using macros for various purposes and never had problem. If there is a concern not to use a macro, best other option is to build a FORM for ur task and call it using PERFORM.

Regards,

Suresh