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: 

dynamic assignment in expression

birendra_chatterjee
Active Participant
0 Kudos

Hi Friends,

I have a requirement such that, based on some conditions, a = b + c, or a = b + d, or a = a - c, or a = a + c, and so on... All variables are of currency type (13,2).

Now, the logic of this condition-based equation comes from table ( i.e. if a = a - c, then 'a' , '-' and 'c' are maintained in a custom table).

I want to populate a text by concatenating 'a' '-' 'c' such that the text equals 'a - c'. Now I want to equate a with text (a = text )to get the value as that of (a - c).

If you can throw some light on this please...

Thanks in advance,

Birendra

3 REPLIES 3

former_member182387
Active Participant
0 Kudos

Hi,

You can achieve this by using field symbols... Just analyze the following sample code..


PARAMETER : w_a TYPE i
     , w_b TYPE i
     , w_symbol TYPE c
     .

DATA : w_text_A(10) TYPE c
      , w_text_B(10) TYPE c
      , w_c TYPE i
      .

FIELD-SYMBOLS : <FS_A>,<FS_B>,<FS_C>.

w_text_A = 'W_A'.

w_text_B = 'W_B'.

WRITE : w_a, w_b, w_c.
WRITE /.

ASSIGN (w_text_A) TO <FS_A>. " assigns the value of field name(w_a) contained in variable(w_text_a)

ASSIGN (w_text_b) TO <FS_B>. " assigns the value of field name(w_b) contained in variable(w_text_b)

CASE W_SYMBOL.
  WHEN '-'.
    W_C = <FS_A> - <FS_B>.
  WHEN '+'.
    W_C = <FS_A> + <FS_B>.
  WHEN '/'.
    W_C = <FS_A> / <FS_B>.
  WHEN '*'.
    W_C = <FS_A> * <FS_B>.
  WHEN OTHERS.
ENDCASE..



WRITE : w_a, w_b, w_c.

copy paste to SE38 and try.You will get what you want.....

Thanks and Regards,

Senthil Kumar Anantham..

SuhaSaha
Advisor
Advisor
0 Kudos

The func. module 'EVAL_FORMULA' should help you.

kesavadas_thekkillath
Active Contributor
0 Kudos

Check this