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

Executing a Arithmatic formula stored in Variable

Former Member
0 Likes
565

Hi all,

I need solution to execute a arithmatic operation which is stored in a variable.

For Example:

data : var type string.

var = ABS('-3').

Now by means of the variable var i need to get the absolute value of -3

ie my output should be 3 if i print the variable "var".

Please help.

Regards,

Vijayakumar

4 REPLIES 4
Read only

Former Member
0 Likes
546

Hello,

Do like this.


REPORT ZV_SDN_3 .
 
DATA: STR TYPE STRING.
DATA: STR1 LIKE STR,
      INT TYPE I,
      LEN TYPE I.
STR = ABS('-3')..
LEN = STRLEN( STR ).
DO LEN TIMES.
  IF NOT STR+INT(1) IS INITIAL.
    IF STR+INT(1) CA '0123456789'.
      CONCATENATE STR1 STR+INT(1) INTO STR1.
    ENDIF.
  ENDIF.
  ADD 1 TO INT.
ENDDO.


 
WRITE: STR1.


Hope this will solve ur issue.

Cheers,

Vasanth

Read only

0 Likes
546

Hi,

I think my example has little bit of misguidance . The real concept is the formula is stored in the string.

i.e var = 'ABS('-3')'.

Now if i display the variable var , I need the output as 3.

Please help.

Regards,

Vijayakumar

Read only

matt
Active Contributor
0 Likes
546

Do what Rob says. It's the only solution I'm aware of.

matt

Read only

Former Member
0 Likes
546

You could generate ABAP code on the fly. Do F1 on GENERATE SUBROUTINE POOL.

Rob