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

Create Variable Name at RUNTIME

Former Member
0 Likes
1,311

Hello ABAP Experts,

i want to create a Variable name at runtime and then assign

num. values to it.

For Ex. :

data : vday type sy-datum

vday = sy-datum+6(2). + 'AAA'.

i want create variable name is" 28AAA at runtime... Bcoz every time sy-datum values are change so my variable name is also change...

Its very urgent

please help me rewards are helpful answers.

Thanks :

Vandana.

4 REPLIES 4
Read only

Former Member
0 Likes
735

if u need a random variable use

GENERAL_GET_RANDOM_STRING

Read only

Sm1tje
Active Contributor
0 Likes
735

do you want the NAME of the variable changed, or do you want to change the contents of your vday variable.

If the latter is the case just concatenate sy-datum+6(2) 'AAA' into vday.

If you want to dynamically create variable names, you will have to use CREATE DATA, or maybe even use the CL_ABAPDESCR classes.

Some examples for Dynamic Creation of Data Objects:

TYPES: BEGIN OF struc,

a TYPE i,

b TYPE c LENGTH 8,

END OF STRUC.

DATA: dref TYPE REF TO DATA,

tname TYPE string,

str TYPE struc,

int TYPE i.

FIELD-SYMBOLS: <int> TYPE i,

<str> TYPE struc,

<f> TYPE any.

dref

CREATE DATA dref TYPE struc.

ASSIGN dref->* TO <str>.

<str>

36 ABC

<str>-a = 36. <str>-b = 'ABC'.

CREATE DATA dref LIKE int.

ASSIGN dref->* TO <int>.

<int>

5

<int> = 5.

tname = 'SFLIGHT'.

CREATE DATA dref TYPE (tname).

ASSIGN dref->* TO <f>.

<f>

SELECT SINGLE * FROM (tname) INTO <f>.

Edited by: Micky Oestreich on May 28, 2008 9:51 AM

Read only

Former Member
0 Likes
735

Hello Micky

Thanks For your reply

concatenate sy-datum+6(2) 'AAA' into vday.

this is right but

but every time the sy-datum is change so my variable vday name is also change . and i want my variable name is change every time when the sy-datun is change...

Please Help me out.

Thanks :

Vandana

Read only

0 Likes
735

hi Vandanan,

what sense does it make to have dynamic name of the variable? Have you ever seriously thought on this?

ec