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

Execute command written in a string

Former Member
0 Likes
1,160

Hi Expert,

is is possible to execute a command written in a variable string?

For example:

va_command type string.

A = 10.

B = 2.

C = 6.

va_command = '( A + B ) / C'.

RESULT = <i><b>EXECUTE</b></i> (va_command).

in result i have "2".

Any hints will be rewarded.

Thanks in advance.

Fabio.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
835

No, you really need to generate a subroutine to do that kind of thing.

In most cases, it is not worth the trouble, what exatly is your requirement.

Regards,

Rich Heilman

6 REPLIES 6
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
836

No, you really need to generate a subroutine to do that kind of thing.

In most cases, it is not worth the trouble, what exatly is your requirement.

Regards,

Rich Heilman

Read only

0 Likes
835

Thanks for the response Rich!

I have to do the user the possibility to dynamycally change formula in a BW routine without maintain ABAP code or FOX formula...my idea is to write the Formula in an infoObject field and translate it in a abap commad in the routine.

Read only

0 Likes
835

Ok, not sure if this will help you or not, but its good to know anyway. Test this program, all it is doing is generating a program at runtime and calling a subroutine with the code in it.




report zrich_0001 .




types: t_source(72).

data: routine(32) value 'TEMP_ROUTINE',
      program(8),
      message(128),
      line type i.

data: isource type table of t_source,
      xsource type t_source.

data: a type i value 10,
      b type i value 2,
      c type i value 6,
      result type i.




xsource = 'REPORT ZTEMP_PROGRAM.'.   append xsource to isource.

xsource = 'FORM TEMP_ROUTINE using a b c result.'.
append xsource to isource.


xsource = 'result = ( a + b ) / c. '. append xsource to isource.
xsource = 'ENDFORM.'.                append xsource to isource.

generate subroutine pool isource name program
                         message message
                         line line.
if sy-subrc = 0.
  perform (routine) in program (program) using a b c result.
else.
  write:/ message.
endif.

write:/ result.

Regards,

Rich Heilman

Read only

0 Likes
835

Many thanks!

i will test the solution....

Read only

0 Likes
835

That's the solution, very great code!

Many thanks.

Fabio.

Read only

former_member194669
Active Contributor
0 Likes
835

Hi,

You need to use subroutine or macro for this.

ex.


report  z_test.
data : v_result type i.

define execute.
  v_result = ( &1 + &2 ).
  v_result = v_result / &3.
end-of-definition.

execute 3 3 3.

write : v_result.

aRs