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

Dynamic data type declaration with series

mohammedsarvar_ka
Product and Topic Expert
Product and Topic Expert
0 Likes
1,792

Hi All,

Can someone help me, is it possible to declare a variable dynamically?

I am just trying out this way but getting syntax error.
actual declaration is like,
data: lt_itab type /someNameSpace/some_table_name_1_k. (here this type has 1 to 14). I just want to replace this 1 dynamically

" data: lv_str(30) type c,
lv_type(30) type c,
lv_num typ n.

lv_str = '/someNameSpace/some_table_name_'.

lv_num = ls_var-nr_dimensions.

CONCATENATE lv_str lv_num '_k' INTO lv_type.

DATA lt_tab TYPE lv_type. "gives syntax error lv_type unknown?

Thanks,
Mohammed

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
1,472

See ABAP documentation of CREATE DATA.

DATA: dref TYPE REF TO DATA.

CREATE DATA dref TYPE (lv_type).
ASSIGN dref->* TO FIELD-SYMBOL(<fs>).
...
1 REPLY 1
Read only

Sandra_Rossi
Active Contributor
1,473

See ABAP documentation of CREATE DATA.

DATA: dref TYPE REF TO DATA.

CREATE DATA dref TYPE (lv_type).
ASSIGN dref->* TO FIELD-SYMBOL(<fs>).
...