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

Former Member
0 Likes
1,149

Hello ABAPPERS,

Can we create the variable at runtime???

Plz help , its really urgent....

Thanks & Regards..

Supriya

4 REPLIES 4
Read only

Sm1tje
Active Contributor
0 Likes
773

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

Read only

Former Member
0 Likes
773

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

Read only

Sm1tje
Active Contributor
0 Likes
773

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

Read only

Former Member
0 Likes
773

Yes , its possible you can use field symbols.

They act as pointers

Hope it helps