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 can I calculate -> total = num1 operator num2 ( oparator = '+' ) .

Former Member
0 Kudos

How can I calculate dynamic operators.

I would like to calculate formular by changing text '+' to plus and text '-' to minus which user can determine formular by themself .

Example :

Data: total type p,

num1 type n value '3',

num2 type n value '5'.

parameters operator type c default '+'.

total = num1 operator num2.

      • I want "total" result like this --> total = 3 + 5 --> total = 8. ***

Thank you for your help.

Sarun

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Friend,

Use this...

PARAMETERS: operator type c DEFAULT '+'.

data:

num1 type n value '2',

num2 type n value '5'.

data: tot type p.

data: st type string.

concatenate num1 operator num2 into st SEPARATED BY space.

CALL FUNCTION 'FORMULA_EVALUATION'

EXPORTING

FORMULA = st

IMPORTING

VALUE = tot.

write:/ tot.

7 REPLIES 7

Former Member
0 Kudos

Friend,

you can use case...endcase...

case operator.

when '+'.

total = num1 + num2.

when '-'.

total = num1 - num2.

endcase.

like above use for *, /

0 Kudos

Thank you so much but formula is not fixed but it will be determined by user . It mean it's a dynamic formula.

Former Member
0 Kudos

hi ,

U want "total" result like this --> total = 3 + 5 --> total = 8. ***

for this try this

'total' = num1 '' num2 '--> total = ' num1num2.

Try this ..

THX

Former Member
0 Kudos

HI try this ,

Data: total type p,

num1 type n value '3',

num2 type n value '5',

num3 type n.

num3 = num1 + num2.

write : 'total = ' .

write : num1.

write : '+'.

write : num2.

write : ' --> total = '.

write : num3.

THX

kesavadas_thekkillath
Active Contributor
0 Kudos

Data: total type p,

num1 type i ,

num2 type i .

parameters operator type c default '+'.

start-of-selection.

num1 = 10.

num2 = 5.

while num1 >= num2.

case operator.

when '+'.

total = num1 + num2.

operator = '-'.

when '-'.

total = num1 - num2.

operator = '+'.

endcase.

num1 = num1 - 1.

write:/ total.

endwhile.

Former Member
0 Kudos

Friend,

Use this...

PARAMETERS: operator type c DEFAULT '+'.

data:

num1 type n value '2',

num2 type n value '5'.

data: tot type p.

data: st type string.

concatenate num1 operator num2 into st SEPARATED BY space.

CALL FUNCTION 'FORMULA_EVALUATION'

EXPORTING

FORMULA = st

IMPORTING

VALUE = tot.

write:/ tot.

0 Kudos

I already solve this problem.

Thank you very much "Ramu",

Sarun