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: 

ABAP-Logic/Command: Execute An Expression Stored In A Variable

Former Member
0 Kudos

Consider the following code - <b>Is it possible to execute the statement/expression stored in variables expression1, expression2 and expression3?</b> The result should be:

sum = 5 , subname = 'First' & i_output should be sorted by lifnr and ebeln.


*---DATA DECLARATIONS
DATA: sum         TYPE i,
      op1         TYPE i,
      op2         TYPE i,

      name        TYPE string,
      subname     TYPE string,
      offset      TYPE i,

      expression1 TYPE string,
      expression2 TYPE string,
      expression3 TYPE string.

DATA: BEGIN OF i_output OCCURS 0,
      lifnr TYPE lfa1-lifnr,
      ebeln TYPE ekko-ebeln,
      ebelp TYPE ekpo-ebelp,
      END OF i_output.

*---BUILD EXPRESSION 1
op1 = 2.
op2 = 3.
expression1 = 'sum = op1 + op2'.

*---BUILD EXPRESSION 2
name   = ' First Name'.
offset = 5.
expression2 = 'subname = name+1(offset)'.

*---POPULATE ITAB I_OUTPUT
MOVE: '111111' TO i_output-lifnr,
      'PO1'    TO i_output-ebeln,
      '010'    TO i_output-ebelp.
APPEND i_output.

MOVE: '111511' TO i_output-lifnr,
      'PO1'    TO i_output-ebeln,
      '020'    TO i_output-ebelp.
APPEND i_output.

MOVE: '111111' TO i_output-lifnr,
      'PO3'    TO i_output-ebeln,
      '010'    TO i_output-ebelp.
APPEND i_output.

MOVE: '114111' TO i_output-lifnr,
      'PO2'    TO i_output-ebeln,
      '010'    TO i_output-ebelp.
APPEND i_output.

MOVE: '111121' TO i_output-lifnr,
      'PO2'    TO i_output-ebeln,
      '020'    TO i_output-ebelp.
APPEND i_output.

CLEAR i_output.

*---BUILD EXPRESSION 3
expression3 = 'sort i_output by lifnr ebeln'.

Thanks in advance!

3 REPLIES 3

Former Member
0 Kudos

You can achieve this by generating a subroutine pool dynamically, passing the code lines (expressions) as an internal table. Here is the syntax:

GENERATE SUBROUTINE POOL itab NAME name.

Hope this helps,

Bhanu

0 Kudos

But, how can you pass some value/data (say a table which has to be sorted) from the main report to the subroutine-pool?

0 Kudos

> You can achieve this by generating a subroutine pool

> dynamically, passing the code lines (expressions) as

> an internal table. Here is the syntax:

>

> GENERATE SUBROUTINE POOL itab NAME name.

>

> Hope this helps,

> Bhanu

Hey Banu, thanks!

Message was edited by: Sam