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 variable name

Former Member
0 Kudos

Hi Experts,

I want to create variable names dynamically in my program.

i know what should be the type of my variable.

eg: I want to create variable of pattern time.001, time.002, time.003 etc.

i get values 001, 002 from one of my source.

then I loop that source,

loop at it_table.

wa_table-period holds this number.

now i want to concatenate that number(001) with time and use this time.001 as a variable for further calculations.

endloop.

this time.001 then time.002 should have type c length 7 and should be able to store values in those variables.

i want this variables are seperate and not in any internal table.

in short, data: time.001(7) type c,

time.002(7) type c. needs to be created dynamically in program.

Can anyone help.

Please

thanks,

Sonali

4 REPLIES 4

0 Kudos

Hi Sonali,

For this instead of creating variables dynamically, you can make use of field symbols.

loop at it_table into wa_table.

     CONCATENATE 'TIME' wa_table-period into lv_temp.

     ASSIGN (lv_temp) to <fs_time>.

    

ENDLOOP.

Now <fs_time> holds time001(if wa_table-period is 001). Whenever you want to use time001, you can use field symbol <fs_time>.

Hope this helps

Sreedhar

0 Kudos

hi Sreedhar,

Thanks for your reply.

this was just an example i gave for time.

assume I need to create variable on the fly for GL accounts.

user can enter data in any number of GL accounts, then I just have these all GL account together in one string seperated by ','.

ie GL001,GL005,GL0056,GL0089

Now I want to store these individual GL's in dynamically created 4 variables.

I want to know how to create these variable if number of accounts is not known.

0 Kudos

Hello Sonali,

Try with these following  links. May be you got some idea to get rid of your problem

http://scn.sap.com/thread/1823076

https://www.google.co.in/search?q=Dynamic+variable+name+in+sap+site:scn.sap.com&biw=1920&bih=950

BR

Chandra..

sandeep_ramesh88
Explorer
0 Kudos

Hi Sonali,

Plz refer : http://scn.sap.com/thread/853522