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: 

Create Variable at Runtime.

Former Member
0 Kudos

Hello ABAPPERS,

Can we create the variable at runtime???

Plz help , its really urgent....

Thanks & Regards..

Supriya

4 REPLIES 4

Sm1tje
Active Contributor
0 Kudos

Your requirement is not fully clear, but it is possible to create variables at runtime like this:


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>.

Former Member
0 Kudos

Hi Micky,

I have tried your Code but its giving me error..

The statement "DREF_CREATE" is not expected. A correct similar statement is "CREATE".....

Please help me out...

Sm1tje
Active Contributor
0 Kudos

Maybe a copy-paste error, since I'm not using any statement DREF_CREATE...


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.

CREATE DATA dref TYPE struc.
ASSIGN dref->* TO <str>.

<str>-a = 36. <str>-b = 'ABC'.
CREATE DATA dref LIKE int.
ASSIGN dref->* TO <int>.

<int> = 5.
tname = 'SFLIGHT'.
CREATE DATA dref TYPE (tname).
ASSIGN dref->* TO <f>.

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

Former Member
0 Kudos

Yes , its possible you can use field symbols.

They act as pointers

Hope it helps